diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilterTest.java new file mode 100644 index 00000000..508a246d --- /dev/null +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilterTest.java @@ -0,0 +1,112 @@ +package io.toolisticon.annotationprocessortoolkit.tools.filter; + +import io.toolisticon.annotationprocessortoolkit.tools.TestCoreMatcherFactory; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.ImplicitMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ImplicitValidator; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import javax.lang.model.element.Element; +import java.util.ArrayList; +import java.util.List; + +/** + * Unit test for {@link ImplicitFilter}. + */ +public class ImplicitFilterTest { + + List list; + + Element element1; + Element element2; + Element element3; + + @Before + public void init() { + list = new ArrayList(); + + element1 = Mockito.mock(Element.class); + element2 = Mockito.mock(Element.class); + element3 = Mockito.mock(Element.class); + + list.add(element1); + list.add(element2); + list.add(element3); + } + + + @Test + public void testImplicitFilter_allMatching() { + + ImplicitFilter>> unit = + new ImplicitFilter>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true).getValidator()); + + + List result = unit.filter(list); + + MatcherAssert.assertThat(result, Matchers.contains(element1, element2, element3)); + + + } + + + @Test + public void testImplicitFilter_oneNotMatching() { + + ImplicitFilter>> unit = + new ImplicitFilter>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true, false, true).getValidator()); + + + List result = unit.filter(list); + + MatcherAssert.assertThat(result, Matchers.contains(element1, element3)); + + + } + + @Test + public void testImplicitFilter_allNotMatching() { + + ImplicitFilter>> unit = + new ImplicitFilter>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); + + + List result = unit.filter(list); + + MatcherAssert.assertThat(result, Matchers.empty()); + + + } + + @Test + public void testImplicitFilter_nullSafety_nullValuedValidator() { + + ImplicitFilter>> unit = + new ImplicitFilter>>(null); + + + List result = unit.filter(list); + + MatcherAssert.assertThat(result, Matchers.empty()); + + + } + + @Test + public void testImplicitFilter_nullSafety_nullListToFilter() { + + ImplicitFilter>> unit = + new ImplicitFilter>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); + + + List result = unit.filter(null); + + MatcherAssert.assertThat(result, Matchers.empty()); + + + } + +}