diff --git a/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElement.java b/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElement.java index 007a5723..338e5efd 100644 --- a/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElement.java +++ b/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElement.java @@ -152,7 +152,7 @@ public void testHasSynchronizedModifier() { @Test - public void testHasNtiveModifier() { + public void testHasNativeModifier() { Element e = Mockito.mock(Element.class); Mockito.when(e.getModifiers()).thenReturn(Utilities.convertVarargsToSet(Modifier.NATIVE)); diff --git a/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/characteristicsvalidator/GenericElementCharacteristicMatcherTest.java b/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/characteristicsvalidator/GenericElementCharacteristicMatcherTest.java new file mode 100644 index 00000000..1ed37b2d --- /dev/null +++ b/annotationprocessor/src/test/java/de/holisticon/annotationprocessortoolkit/tools/characteristicsvalidator/GenericElementCharacteristicMatcherTest.java @@ -0,0 +1,130 @@ +package de.holisticon.annotationprocessortoolkit.tools.characteristicsvalidator; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; +import org.mockito.Mockito; + +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; + +/** + * Unit test of {@link GenericElementCharacteristicValidator}. + */ +public class GenericElementCharacteristicMatcherTest { + + + @Test + public void testHasOf_OneOf() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + Element element = Mockito.mock(Element.class); + spy.hasOf(ValidatorKind.ONE_OF, element, Modifier.ABSTRACT); + + Mockito.verify(spy).hasOneOf(element, Modifier.ABSTRACT); + + } + + @Test + public void testHasOf_AtLeastOneOf() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + Element element = Mockito.mock(Element.class); + spy.hasOf(ValidatorKind.AT_LEAST_ONE_OF, element, Modifier.ABSTRACT); + + Mockito.verify(spy).hasAtLeastOneOf(element, Modifier.ABSTRACT); + + } + + @Test + public void testHasOf_AllOf() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + Element element = Mockito.mock(Element.class); + spy.hasOf(ValidatorKind.ALL_OF, element, Modifier.ABSTRACT); + + Mockito.verify(spy).hasAllOf(element, Modifier.ABSTRACT); + + } + + @Test + public void testHasOf_NoneOf() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + Element element = Mockito.mock(Element.class); + spy.hasOf(ValidatorKind.NONE_OF, element, Modifier.ABSTRACT); + + Mockito.verify(spy).hasNoneOf(element, Modifier.ABSTRACT); + + } + + @Test + public void testHasOf_nullValuedKind() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + Element element = Mockito.mock(Element.class); + MatcherAssert.assertThat(spy.hasOf(null, element, Modifier.ABSTRACT), Matchers.is(false)); + + Mockito.verify(spy, Mockito.never()).hasNoneOf(element, Modifier.ABSTRACT); + Mockito.verify(spy, Mockito.never()).hasOneOf(element, Modifier.ABSTRACT); + Mockito.verify(spy, Mockito.never()).hasAtLeastOneOf(element, Modifier.ABSTRACT); + Mockito.verify(spy, Mockito.never()).hasAllOf(element, Modifier.ABSTRACT); + + + } + + @Test + public void testHasOf_oneOf_nullValuedElement() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + MatcherAssert.assertThat(spy.hasOf(ValidatorKind.ONE_OF, null, Modifier.ABSTRACT), Matchers.is(false)); + + Mockito.verify(spy).hasOneOf(null, Modifier.ABSTRACT); + + + } + + @Test + public void testHasOf_atLeastOneOf_nullValuedElement() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + MatcherAssert.assertThat(spy.hasOf(ValidatorKind.AT_LEAST_ONE_OF, null, Modifier.ABSTRACT), Matchers.is(false)); + + Mockito.verify(spy).hasAtLeastOneOf(null, Modifier.ABSTRACT); + + + } + + @Test + public void testHasOf_allOf_nullValuedElement() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + MatcherAssert.assertThat(spy.hasOf(ValidatorKind.ALL_OF, null, Modifier.ABSTRACT), Matchers.is(false)); + + Mockito.verify(spy).hasAllOf(null, Modifier.ABSTRACT); + + + } + + @Test + public void testHasOf_noneOf_nullValuedElement() { + + GenericElementCharacteristicValidator spy = Mockito.spy((GenericElementCharacteristicValidator) Validator.getModifierValidator()); + + MatcherAssert.assertThat(spy.hasOf(ValidatorKind.NONE_OF, null, Modifier.ABSTRACT), Matchers.is(false)); + + Mockito.verify(spy).hasNoneOf(null, Modifier.ABSTRACT); + + + } + + +}