RecursiveTreeFilter extends ViewerFilter { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return select(viewer, parentElement, element, 0); } RecursiveTreeFilter(ViewerFilter delegateFilter);   RecursiveTreeFilter(ViewerFilter delegateFilter, int maxDepth); @Override boolean select(Viewer viewer, Object parentElement, Object element);  }
@Test public void positiveRoot() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); Viewer viewerMock = mock(Viewer.class); Object parentMock = mock(Object.class); BpRequirementGroup elementMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, elementMock)).thenReturn(true); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertTrue(sut.select(viewerMock, parentMock, elementMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, elementMock); }
@Test public void negativeRootNoChildren() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); StructuredViewer viewerMock = mock(StructuredViewer.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, rootMock)).thenReturn(false); when(treeContentProviderMock.getChildren(rootMock)).thenReturn(new Object[0]); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertFalse(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); }
@Test public void negativeRootPositiveChild() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, rootMock)).thenReturn(false); BpRequirement negativeChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild)).thenReturn(true); BpRequirement positiveChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, rootMock, positiveChild)).thenReturn(true); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild, positiveChild }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertTrue(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); verify(delegateFilterMock, times(1)).select(viewerMock, rootMock, negativeChild); }
@Test public void negativeRootNegativeChildren() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, rootMock)).thenReturn(false); BpRequirement negativeChild1 = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild1)).thenReturn(false); BpRequirement negativeChild2 = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild2)).thenReturn(false); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild1, negativeChild2 }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertFalse(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); }
@Test public void negativeRootPositveGrandChild() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, null, rootMock)).thenReturn(false); BpRequirementGroup negativeChild = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild)).thenReturn(false); BpRequirement positiveGrandChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, negativeChild, positiveGrandChild)) .thenReturn(true); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild }); when(treeContentProviderMock.getChildren(negativeChild)) .thenReturn(new Object[] { positiveGrandChild }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertTrue(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); verify(delegateFilterMock, times(1)).select(viewerMock, rootMock, negativeChild); }
@Test public void negativeRootNegativeDescendants() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, null, rootMock)).thenReturn(false); BpRequirementGroup negativeChild = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild)).thenReturn(false); BpRequirement negativeGrandChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, negativeChild, negativeGrandChild)) .thenReturn(false); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild }); when(treeContentProviderMock.getChildren(negativeChild)) .thenReturn(new Object[] { negativeGrandChild }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock); Assert.assertFalse(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); verify(delegateFilterMock, times(1)).select(viewerMock, rootMock, negativeChild); verify(delegateFilterMock, times(1)).select(viewerMock, negativeChild, negativeGrandChild); }
@Test public void negativeRootNegativeDescendantsLimitedDepth() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, rootMock)).thenReturn(false); BpRequirementGroup negativeChild = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild)).thenReturn(false); BpRequirement negativeGrandChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, negativeChild, negativeGrandChild)) .thenReturn(false); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild }); when(treeContentProviderMock.getChildren(negativeChild)) .thenReturn(new Object[] { negativeGrandChild }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock, 1); Assert.assertTrue(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); verify(delegateFilterMock, times(1)).select(viewerMock, rootMock, negativeChild); verify(delegateFilterMock, never()).select(viewerMock, negativeChild, negativeGrandChild); verify(treeContentProviderMock, never()).getChildren(negativeChild); }
@Test public void negativeRootNegativeDescendantsSufficientDepth() { ViewerFilter delegateFilterMock = mock(ViewerFilter.class); ITreeContentProvider treeContentProviderMock = mock(ITreeContentProvider.class); StructuredViewer viewerMock = mock(StructuredViewer.class); when(viewerMock.getContentProvider()).thenReturn(treeContentProviderMock); Object parentMock = mock(Object.class); BpRequirementGroup rootMock = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, parentMock, rootMock)).thenReturn(false); BpRequirementGroup negativeChild = mock(BpRequirementGroup.class); when(delegateFilterMock.select(viewerMock, rootMock, negativeChild)).thenReturn(false); BpRequirement negativeGrandChild = mock(BpRequirement.class); when(delegateFilterMock.select(viewerMock, negativeChild, negativeGrandChild)) .thenReturn(false); when(treeContentProviderMock.getChildren(rootMock)) .thenReturn(new Object[] { negativeChild }); when(treeContentProviderMock.getChildren(negativeChild)) .thenReturn(new Object[] { negativeGrandChild }); RecursiveTreeFilter sut = new RecursiveTreeFilter(delegateFilterMock, 2); Assert.assertFalse(sut.select(viewerMock, parentMock, rootMock)); verify(delegateFilterMock, times(1)).select(viewerMock, parentMock, rootMock); verify(delegateFilterMock, times(1)).select(viewerMock, rootMock, negativeChild); verify(delegateFilterMock, times(1)).select(viewerMock, negativeChild, negativeGrandChild); }