@Test public void testBucketBucketFlat() { RevTree left = RevObjectTestSupport.INSTANCE.createFeaturesTree(leftSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 1); RevTree right = RevObjectTestSupport.INSTANCE.createFeaturesTree(rightSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 2); PreOrderDiffWalk visitor = newVisitor(left, right); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); when(consumer.bucket(any(NodeRef.class), any(NodeRef.class), any(BucketIndex.class), any(Bucket.class), any(Bucket.class))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).bucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verify(consumer, times(1)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(1)).endTree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).endBucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verifyNoMoreInteractions(consumer); }
@Test public void testBucketBucketFlat() { RevTree left = testSupport.createFeaturesTree(leftSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 1); RevTree right = testSupport.createFeaturesTree(rightSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 2); PreOrderDiffWalk visitor = newVisitor(left, right); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); when(consumer.bucket(any(NodeRef.class), any(NodeRef.class), any(BucketIndex.class), any(Bucket.class), any(Bucket.class))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).bucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verify(consumer, times(1)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(1)).endTree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).endBucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verifyNoMoreInteractions(consumer); }
@Test public void testBucketBucketFlat() { RevTree left = createFeaturesTree(leftSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 1); RevTree right = createFeaturesTree(rightSource, "f", CanonicalNodeNameOrder.normalizedSizeLimit(0) + 2); PreOrderDiffWalk visitor = newVisitor(left, right); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); when(consumer.bucket(any(NodeRef.class), any(NodeRef.class), any(BucketIndex.class), any(Bucket.class), any(Bucket.class))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).bucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verify(consumer, times(1)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(1)).endTree(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(1)).endBucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verifyNoMoreInteractions(consumer); }
@Test public void testBucketLeafSimple() { final int leftsize = 1 + CanonicalNodeNameOrder.normalizedSizeLimit(0); RevTree left = testSupport.createFeaturesTree(leftSource, "f", leftsize); RevTree right = testSupport.createFeaturesTree(rightSource, "f", 1); PreOrderDiffWalk visitor = newVisitor(left, right); // consume all when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); when(consumer.bucket(any(NodeRef.class), any(NodeRef.class), any(BucketIndex.class), any(Bucket.class), any(Bucket.class))).thenReturn(true); visitor.walk(consumer); // there's only the root tree verify(consumer, times(1)).tree(any(NodeRef.class), any(NodeRef.class)); // there's only one feature on the right tree, so all right trees features fall on a single // bucket final int leftBucketCount = left.bucketsSize(); final int expectedBucketCalls = leftBucketCount; verify(consumer, times(expectedBucketCalls)).bucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verify(consumer, times(leftsize - 1)).feature(any(NodeRef.class), (NodeRef) isNull()); verify(consumer, times(expectedBucketCalls)).endBucket(any(NodeRef.class), any(NodeRef.class), argThat(depthMatches(0)), any(Bucket.class), any(Bucket.class)); verify(consumer, times(1)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafTwoAdds() { // two leaf trees RevTree left = createFeaturesTree(leftSource, "f", 3); RevTree right = createFeaturesTree(rightSource, "f", 5); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(eq(lroot), eq(rroot)); ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).feature(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertNull(larg.getAllValues().get(0)); assertNull(larg.getAllValues().get(1)); NodeRef n1 = featureNodeRef("f", 3);// the two added nodes NodeRef n2 = featureNodeRef("f", 4); assertTrue(rarg.getAllValues().contains(n1)); assertTrue(rarg.getAllValues().contains(n2)); verify(consumer, times(1)).endTree(eq(lroot), eq(rroot)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafTwoRemoves() { // two leaf trees RevTree left = RevObjectTestSupport.INSTANCE.createFeaturesTree(leftSource, "f", 5); RevTree right = RevObjectTestSupport.INSTANCE.createFeaturesTree(rightSource, "f", 3); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(eq(lroot), eq(rroot)); ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).feature(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertNull(rarg.getAllValues().get(0)); assertNull(rarg.getAllValues().get(1)); NodeRef n1 = featureNodeRef("f", 3);// the two added nodes NodeRef n2 = featureNodeRef("f", 4); assertTrue(larg.getAllValues().contains(n1)); assertTrue(larg.getAllValues().contains(n2)); verify(consumer, times(1)).endTree(eq(lroot), eq(rroot)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafTwoRemoves() { // two leaf trees RevTree left = testSupport.createFeaturesTree(leftSource, "f", 5); RevTree right = testSupport.createFeaturesTree(rightSource, "f", 3); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); visitor.walk(consumer); verify(consumer, times(1)).tree(eq(lroot), eq(rroot)); ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).feature(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertNull(rarg.getAllValues().get(0)); assertNull(rarg.getAllValues().get(1)); NodeRef n1 = featureNodeRef("f", 3);// the two added nodes NodeRef n2 = featureNodeRef("f", 4); assertTrue(larg.getAllValues().contains(n1)); assertTrue(larg.getAllValues().contains(n2)); verify(consumer, times(1)).endTree(eq(lroot), eq(rroot)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = RevObjectTestSupport.INSTANCE.createTreesTree(leftSource, 3, 10, metadataId); RevTree right = RevObjectTestSupport.INSTANCE.createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = createTreesTree(leftSource, 3, 10, metadataId); RevTree right = createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = RevObjectTestSupport.INSTANCE.createTreesTree(leftSource, 2, 10, metadataId); RevTree right = RevObjectTestSupport.INSTANCE.createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = testSupport.createTreesTree(leftSource, 3, 10, metadataId); RevTree right = testSupport.createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = createTreesTree(leftSource, 2, 10, metadataId); RevTree right = createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = testSupport.createTreesTree(leftSource, 2, 10, metadataId); RevTree right = testSupport.createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testCallsRootNode() { RevTree left = createFeaturesTree(leftSource, "f", 1); RevTree right = createFeaturesTree(rightSource, "f", 2); PreOrderDiffWalk visitor = newVisitor(left, right); visitor.walk(consumer); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(false); final NodeRef lNode = nodeFor(left); final NodeRef rNode = nodeFor(right); ArgumentCaptor<NodeRef> leftNode = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rightNode = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(1)).tree(leftNode.capture(), rightNode.capture()); assertEquals(lNode, leftNode.getValue()); assertEquals(rNode, rightNode.getValue()); verify(consumer, times(1)).endTree(leftNode.capture(), rightNode.capture()); verifyNoMoreInteractions(consumer); }
@Test public void testCallsRootNode() { RevTree left = RevObjectTestSupport.INSTANCE.createFeaturesTree(leftSource, "f", 1); RevTree right = RevObjectTestSupport.INSTANCE.createFeaturesTree(rightSource, "f", 2); PreOrderDiffWalk visitor = newVisitor(left, right); visitor.walk(consumer); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(false); final NodeRef lNode = nodeFor(left); final NodeRef rNode = nodeFor(right); ArgumentCaptor<NodeRef> leftNode = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rightNode = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(1)).tree(leftNode.capture(), rightNode.capture()); assertEquals(lNode, leftNode.getValue()); assertEquals(rNode, rightNode.getValue()); verify(consumer, times(1)).endTree(leftNode.capture(), rightNode.capture()); verifyNoMoreInteractions(consumer); }
@Test public void testCallsRootNode() { RevTree left = testSupport.createFeaturesTree(leftSource, "f", 1); RevTree right = testSupport.createFeaturesTree(rightSource, "f", 2); PreOrderDiffWalk visitor = newVisitor(left, right); visitor.walk(consumer); when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(false); final NodeRef lNode = nodeFor(left); final NodeRef rNode = nodeFor(right); ArgumentCaptor<NodeRef> leftNode = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rightNode = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(1)).tree(leftNode.capture(), rightNode.capture()); assertEquals(lNode, leftNode.getValue()); assertEquals(rNode, rightNode.getValue()); verify(consumer, times(1)).endTree(leftNode.capture(), rightNode.capture()); verifyNoMoreInteractions(consumer); }
@Override public boolean tree(NodeRef left, NodeRef right) { return delegate.tree(left, right); }
@Override public boolean tree(NodeRef left, NodeRef right) { return !isCancelled() && delegate.tree(left, right); }
@Override public boolean tree(NodeRef left, NodeRef right) { return !isCancelled() && delegate.tree(left, right); }
@Override public boolean tree(NodeRef left, NodeRef right) { return delegate.tree(left, right); }