### Question:
RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i); long targetStart = targetSpan.getStart(); long targetEnd = targetStart + targetSpan.getWidth(); if (!(element instanceof InvariantSpan)) { continue; } InvariantSpan span = (InvariantSpan) element; long start = span.getStart(); long end = start + span.getWidth(); if (RopeUtils.intersects(start, end, targetStart, targetEnd)) { long a = Math.max(0, targetStart - start); long b = Math.max(0, end - targetEnd); VariantSpan vs = new VariantSpan(index + a, span.getWidth() - b - a); vs.documentHash = documentHash; vspans.add(vs); } index += span.getWidth(); } return vspans; } RopeVariantStream(String documentHash);  RopeVariantStream(String documentHash, Node<T> root); @Override void copy(long characterPosition, VariantSpan variantSpan); @Override void delete(VariantSpan variantSpan); @Override String getDocumentHash(); @Override List<T> getStreamElements(); @Override List<T> getStreamElements(VariantSpan variantSpan); @Override List<VariantSpan> getVariantSpans(InvariantSpan targetSpan); @Override T index(long characterPosition); @Override void move(long to, VariantSpan v1); @Override void put(long characterPosition, T val); @Override void rebalance(); void save(OutputStream os); @Override void swap(VariantSpan v1, VariantSpan v2); @Override void toggleOverlay(VariantSpan variantSpan, Overlay linkType);  }### Answer:
@Test public void getVariantSpansTwoIntersect() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElements(1, spans); List<VariantSpan> result = stream.getVariantSpans(new InvariantSpan(2, 5, documentHash)); assertEquals(2, result.size()); assertEquals(new VariantSpan(6, 3, documentHash), result.get(0)); assertEquals(new VariantSpan(10, 2, documentHash), result.get(1)); }
@Test public void getVariantSpansTwoIntersect2() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElements(1, spans); List<VariantSpan> result = stream.getVariantSpans(new InvariantSpan(1, 4, documentHash)); assertEquals(2, result.size()); assertEquals(new VariantSpan(6, 1, documentHash), result.get(0)); assertEquals(new VariantSpan(9, 3, documentHash), result.get(1)); }