src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
ByElementKindMatcher implements CriteriaMatcher<Element, ElementKind> { @Override public boolean checkForMatchingCharacteristic(Element element, ElementKind toCheckFor) { return (element != null && toCheckFor != null) && element.getKind().equals(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element element, ElementKind toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(ElementKind toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, ElementKind.CLASS)); } @Test public void test_checkForMatchingCharacteristic_mismatch() { Element element = Mockito.mock(Element.class); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, ElementKind.INTERFACE)); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, ElementKind.CLASS)); } @Test public void test_checkForMatchingCharacteristic_nullValuedElementKind() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should return false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should return false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
HasPublicNoargConstructorMatcher implements ImplicitMatcher<Element> { @Override public boolean check(Element element) { if (element == null) { return false; } TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(element.asType()); if (typeElement == null) { return false; } FluentElementFilter<ExecutableElement> fluentElementFilter = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_CONSTRUCTOR); boolean hasLombokNoArgConstructor = AnnotationUtils.getAnnotationMirror(typeElement, "lombok.NoArgsConstructor") != null; boolean hasLombokAllArgsConstructor = AnnotationUtils.getAnnotationMirror(typeElement, "lombok.AllArgsConstructor") != null; boolean hasLombokRequiredArgsConstructor = AnnotationUtils.getAnnotationMirror(typeElement, "lombok.RequiredArgsConstructor") != null; return (fluentElementFilter.isEmpty() && !hasLombokAllArgsConstructor && !hasLombokRequiredArgsConstructor) || hasLombokNoArgConstructor || fluentElementFilter .applyFilter(CoreMatchers.HAS_NO_PARAMETERS) .applyFilter(CoreMatchers.BY_MODIFIER).filterByOneOf(Modifier.PUBLIC) .hasSingleElement(); } @Override boolean check(Element element); }
@Test public void checkDefaultConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(DefaultNoargConstructor.class); MatcherAssert.assertThat("Must return true for class with default constructor", CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(typeElement)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkWithNoargConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(NonNoargConstructor.class); MatcherAssert.assertThat("Must return false for class with no noarg constructor", !CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(typeElement)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkWithPublicNoargConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(NoPublicNoargConstructor.class); MatcherAssert.assertThat("Must return false for class with no public noarg constructor", !CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(typeElement)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkWithPublicNoargConstructorNextToOtherConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(PublicNoargConstructorNextToOtherConstructors.class); MatcherAssert.assertThat("Must return true for class with default constructor", CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(typeElement)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkWithPublicNoargConstructorNextToOtherConstructors() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { Element testElement = FluentElementFilter.createFluentElementFilter( TypeUtils.TypeRetrieval.getTypeElement(HasPublicNoargConstructorMatcherTest.class).getEnclosedElements() ).applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testField") .getResult().get(0); MatcherAssert.assertThat("Must return true for class with default constructor", CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(testElement)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkestNullSafety() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Must return false for null valued parameter", !CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(null)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkestLombokNoConstructoButWithAllArgConstructorAnnotation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Must return false for Class with arg constructor annotated with NoArgsConstructor annotation", CoreMatchers.HAS_PUBLIC_NOARG_CONSTRUCTOR.getMatcher().check(element)); } }) .compilationShouldSucceed() .executeTest(); }
ByReturnTypeFqnMatcher implements CriteriaMatcher<ExecutableElement, String> { @Override public boolean checkForMatchingCharacteristic(ExecutableElement element, String toCheckFor) { if (element == null || toCheckFor == null) { return false; } return TypeUtils.TypeComparison.isTypeEqual(element.getReturnType(), TypeUtils.TypeRetrieval.getTypeMirror(toCheckFor)); } ByReturnTypeFqnMatcher(); @Override boolean checkForMatchingCharacteristic(ExecutableElement element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void byReturnTypeMirrorMatcher_match() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: dound method has to be of zype ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Precondition: method must have a return type", executableElement.getReturnType(), Matchers.notNullValue()); MatcherAssert.assertThat("Precondition: return type must be of type String but is " + executableElement.getParameters().get(0).asType().toString(), executableElement.getReturnType().toString().equals(String.class.getCanonicalName())); MatcherAssert.assertThat("Should have found matching return type", CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, String.class.getCanonicalName())); } }) .compilationShouldSucceed() .executeTest(); } @Test public void byReturnTypeMirrorMatcher_noMatch() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: dound method has to be of zype ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Precondition: method must have a return type", executableElement.getReturnType(), Matchers.notNullValue()); MatcherAssert.assertThat("Precondition: return type must be of type String but is " + executableElement.getParameters().get(0).asType().toString(), executableElement.getReturnType().toString().equals(String.class.getCanonicalName())); MatcherAssert.assertThat("Should have found a non matching return type", !CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, Boolean.class.getCanonicalName())); } }) .compilationShouldSucceed() .executeTest(); } @Test public void byReturnTypeMirrorMatcher_nullValues() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: dound method has to be of zype ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Precondition: method must have a return type", executableElement.getReturnType(), Matchers.notNullValue()); MatcherAssert.assertThat("Precondition: return type must be of type String but is " + executableElement.getParameters().get(0).asType().toString(), executableElement.getReturnType().toString().equals(String.class.getCanonicalName())); MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(null, String.class.getCanonicalName())); MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, null)); MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(null, null)); } }) .compilationShouldSucceed() .executeTest(); }
ByReturnTypeFqnMatcher implements CriteriaMatcher<ExecutableElement, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor : ""; } ByReturnTypeFqnMatcher(); @Override boolean checkForMatchingCharacteristic(ExecutableElement element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().getStringRepresentationOfPassedCharacteristic(null), Matchers.is("")); } }) .compilationShouldSucceed() .executeTest(); } @Test public void getStringRepresentationOfPassedCharacteristic_getStringRepresentation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should have created valid string representation", CoreMatchers.BY_RETURN_TYPE_FQN.getMatcher().getStringRepresentationOfPassedCharacteristic(String.class.getCanonicalName()), Matchers.is(String.class.getCanonicalName())); } }) .compilationShouldSucceed() .executeTest(); }
ByQualifiedNameMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertThat("Should return null for null valued parameter", unit.getStringRepresentationOfPassedCharacteristic(null) == null); }
ByQualifiedNameMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element == null || toCheckFor == null) { return false; } switch (element.getKind()) { case ENUM: case INTERFACE: case ANNOTATION_TYPE: case CLASS: { TypeElement typeElement = ElementUtils.CastElement.castToTypeElement(element); return (typeElement != null && toCheckFor != null) && typeElement.getQualifiedName().toString().equals(toCheckFor); } case PACKAGE: { PackageElement packageElement = (PackageElement) element; return (packageElement != null && toCheckFor != null) && packageElement.getQualifiedName().toString().equals(toCheckFor); } default: { return (element != null && toCheckFor != null) && element.getSimpleName().toString().equals(toCheckFor); } } } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_match_package() { PackageElement element = Mockito.mock(PackageElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.PACKAGE); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_match_method() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.METHOD); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch_package() { PackageElement element = Mockito.mock(PackageElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.PACKAGE); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch_method() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.METHOD); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedAnnotationType() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should retrun false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should return false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
SimpleResourceReader { public String readAsString() throws IOException { char[] buffer = new char[10000]; CharArrayWriter writer = new CharArrayWriter(); int line = 0; while ((line = foReader.read(buffer)) != -1) { writer.write(buffer, 0, line); } foReader.close(); writer.flush(); writer.close(); return writer.toString(); } SimpleResourceReader(FileObject fileObject); String readLine(); String readAsString(); List<String> readAsLines(); List<String> readAsLines(boolean trimLines); Properties readAsProperties(); void close(); }
@Test public void testReadAsString() throws IOException { final String RESOURCE_STRING = "abc\ndef\nhij"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringReader); SimpleResourceReader unit = new SimpleResourceReader(fileObject); MatcherAssert.assertThat(unit.readAsString(), Matchers.equalTo(RESOURCE_STRING)); Mockito.verify(stringReader, Mockito.times(1)).close(); }
IsConstructorMatcher implements ImplicitMatcher<ELEMENT> { @Override public boolean check(ELEMENT element) { return ElementUtils.CheckKindOfElement.isConstructor(element); } @Override boolean check(ELEMENT element); }
@Test public void checkMatchingConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(IsConstructorMatcherTest.class); List<? extends Element> constructors = ElementUtils.AccessEnclosedElements.getEnclosedElementsOfKind(typeElement, ElementKind.CONSTRUCTOR); MatcherAssert.assertThat("Precondition: must have found a enum", constructors.size() >= 1); MatcherAssert.assertThat("Should return true for enum : ", CoreMatchers.IS_CONSTRUCTOR.getMatcher().check(constructors.get(0))); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkMismatchingConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for non constructor : ", !CoreMatchers.IS_CONSTRUCTOR.getMatcher().check(element)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checknullValuedElement() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for null valued element : ", !CoreMatchers.IS_CONSTRUCTOR.getMatcher().check(null)); } }) .compilationShouldSucceed() .executeTest(); }
IsAssignableToMatcher implements CriteriaMatcher<Element, Class> { @Override public boolean checkForMatchingCharacteristic(Element element, Class toCheckFor) { return element != null && toCheckFor != null && TypeUtils.getTypes() .isAssignable( element.asType(), TypeUtils.TypeRetrieval.getTypeMirror(toCheckFor.getCanonicalName()) ); } @Override String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor); @Override boolean checkForMatchingCharacteristic(Element element, Class toCheckFor); }
@Test public void checkMatchingAssignableToCase() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return true for matching assignable to case : ", CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkForMatchingCharacteristic(TypeUtils.TypeRetrieval.getTypeElement(String.class), Object.class)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkMismatchingAssignableToCase() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for mismatching assignable to case : ", !CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkForMatchingCharacteristic(TypeUtils.TypeRetrieval.getTypeElement(Object.class), String.class)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkNullValuedElementAndClass() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for null valued element : ", !CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkForMatchingCharacteristic(null, String.class)); MatcherAssert.assertThat("Should return false for null valued assignable to class : ", !CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkForMatchingCharacteristic(element, null)); MatcherAssert.assertThat("Should return false for null valued element and assignable to class : ", !CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkForMatchingCharacteristic(null, null)); } }) .compilationShouldSucceed() .executeTest(); }
SimpleResourceReader { public List<String> readAsLines() throws IOException { return readAsLines(false); } SimpleResourceReader(FileObject fileObject); String readLine(); String readAsString(); List<String> readAsLines(); List<String> readAsLines(boolean trimLines); Properties readAsProperties(); void close(); }
@Test public void testReadAsLines() throws IOException { final String RESOURCE_STRING = "abc\ndef\nhij"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringReader); SimpleResourceReader unit = new SimpleResourceReader(fileObject); MatcherAssert.assertThat(unit.readAsLines(), Matchers.contains("abc", "def", "hij")); Mockito.verify(stringReader, Mockito.times(1)).close(); }
IsAssignableToMatcher implements CriteriaMatcher<Element, Class> { @Override public String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.getCanonicalName() : null; } @Override String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor); @Override boolean checkForMatchingCharacteristic(Element element, Class toCheckFor); }
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().getStringRepresentationOfPassedCharacteristic(null), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); } @Test public void getStringRepresentationOfPassedCharacteristic_getStringRepresentation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().getStringRepresentationOfPassedCharacteristic(null), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
HasNoThrownTypesMatcher implements ImplicitMatcher<ExecutableElement> { @Override public boolean check(ExecutableElement element) { return element != null && element.getThrownTypes().size() == 0; } @Override boolean check(ExecutableElement element); }
@Test public void test_check_withNullValue() { MatcherAssert.assertThat(CoreMatchers.HAS_NO_THROWN_TYPES.getMatcher().check(null), Matchers.is(false)); } @Test public void test_check_withoutThrownTypes() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirror.class); Mockito.when(element.getThrownTypes()).thenReturn(Collections.EMPTY_LIST); MatcherAssert.assertThat(CoreMatchers.HAS_NO_THROWN_TYPES.getMatcher().check(element), Matchers.is(true)); } @Test public void test_check_withNonVoidReturnType() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirror.class); List list = new ArrayList<TypeMirror>(); list.add(Mockito.mock(TypeMirror.class)); Mockito.when(element.getThrownTypes()).thenReturn(list); MatcherAssert.assertThat(CoreMatchers.HAS_NO_THROWN_TYPES.getMatcher().check(element), Matchers.is(false)); }
IsAttributeFieldMatcher implements ImplicitMatcher<VariableElement> { @Override public boolean check(VariableElement element) { if (element == null || element.getKind() != ElementKind.FIELD) { return false; } return BeanUtils.isAttribute(element); } @Override boolean check(VariableElement element); }
@Test public void test_isAttributeField_match__shouldReturnTrue() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return true for non static field with getter and setter : ", CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("validAttributeField"))); } }) .compilationShouldSucceed() .executeTest(); ; } @Test public void test_isNoAttributeField_noGetter_shouldReturnFalse() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for non static field without getter : ", !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("fieldWithoutGetter"))); } }) .compilationShouldSucceed() .executeTest(); ; } @Test public void test_isNoAttributeField_noSetter_shouldReturnFalse() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for non static field without setter : ", !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("fieldWithoutSetter"))); } }) .compilationShouldSucceed() .executeTest(); ; } @Test public void test_isNoAttributeField_isStatic_shouldReturnFalse() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for static field : ", !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("staticField"))); } }) .compilationShouldSucceed() .executeTest(); ; } @Test public void test_passedNullValue_shouldReturnFalse() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for passed null value : ", !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(null)); } }) .compilationShouldSucceed() .executeTest(); ; }
SimpleResourceReader { public Properties readAsProperties() throws IOException { Properties properties = new Properties(); try { properties.load(foReader); } finally { foReader.close(); } return properties; } SimpleResourceReader(FileObject fileObject); String readLine(); String readAsString(); List<String> readAsLines(); List<String> readAsLines(boolean trimLines); Properties readAsProperties(); void close(); }
@Test public void testReadAsProperties() throws IOException { final String RESOURCE_STRING = "a=1\nb=2\nc=3"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringReader); SimpleResourceReader unit = new SimpleResourceReader(fileObject); Properties result = unit.readAsProperties(); MatcherAssert.assertThat(result.get("a"), Matchers.equalTo((Object) "1")); MatcherAssert.assertThat(result.get("b"), Matchers.equalTo((Object) "2")); MatcherAssert.assertThat(result.get("c"), Matchers.equalTo((Object) "3")); Mockito.verify(stringReader, Mockito.times(1)).close(); }
HasVoidReturnTypeMatcher implements ImplicitMatcher<ExecutableElement> { @Override public boolean check(ExecutableElement element) { return element != null && TypeUtils.CheckTypeKind.isVoid(element.getReturnType()); } @Override boolean check(ExecutableElement element); }
@Test public void test_check_withNullValue() { MatcherAssert.assertThat(CoreMatchers.HAS_VOID_RETURN_TYPE.getMatcher().check(null), Matchers.is(false)); } @Test public void test_check_withVoidReturnType() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirror.class); Mockito.when(element.getReturnType()).thenReturn(typeMirror); Mockito.when(typeMirror.getKind()).thenReturn(TypeKind.VOID); MatcherAssert.assertThat(CoreMatchers.HAS_VOID_RETURN_TYPE.getMatcher().check(element), Matchers.is(true)); } @Test public void test_check_withNonVoidReturnType() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirror.class); Mockito.when(element.getReturnType()).thenReturn(typeMirror); Mockito.when(typeMirror.getKind()).thenReturn(TypeKind.ARRAY); MatcherAssert.assertThat(CoreMatchers.HAS_VOID_RETURN_TYPE.getMatcher().check(element), Matchers.is(false)); }
ByNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertThat("Should return null for null valued parameter", unit.getStringRepresentationOfPassedCharacteristic(null) == null); }
ByNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element != null && toCheckFor != null) { Pattern pattern = Pattern.compile(toCheckFor); return pattern.matcher(element.getSimpleName().toString()).matches(); } return false; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, "N.*E")); } @Test public void test_checkForMatchingCharacteristic_mismatch() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test(expected = PatternSyntaxException.class) public void test_checkForMatchingCharacteristic_invalidRegex() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); unit.checkForMatchingCharacteristic(element, "ABC{"); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedAnnotationType() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should retrun false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should return false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
ImplicitFilter { public List<ELEMENT> filter(List<ELEMENT> toFilter) { return filter(toFilter, false); } ImplicitFilter(VALIDATOR validator); List<ELEMENT> filter(List<ELEMENT> toFilter); List<ELEMENT> filter(List<ELEMENT> toFilter, boolean invertFilter); }
@Test public void testImplicitFilter_allMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true).getValidator()); List<Element> result = unit.filter(list); MatcherAssert.assertThat(result, Matchers.contains(element1, element2, element3)); } @Test public void testImplicitFilter_oneNotMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true, false, true).getValidator()); List<Element> result = unit.filter(list); MatcherAssert.assertThat(result, Matchers.contains(element1, element3)); } @Test public void testImplicitFilter_allNotMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); List<Element> result = unit.filter(list); MatcherAssert.assertThat(result, Matchers.<Element>empty()); } @Test public void testImplicitFilter_inverted_allMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); List<Element> result = unit.filter(list, true); MatcherAssert.assertThat(result, Matchers.contains(element1, element2, element3)); } @Test public void testImplicitFilter_inverted_oneNotMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true, false, true).getValidator()); List<Element> result = unit.filter(list, true); MatcherAssert.assertThat(result, Matchers.contains(element2)); } @Test public void testImplicitFilter_inverted_allNotMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); List<Element> result = unit.filter(list, true); MatcherAssert.assertThat(result, Matchers.contains(element1, element2, element3)); } @Test public void testImplicitFilter_nullSafety_nullValuedValidator() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(null); List<Element> result = unit.filter(list); MatcherAssert.assertThat(result, Matchers.empty()); } @Test public void testImplicitFilter_nullSafety_nullListToFilter() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", false).getValidator()); List<Element> result = unit.filter(null); MatcherAssert.assertThat(result, Matchers.empty()); }
ByNumberOfParametersMatcher implements CriteriaMatcher<ExecutableElement, Integer> { @Override public boolean checkForMatchingCharacteristic(ExecutableElement element, Integer toCheckFor) { return (element != null && toCheckFor != null) && element.getParameters().size() == toCheckFor; } @Override boolean checkForMatchingCharacteristic(ExecutableElement element, Integer toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Integer toGetStringRepresentationFor); }
@Test public void byNumberOfParametersMatcher_methodWith0Parameters() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(ByNumberOfParametersMatcherTest.class); MatcherAssert.assertThat("Precondition: should have found TypeElement", typeElement, Matchers.notNullValue()); List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(typeElement, "noParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: found method has to be of type ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Should match 0 parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 0)); MatcherAssert.assertThat("Should match 1 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 1)); MatcherAssert.assertThat("Should match 2 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 2)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void byNumberOfParametersMatcher_methodWith1Parameters() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(ByNumberOfParametersMatcherTest.class); MatcherAssert.assertThat("Precondition: should have found TypeElement", typeElement, Matchers.notNullValue()); List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(typeElement, "oneParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: found method has to be of type ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Should match 0 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 0)); MatcherAssert.assertThat("Should match 1 parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 1)); MatcherAssert.assertThat("Should match 2 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 2)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void byNumberOfParametersMatcher_methodWith2Parameters() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(ByNumberOfParametersMatcherTest.class); MatcherAssert.assertThat("Precondition: should have found TypeElement", typeElement, Matchers.notNullValue()); List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(typeElement, "twoParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: found method has to be of type ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Should match 0 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 0)); MatcherAssert.assertThat("Should match 1 parameters", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 1)); MatcherAssert.assertThat("Should match 2 parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, 2)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void byNumberOfParametersMatcher_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); MatcherAssert.assertThat("Precondition: should have found one method", result.size() == 1); MatcherAssert.assertThat("Precondition: dound method has to be of type ExecutableElement", result.get(0) instanceof ExecutableElement); ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Precondition: method must have 2 parameters", executableElement.getParameters().size() == 2); MatcherAssert.assertThat("Should return false", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(executableElement, null)); MatcherAssert.assertThat("Should return false", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(null, 1)); MatcherAssert.assertThat("Should return false", !CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().checkForMatchingCharacteristic(null, null)); } }) .compilationShouldSucceed() .executeTest(); }
ByNumberOfParametersMatcher implements CriteriaMatcher<ExecutableElement, Integer> { @Override public String getStringRepresentationOfPassedCharacteristic(Integer toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.toString() : null; } @Override boolean checkForMatchingCharacteristic(ExecutableElement element, Integer toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Integer toGetStringRepresentationFor); }
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().getStringRepresentationOfPassedCharacteristic(null), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); } @Test public void getStringRepresentationOfPassedCharacteristic_getStringRepresentation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS.getMatcher().getStringRepresentationOfPassedCharacteristic(null), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
ByNameMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertThat("Should return null for null valued parameter", unit.getStringRepresentationOfPassedCharacteristic(null) == null); }
ByNameMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { return (element != null && toCheckFor != null) && element.getSimpleName().toString().equals(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedAnnotationType() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should retrun false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should retrun false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
IsVariableElementMatcher implements ImplicitMatcher<ELEMENT> { @Override public boolean check(ELEMENT element) { return ElementUtils.CastElement.isVariableElement(element); } @Override boolean check(ELEMENT element); }
@Test public void checkMatchingVariableElement_field() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsOfKind(TypeUtils.TypeRetrieval.getTypeElement(IsVariableElementMatcherTest.class), ElementKind.FIELD); MatcherAssert.assertThat("Precondition: should have found one field", result.size() >= 1); MatcherAssert.assertThat("Precondition: found method has to be of type VariableElement", result.get(0) instanceof VariableElement); MatcherAssert.assertThat("Should return true for field : ", CoreMatchers.IS_VARIABLE_ELEMENT.getMatcher().check(result.get(0))); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkMismatchingVariableElement_class() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for non VariableElement : ", !CoreMatchers.IS_VARIABLE_ELEMENT.getMatcher().check(element)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkMismatchingVariableElement_nullValuedElement() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false for null valued element : ", !CoreMatchers.IS_VARIABLE_ELEMENT.getMatcher().check(null)); } }) .compilationShouldSucceed() .executeTest(); }
ByQualifiedNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertThat("Should return null for null valued parameter", unit.getStringRepresentationOfPassedCharacteristic(null) == null); }
ByQualifiedNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element != null && toCheckFor != null) { String name = null; switch (element.getKind()) { case ENUM: case INTERFACE: case ANNOTATION_TYPE: case CLASS: { TypeElement typeElement = ElementUtils.CastElement.castToTypeElement(element); name = typeElement.getQualifiedName().toString(); break; } case PACKAGE: { PackageElement packageElement = (PackageElement) element; name = packageElement.getQualifiedName().toString(); break; } default: { name = element.getSimpleName().toString(); } } Pattern pattern = Pattern.compile(toCheckFor); return pattern.matcher(name).matches(); } return false; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, "N.*E")); } @Test public void test_checkForMatchingCharacteristic_match_package() { PackageElement element = Mockito.mock(PackageElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.PACKAGE); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, "N.*E")); } @Test public void test_checkForMatchingCharacteristic_match_method() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.METHOD); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, "N.*E")); } @Test public void test_checkForMatchingCharacteristic_mismatch_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch_package() { PackageElement element = Mockito.mock(PackageElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.PACKAGE); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test public void test_checkForMatchingCharacteristic_mismatch_method() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.METHOD); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, NAME)); } @Test(expected = PatternSyntaxException.class) public void test_checkForMatchingCharacteristic_invalidRegex() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn("XXX"); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQualifiedName()).thenReturn(nameOfElement); unit.checkForMatchingCharacteristic(element, "ABC{"); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, NAME)); } @Test public void test_checkForMatchingCharacteristic_nullValuedAnnotationType() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should retrun false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should return false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
ByRawTypeMatcher implements CriteriaMatcher<Element, Class> { @Override public String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.getCanonicalName() : null; } ByRawTypeMatcher(); @Override boolean checkForMatchingCharacteristic(Element element, Class toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor); }
@Test public void getStringRepresentationOfPassedCharacteristic_happyPath() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return cannonical class name of annotation class", CoreMatchers.BY_RAW_TYPE.getMatcher().getStringRepresentationOfPassedCharacteristic(ByRawTypeMatcherTest.class).equals(ByRawTypeMatcherTest.class.getCanonicalName())); } }) .compilationShouldSucceed() .executeTest(); } @Test public void getStringRepresentationOfPassedCharacteristic_passedNullValue_shouldReturnNull() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return null for null valued parameter", CoreMatchers.BY_RAW_TYPE.getMatcher().getStringRepresentationOfPassedCharacteristic(null) == null); } }) .compilationShouldSucceed() .executeTest(); }
ByRawTypeMatcher implements CriteriaMatcher<Element, Class> { @Override public boolean checkForMatchingCharacteristic(Element element, Class toCheckFor) { if (element == null || toCheckFor == null) { return false; } return TypeUtils.TypeComparison.isErasedTypeEqual(element.asType(), TypeUtils.TypeRetrieval.getTypeMirror(toCheckFor)); } ByRawTypeMatcher(); @Override boolean checkForMatchingCharacteristic(Element element, Class toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor); }
@Test public void checkForMatchingCharacteristic_match() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement tmpElement = TypeUtils.TypeRetrieval.getTypeElement(ByRawTypeMatcherTest.class); MatcherAssert.assertThat("Should find match correctly", CoreMatchers.BY_RAW_TYPE.getMatcher().checkForMatchingCharacteristic(tmpElement, ByRawTypeMatcherTest.class)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkForMatchingCharacteristic_mismatch() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement tmpElement = TypeUtils.TypeRetrieval.getTypeElement(String.class); MatcherAssert.assertThat("Should find match correctly", !CoreMatchers.BY_RAW_TYPE.getMatcher().checkForMatchingCharacteristic(tmpElement, ByRawTypeMatcherTest.class)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkForMatchingCharacteristic_nullValuedElement() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false in case of null valued element", !CoreMatchers.BY_RAW_TYPE.getMatcher().checkForMatchingCharacteristic(null, TestAnnotation.class)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkForMatchingCharacteristic_nullValuedRawType() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false in case of null valued annotation", !CoreMatchers.BY_RAW_TYPE.getMatcher().checkForMatchingCharacteristic(element, null)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void checkForMatchingCharacteristic_nullValuedElementAndRawType() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return false in case of null valued parameters", !CoreMatchers.BY_RAW_TYPE.getMatcher().checkForMatchingCharacteristic(null, null)); } }) .compilationShouldSucceed() .executeTest(); }
ByModifierMatcher implements CriteriaMatcher<Element, Modifier> { @Override public String getStringRepresentationOfPassedCharacteristic(Modifier toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.name() : null; } @Override boolean checkForMatchingCharacteristic(Element element, Modifier toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Modifier toGetStringRepresentationFor); }
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(Modifier.FINAL).equals(Modifier.FINAL.name())); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertThat("Should return null for null valued parameter", unit.getStringRepresentationOfPassedCharacteristic(null) == null); }
ByModifierMatcher implements CriteriaMatcher<Element, Modifier> { @Override public boolean checkForMatchingCharacteristic(Element element, Modifier toCheckFor) { return (element != null && toCheckFor != null) && element.getModifiers().contains(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element element, Modifier toCheckFor); @Override String getStringRepresentationOfPassedCharacteristic(Modifier toGetStringRepresentationFor); }
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Set<Modifier> modifierSet = new HashSet<Modifier>(); modifierSet.add(Modifier.FINAL); Mockito.when(element.getModifiers()).thenReturn(modifierSet); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, Modifier.FINAL)); } @Test public void test_checkForMatchingCharacteristic_mismatch() { Element element = Mockito.mock(Element.class); Set<Modifier> modifierSet = new HashSet<Modifier>(); modifierSet.add(Modifier.FINAL); Mockito.when(element.getModifiers()).thenReturn(modifierSet); MatcherAssert.assertThat("Should find mismatch correctly", !unit.checkForMatchingCharacteristic(element, Modifier.PUBLIC)); } @Test public void test_checkForMatchingCharacteristic_nullValuedElement() { MatcherAssert.assertThat("Should return false in case of null valued element", !unit.checkForMatchingCharacteristic(null, Modifier.ABSTRACT)); } @Test public void test_checkForMatchingCharacteristic_nullValuedAnnotationType() { Element element = Mockito.mock(Element.class); MatcherAssert.assertThat("Should retrun false in case of null valued annotation", !unit.checkForMatchingCharacteristic(element, null)); } @Test public void test_checkForMatchingCharacteristic_nullValuedParameters() { MatcherAssert.assertThat("Should retrun false in case of null valued parameters", !unit.checkForMatchingCharacteristic(null, null)); }
CriteriaElementValidatorImpl { @SafeVarargs public final <ELEMENT extends Element, CRITERIA, MATCHER extends CriteriaMatcher<ELEMENT, CRITERIA>> boolean validateByValidatorKind(ValidatorKind validatorKind, MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { if (validatorKind == null) { return false; } switch (validatorKind) { case HAS_ONE_OF: return hasOneOf(matcher, element, criteriaToCheck); case HAS_NONE_OF: return hasNoneOf(matcher, element, criteriaToCheck); case HAS_AT_LEAST_ONE_OF: return hasAtLeastOneOf(matcher, element, criteriaToCheck); case HAS_ALL_OF: return hasAllOf(matcher, element, criteriaToCheck); } return false; } private CriteriaElementValidatorImpl(); @SafeVarargs final boolean validateByValidatorKind(ValidatorKind validatorKind, MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck); @SafeVarargs final boolean hasOneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck); @SafeVarargs final boolean hasNoneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck); @SafeVarargs final boolean hasAllOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck); @SafeVarargs final boolean hasAtLeastOneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck); static CriteriaElementValidatorImpl INSTANCE; }
@Test public void validateByValidatorKind_null_safety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if validator kind is null", !unit.validateByValidatorKind(null, matcherSpy, element, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); } @Test public void validateByValidatorKind_oneOf_test() { MatcherAssert.assertThat("Should be validated as true", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, SUCCEEDING_MATCHER, element, "TEST")); MatcherAssert.assertThat("Should be validated as false", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, FAILING_MATCHER, element, "TEST")); } @Test public void validateByValidatorKind_oneOf_nullSafety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if matcher is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, null, element, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, SUCCEEDING_MATCHER, null, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, null, null, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if no criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, SUCCEEDING_MATCHER, element)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if single null criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, SUCCEEDING_MATCHER, element, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if two null valued criteria are used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, SUCCEEDING_MATCHER, element, null, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); } @Test public void validateByValidatorKind_noneOf_test() { MatcherAssert.assertThat("Should be validated as false if Matcher matches", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, SUCCEEDING_MATCHER, element, "TEST")); MatcherAssert.assertThat("Should be validated as true if Matcher doesn't match", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, FAILING_MATCHER, element, "TEST")); } @Test public void validateByValidatorKind_noneOf_nullSafety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if matcher is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, null, element, "TEST")); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcherSpy, null, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, null, null, "TEST")); MatcherAssert.assertThat("Should return true if no criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcherSpy, element)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if single null criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcherSpy, element, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if two null valued criteria are used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcherSpy, element, null, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); } @Test public void validateByValidatorKind_atLeastOneOf_test() { MatcherAssert.assertThat("Should be validated as true", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, SUCCEEDING_MATCHER, element, "TEST")); MatcherAssert.assertThat("Should be validated as false", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, FAILING_MATCHER, element, "TEST")); } @Test public void validateByValidatorKind_atLeastOneOf_nullSafety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if matcher is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, null, element, "TEST")); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcherSpy, null, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, null, null, "TEST")); MatcherAssert.assertThat("Should return true if no criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcherSpy, element)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if single null criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcherSpy, element, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if two null valued criteria are used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcherSpy, element, null, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); } @Test public void validateByValidatorKind_allOf_test() { MatcherAssert.assertThat("Should be validated as true", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, SUCCEEDING_MATCHER, element, "TEST")); MatcherAssert.assertThat("Should be validated as false", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, FAILING_MATCHER, element, "TEST")); } @Test public void validateByValidatorKind_allOf_nullSafety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if matcher is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, null, element, "TEST")); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcherSpy, null, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return false if element is null", !unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, null, null, "TEST")); MatcherAssert.assertThat("Should return true if no criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcherSpy, element)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if single null criteria is used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcherSpy, element, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); MatcherAssert.assertThat("Should return true if two null valued criteria are used", unit.validateByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcherSpy, element, null, null)); Mockito.verify(matcherSpy, Mockito.never()).checkForMatchingCharacteristic(Mockito.any(Element.class), Mockito.any(String.class)); }
MessagerUtils { public static Messager getMessager() { return ProcessingEnvironmentUtils.getMessager(); } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String message, Object... args); static void warning(Element e, String message, Object... args); static void mandatoryWarning(Element e, String message, Object... args); static void info(Element e, String message, Object... args); static void other(Element e, String message, Object... args); static void error(Element e, ValidationMessage message, Object... args); static void warning(Element e, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, ValidationMessage message, Object... args); static void info(Element e, ValidationMessage message, Object... args); static void other(Element e, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, String message, Object... args); static void warning(Element e, AnnotationMirror a, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, String message, Object... args); static void info(Element e, AnnotationMirror a, String message, Object... args); static void other(Element e, AnnotationMirror a, String message, Object... args); static void error(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, ValidationMessage message, Object... args); static Messager getMessager(); static MessagerUtils getMessagerUtils(); static String createMessage(String message, Object... messageParameters); static String createMessage(ValidationMessage message, Object... messageParameters); }
@Test public void testGetMessaggerUtils() { MatcherAssert.assertThat(unit.getMessager(), Matchers.is(messager)); }
MessagerUtils { public static String createMessage(String message, Object... messageParameters) { String result = message; if (messageParameters != null) { for (int i = 0; i < messageParameters.length; i++) { result = result.replaceAll("\\$\\{" + i + "\\}", messageParameters[i] != null ? messageParameters[i].toString() : "null"); } } return result; } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String message, Object... args); static void warning(Element e, String message, Object... args); static void mandatoryWarning(Element e, String message, Object... args); static void info(Element e, String message, Object... args); static void other(Element e, String message, Object... args); static void error(Element e, ValidationMessage message, Object... args); static void warning(Element e, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, ValidationMessage message, Object... args); static void info(Element e, ValidationMessage message, Object... args); static void other(Element e, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, String message, Object... args); static void warning(Element e, AnnotationMirror a, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, String message, Object... args); static void info(Element e, AnnotationMirror a, String message, Object... args); static void other(Element e, AnnotationMirror a, String message, Object... args); static void error(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, ValidationMessage message, Object... args); static Messager getMessager(); static MessagerUtils getMessagerUtils(); static String createMessage(String message, Object... messageParameters); static String createMessage(ValidationMessage message, Object... messageParameters); }
@Test public void createMessage_exactNumberOfParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, ${2}, ${1}", 1, "YES", true), Matchers.is("TEST 1, true, YES")); } @Test public void createMessage_smallerNumberOfParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, ${2}, ${1}", 1, "YES"), Matchers.is("TEST 1, ${2}, YES")); } @Test public void createMessage_greaterNumberOfParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, ${2}, ${1}", 1, "YES", true, "WTF"), Matchers.is("TEST 1, true, YES")); } @Test public void createMessage_noParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, ${2}, ${1}"), Matchers.is("TEST ${0}, ${2}, ${1}")); }
MessagerUtils { protected static String argToString(Object arg){ if(arg == null) { return "<NULL>"; } else if (arg.getClass().isArray()) { StringBuilder stringBuilder = new StringBuilder("["); boolean first = true; for (Object argument : (Object[])arg) { if(first) { first = false; } else { stringBuilder.append(", "); } stringBuilder.append(argToString(argument)); } stringBuilder.append("]"); return stringBuilder.toString(); } else if (Collection.class.isAssignableFrom(arg.getClass())) { StringBuilder stringBuilder = new StringBuilder("["); boolean first = true; for (Object argument : (Collection)arg) { if(first) { first = false; } else { stringBuilder.append(", "); } stringBuilder.append(argToString(argument)); } stringBuilder.append("]"); return stringBuilder.toString(); } return arg.toString(); } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String message, Object... args); static void warning(Element e, String message, Object... args); static void mandatoryWarning(Element e, String message, Object... args); static void info(Element e, String message, Object... args); static void other(Element e, String message, Object... args); static void error(Element e, ValidationMessage message, Object... args); static void warning(Element e, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, ValidationMessage message, Object... args); static void info(Element e, ValidationMessage message, Object... args); static void other(Element e, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, String message, Object... args); static void warning(Element e, AnnotationMirror a, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, String message, Object... args); static void info(Element e, AnnotationMirror a, String message, Object... args); static void other(Element e, AnnotationMirror a, String message, Object... args); static void error(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, ValidationMessage message, Object... args); static Messager getMessager(); static MessagerUtils getMessagerUtils(); static String createMessage(String message, Object... messageParameters); static String createMessage(ValidationMessage message, Object... messageParameters); }
@Test public void argToString_nullValue() { MatcherAssert.assertThat(MessagerUtils.argToString(null), Matchers.is("<NULL>")); } @Test public void argToString_arrayValue() { String[] array = {"A", "B", "C"}; MatcherAssert.assertThat(MessagerUtils.argToString(array), Matchers.is("[A, B, C]")); } @Test public void argToString_collectionValue() { String[] array = {"A", "B", "C"}; MatcherAssert.assertThat(MessagerUtils.argToString(Arrays.asList(array)), Matchers.is("[A, B, C]")); } @Test public void argToString_otherValue() { MatcherAssert.assertThat(MessagerUtils.argToString(1), Matchers.is("1")); }
MessagerUtils { public static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args) { printMessage(e, kind, PlainValidationMessage.create(message), args); } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String message, Object... args); static void warning(Element e, String message, Object... args); static void mandatoryWarning(Element e, String message, Object... args); static void info(Element e, String message, Object... args); static void other(Element e, String message, Object... args); static void error(Element e, ValidationMessage message, Object... args); static void warning(Element e, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, ValidationMessage message, Object... args); static void info(Element e, ValidationMessage message, Object... args); static void other(Element e, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, String message, Object... args); static void warning(Element e, AnnotationMirror a, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, String message, Object... args); static void info(Element e, AnnotationMirror a, String message, Object... args); static void other(Element e, AnnotationMirror a, String message, Object... args); static void error(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, ValidationMessage message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, String message, Object... args); static void error(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void warning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void mandatoryWarning(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void info(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void other(Element e, AnnotationMirror a, AnnotationValue v, ValidationMessage message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, String message, Object... args); static void printMessage(Element e, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, Diagnostic.Kind kind, ValidationMessage message, Object... args); static void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Diagnostic.Kind kind, ValidationMessage message, Object... args); static Messager getMessager(); static MessagerUtils getMessagerUtils(); static String createMessage(String message, Object... messageParameters); static String createMessage(ValidationMessage message, Object... messageParameters); }
@Test public void printMessage_testStringBasedMessage() { unit.printMessage(element, Diagnostic.Kind.ERROR, MESSSAGE, MESSAGE_ARG_1, MESSAGE_ARG_2); Mockito.verify(messager).printMessage(Diagnostic.Kind.ERROR, MESSSAGE_STR_WITH_REPLACED_ARGUMENTS, element); } @Test public void printMessage_testStringBasedMessageWithAnnotationMirror() { unit.printMessage(element, annotationMirror, Diagnostic.Kind.ERROR, MESSSAGE, MESSAGE_ARG_1, MESSAGE_ARG_2); Mockito.verify(messager).printMessage(Diagnostic.Kind.ERROR, MESSSAGE_STR_WITH_REPLACED_ARGUMENTS, element, annotationMirror); } @Test public void printMessage_testStringBasedMessageWithAnnotationMirrorAndValue() { unit.printMessage(element, annotationMirror, annotationValue, Diagnostic.Kind.ERROR, MESSSAGE, MESSAGE_ARG_1, MESSAGE_ARG_2); Mockito.verify(messager).printMessage(Diagnostic.Kind.ERROR, MESSSAGE_STR_WITH_REPLACED_ARGUMENTS, element, annotationMirror, annotationValue); }
TypeUtils { public static Types getTypes() { return ProcessingEnvironmentUtils.getTypes(); } private TypeUtils(); static Types getTypes(); }
@Test public void typeUtils_typeRetrieval_getTypes_getEncapsulatedTypesInstance() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat(TypeUtils.getTypes(), Matchers.notNullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isLong(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Long.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isLong() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isLong(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isInteger(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Integer.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isInteger() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isInteger(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isFloat(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Float.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isFloat() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isFloat(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isDouble(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Double.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isDouble() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isDouble(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isBoolean(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Boolean.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isBoolean() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isBoolean(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isString(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, String.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isString() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isString(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isChar(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Character.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isChar() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isChar(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isEnum(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, VariableElement.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isEnum() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isEnum(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isClass(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, TypeMirror.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isClass() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isClass(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isAnnotation(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, AnnotationMirror.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isAnnotation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isAnnotation(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(false)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static boolean isArray(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, List.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_isArray() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.is(false)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.isArray(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.is(true)); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Long getLongValue(AnnotationValue annotationValue) { return !isLong(annotationValue) ? null : (Long) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getLongValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.is(1L)); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getLongValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Integer getIntegerValue(AnnotationValue annotationValue) { return !isInteger(annotationValue) ? null : (Integer) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getIntegerValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.is(1)); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getIntegerValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Float getFloatValue(AnnotationValue annotationValue) { return !isFloat(annotationValue) ? null : (Float) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getFloatValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.is(1.0f)); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getFloatValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
InclusiveCriteriaElementFilter { @SafeVarargs public final <PARAM_ELEMENT extends ELEMENT> List<PARAM_ELEMENT> filterByAllOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck) { return filterByAllOf(elements, false, criteriaToCheck); } InclusiveCriteriaElementFilter(VALIDATOR validator); @SafeVarargs final List<PARAM_ELEMENT> filterByOneOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByOneOf(List<PARAM_ELEMENT> elements, boolean invertFilter, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByNoneOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByNoneOf(List<PARAM_ELEMENT> elements, boolean invertFilter, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByAtLeastOneOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByAtLeastOneOf(List<PARAM_ELEMENT> elements, boolean invertFilter, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByAllOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck); @SafeVarargs final List<PARAM_ELEMENT> filterByAllOf(List<PARAM_ELEMENT> elements, boolean invertFilter, CRITERIA... criteriaToCheck); }
@Test public void findByAll_happyPath() { CompileTestBuilder .unitTest() .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<Element> filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List<Element>) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED); MatcherAssert.assertThat("Must have exactly one element'", filteredList, Matchers.hasSize(1)); MatcherAssert.assertThat("Must find one element with name 'synchronizedMethod'", filteredList.get(0).getSimpleName().toString(), Matchers.is("synchronizedMethod")); filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List<Element>) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED, Modifier.PROTECTED); MatcherAssert.assertThat("Must have noelement'", filteredList, Matchers.<Element>empty()); } }) .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java")) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Double getDoubleValue(AnnotationValue annotationValue) { return !isDouble(annotationValue) ? null : (Double) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getDoubleValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.is(1.0)); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getDoubleValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Boolean getBooleanValue(AnnotationValue annotationValue) { return !isBoolean(annotationValue) ? null : (Boolean) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getBooleanValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.is(true)); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getBooleanValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static String getStringValue(AnnotationValue annotationValue) { return !isString(annotationValue) ? null : (String) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getStringValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.is("stringValue")); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getStringValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static Character getCharValue(AnnotationValue annotationValue) { return !isChar(annotationValue) ? null : (Character) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getCharValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.is('C')); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getCharValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static VariableElement getEnumValue(AnnotationValue annotationValue) { return !isEnum(annotationValue) ? null : (VariableElement) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getEnumValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")).getSimpleName().toString(), Matchers.is(StandardLocation.SOURCE_OUTPUT.name())); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); } @Test public void annotationValueUtils_test_getClassValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")).getSimpleName().toString(), Matchers.is(StandardLocation.SOURCE_OUTPUT.name())); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getEnumValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
AnnotationValueUtils { public static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue) { return !isAnnotation(annotationValue) ? null : (AnnotationMirror) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boolean isBoolean(AnnotationValue annotationValue); static boolean isFloat(AnnotationValue annotationValue); static boolean isDouble(AnnotationValue annotationValue); static boolean isString(AnnotationValue annotationValue); static boolean isChar(AnnotationValue annotationValue); static boolean isEnum(AnnotationValue annotationValue); static boolean isClass(AnnotationValue annotationValue); static boolean isArray(AnnotationValue annotationValue); static boolean isAnnotation(AnnotationValue annotationValue); static Long getLongValue(AnnotationValue annotationValue); static Integer getIntegerValue(AnnotationValue annotationValue); static Boolean getBooleanValue(AnnotationValue annotationValue); static Float getFloatValue(AnnotationValue annotationValue); static Double getDoubleValue(AnnotationValue annotationValue); static String getStringValue(AnnotationValue annotationValue); static Character getCharValue(AnnotationValue annotationValue); static TypeMirror getClassValue(AnnotationValue annotationValue); static String getClassValueAsFQN(AnnotationValue annotationValue); static TypeMirror getTypeMirrorValue(AnnotationValue annotationValue); static VariableElement getEnumValue(AnnotationValue annotationValue); static T getEnumValue(Class<T> enumType, AnnotationValue annotationValue); static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue); static List<? extends AnnotationValue> getArrayValue(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(AnnotationValue annotationValue); static TypeMirror[] getTypeAttributeValueArray(List<? extends AnnotationValue> annotationValues); static T[] convertAndCastAttributeValueListToArray(List<? extends AnnotationValue> annotatedValues, Class<T> type); static Long[] getLongValueArray(AnnotationValue annotationValue); static Long[] getLongValueArray(List<? extends AnnotationValue> annotationValues); static Integer[] getIntegerValueArray(AnnotationValue annotationValue); static Integer[] getIntegerValueArray(List<? extends AnnotationValue> annotationValues); static Double[] getDoubleValueArray(AnnotationValue annotationValue); static Double[] getDoubleValueArray(List<? extends AnnotationValue> annotationValues); static Float[] getFloatValueArray(AnnotationValue annotationValue); static Float[] getFloatValueArray(List<? extends AnnotationValue> annotationValues); static Boolean[] getBooleanValueArray(AnnotationValue annotationValue); static Boolean[] getBooleanValueArray(List<? extends AnnotationValue> annotationValues); static Character[] getCharValueArray(AnnotationValue annotationValue); static Character[] getCharValueArray(List<? extends AnnotationValue> annotationValues); static String[] getStringValueArray(AnnotationValue annotationValue); static String[] getStringValueArray(List<? extends AnnotationValue> annotationValues); static VariableElement[] getEnumValueArray(AnnotationValue annotationValue); static VariableElement[] getEnumValueArray(List<? extends AnnotationValue> annotationValues); static AnnotationMirror[] getAnnotationValueArray(AnnotationValue annotationValue); static AnnotationMirror[] getAnnotationValueArray(List<? extends AnnotationValue> annotationValues); static boolean isIntegerArray(AnnotationValue annotationValue); static boolean isLongArray(AnnotationValue annotationValue); static boolean isBooleanArray(AnnotationValue annotationValue); static boolean isFloatArray(AnnotationValue annotationValue); static boolean isDoubleArray(AnnotationValue annotationValue); static boolean isStringArray(AnnotationValue annotationValue); static boolean isCharArray(AnnotationValue annotationValue); static boolean isEnumArray(AnnotationValue annotationValue); static boolean isClassArray(AnnotationValue annotationValue); static boolean isArrayArray(AnnotationValue annotationValue); static boolean isAnnotationArray(AnnotationValue annotationValue); static boolean isAnnotationValueArray(AnnotationValue annotationValue, Class type); static boolean isAnnotationValueArray(List<? extends AnnotationValue> annotationValues, Class type); }
@Test public void annotationValueUtils_test_getAnnotationValueOfAttribute() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationValue")).toString(), Matchers.is("@" + Deprecated.class.getCanonicalName())); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "longArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "intArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "booleanArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "floatArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "doubleArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "stringArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "charArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "enumArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "classArrayValue")), Matchers.nullValue()); MatcherAssert.assertThat(AnnotationValueUtils.getAnnotationValue(AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror, "annotationArrayValue")), Matchers.nullValue()); } }) .compilationShouldSucceed() .executeTest(); }
Utilities { public static <T> Set<T> convertArrayToSet(T[] array) { if (array == null) { return null; } Set<T> set = new HashSet<>(array.length); for (T element : array) { if (element != null) { set.add(element); } } return set; } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<T> convertVarargsToList(T... varargs); @SafeVarargs static T[] convertVarargsToArray(T... varargs); }
@Test public void convertArrayToSet_nullValue() { MatcherAssert.assertThat(Utilities.convertArrayToSet(null), Matchers.nullValue()); } @Test public void convertArrayToSet_nonNullValue() { String[] array = {"A","B","C"}; MatcherAssert.assertThat(Utilities.convertArrayToSet(array), Matchers.containsInAnyOrder("A","B","C")); }
Utilities { @SafeVarargs public static <T> Set<T> convertVarargsToSet(T... varargs) { return varargs != null ? new HashSet<>(Arrays.asList(varargs)) : new HashSet<T>(); } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<T> convertVarargsToList(T... varargs); @SafeVarargs static T[] convertVarargsToArray(T... varargs); }
@Test public void convertVarargsToSet_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToSet(), Matchers.empty()); } @Test public void convertVarargsToSet_singleNullValue_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToSet(null), Matchers.empty()); } @Test public void convertArrayToSet_withValues() { MatcherAssert.assertThat(Utilities.convertVarargsToSet("A","B", (String)null, "C"), Matchers.containsInAnyOrder("A","B","C", (String)null)); }
BeanUtils { public static String getPrefixedName(String prefix, String name) { return prefix + name.substring(0, 1).toUpperCase() + name.substring(1); } private BeanUtils(); static boolean hasDefaultNoargsConstructor(TypeElement typeElement); static boolean isDefaultNoargConstructor(ExecutableElement element); static boolean isAttribute(VariableElement field); static AttributeResult[] getAttributesWithInheritance(TypeElement typeElement); static AttributeResult[] getAttributes(TypeElement typeElement); static boolean checkHasGetter(VariableElement field); static boolean checkHasSetter(VariableElement field); static boolean checkLombokDataAnnotation(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnField(VariableElement variableElement); static String getGetterMethodName(VariableElement field); static String getSetterMethodName(VariableElement field); static String getPrefixedName(String prefix, String name); static boolean checkLombokSetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokSetterAnnotationOnField(VariableElement variableElement); }
@Test public void getPossibleGetterOrSetterNames_getter() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat(Arrays.asList(BeanUtils.getPrefixedName("get", "testField")), Matchers.contains("getTestField")); } }) .compilationShouldSucceed() .executeTest(); }
Utilities { @SafeVarargs public static <T> List<T> convertVarargsToList(T... varargs) { return varargs != null ? Arrays.asList(varargs) : new ArrayList<T>(); } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<T> convertVarargsToList(T... varargs); @SafeVarargs static T[] convertVarargsToArray(T... varargs); }
@Test public void convertVarargsToList_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToList(), Matchers.empty()); } @Test public void convertVarargsToList_singleNullValue_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToList(null), Matchers.empty()); } @Test public void convertVarargsToList_withValues() { MatcherAssert.assertThat(Utilities.convertVarargsToList("A","B", (String)null, "C"), Matchers.contains("A","B", (String)null,"C")); }
Utilities { @SafeVarargs public static <T> T[] convertVarargsToArray(T... varargs) { final Object[] e = {}; if (varargs == null) { return (T[]) e; } return varargs; } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<T> convertVarargsToList(T... varargs); @SafeVarargs static T[] convertVarargsToArray(T... varargs); }
@Test public void convertVarargsToArray_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Arrays.asList(Utilities.convertVarargsToArray()), Matchers.empty()); } @Test public void convertVarargsToArray_singleNullValue_shouldReturnEmptyArrayg() { MatcherAssert.assertThat(Arrays.asList(Utilities.convertVarargsToArray(null)), Matchers.empty()); } @Test public void convertVarargsToArray_withValues() { MatcherAssert.assertThat(Arrays.asList(Utilities.convertVarargsToArray("A","B", (String)null, "C")), Matchers.contains("A","B", (String)null,"C")); }
AbstractAnnotationProcessor extends AbstractProcessor { @SafeVarargs protected static Set<String> createSupportedAnnotationSet(Class<? extends Annotation>... annotationTypes) { Set<String> result = new HashSet<>(); if (annotationTypes != null) { for (Class<? extends Annotation> annotationType : annotationTypes) { if (annotationType != null) { result.add(annotationType.getCanonicalName()); } } } return result; } @Override synchronized void init(ProcessingEnvironment processingEnv); @Override final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); abstract boolean processAnnotations(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); @Override SourceVersion getSupportedSourceVersion(); static Elements getElements(); static Filer getFiler(); static Types getTypes(); static Messager getMessager(); @SafeVarargs static T[] wrapToArray(T... element); }
@Test public void createSupportedAnnotationSet_withoutParameters() { MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnnotationSet(), Matchers.<String>empty()); } @Test public void createSupportedAnnotationSet_withParameters() { MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnnotationSet(Override.class, Ignore.class), Matchers.containsInAnyOrder(Override.class.getCanonicalName(), Ignore.class.getCanonicalName())); } @Test public void createSupportedAnnotationSet_withNullParameter() { MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnnotationSet(null), Matchers.<String>empty()); MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnnotationSet(Override.class, null, Ignore.class), Matchers.containsInAnyOrder(Override.class.getCanonicalName(), Ignore.class.getCanonicalName())); }
BeanUtils { public static boolean checkHasGetter(VariableElement field) { if (field == null || field.getKind() != ElementKind.FIELD || CoreMatchers.BY_MODIFIER.getMatcher().checkForMatchingCharacteristic(field, Modifier.STATIC)) { return false; } TypeElement typeElement = ElementUtils.AccessEnclosingElements.<TypeElement>getFirstEnclosingElementOfKind(field, ElementKind.CLASS); return checkLombokDataAnnotation(typeElement) || checkLombokGetterAnnotationOnType(typeElement) || checkLombokGetterAnnotationOnField(field) || checkHasGetterMethod(field, typeElement) ; } private BeanUtils(); static boolean hasDefaultNoargsConstructor(TypeElement typeElement); static boolean isDefaultNoargConstructor(ExecutableElement element); static boolean isAttribute(VariableElement field); static AttributeResult[] getAttributesWithInheritance(TypeElement typeElement); static AttributeResult[] getAttributes(TypeElement typeElement); static boolean checkHasGetter(VariableElement field); static boolean checkHasSetter(VariableElement field); static boolean checkLombokDataAnnotation(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnField(VariableElement variableElement); static String getGetterMethodName(VariableElement field); static String getSetterMethodName(VariableElement field); static String getPrefixedName(String prefix, String name); static boolean checkLombokSetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokSetterAnnotationOnField(VariableElement variableElement); }
@Test public void fieldWithImplementedGetterAndSetters_checkHasGetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithImplementedGetterAndSetters") .getResult().get(0); MatcherAssert.assertThat("Should detect getter ", BeanUtils.checkHasGetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithImplementedGetterAndSetterAnnotation_checkHasGetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithImplementedSetterAndGetterAnnotation") .getResult().get(0); MatcherAssert.assertThat("Should detect lombok generated getter ", BeanUtils.checkHasGetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithoutGetter_checkHasGetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithoutGetter") .getResult().get(0); MatcherAssert.assertThat("Should not detect getter ", !BeanUtils.checkHasGetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithoutSetter_checkHasLombokGetterOnClass() { unitTestBuilder .useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/LombokGetterOnClass.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testField") .getResult().get(0); MatcherAssert.assertThat("Should detect getter ", BeanUtils.checkHasGetter(field)); } }) .compilationShouldSucceed() .executeTest(); }
AbstractAnnotationProcessor extends AbstractProcessor { @SafeVarargs public static <T> T[] wrapToArray(T... element) { return element; } @Override synchronized void init(ProcessingEnvironment processingEnv); @Override final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); abstract boolean processAnnotations(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); @Override SourceVersion getSupportedSourceVersion(); static Elements getElements(); static Filer getFiler(); static Types getTypes(); static Messager getMessager(); @SafeVarargs static T[] wrapToArray(T... element); }
@Test public void wrapToArrayt_withNullParameter() { MatcherAssert.assertThat("Should return null", AbstractAnnotationProcessor.wrapToArray((String) null)[0] == null); Class[] resultArray = AbstractAnnotationProcessor.wrapToArray(Override.class, null, Ignore.class); MatcherAssert.assertThat(Arrays.asList(resultArray), Matchers.hasSize(3)); MatcherAssert.assertThat(resultArray[0], Matchers.equalTo((Class) Override.class)); MatcherAssert.assertThat(resultArray[1], Matchers.nullValue()); MatcherAssert.assertThat(resultArray[2], Matchers.equalTo((Class) Ignore.class)); }
ToolingProvider { public static void setTooling(ProcessingEnvironment processingEnvironment) { tooling.set(new ToolingProvider(processingEnvironment)); } ToolingProvider(ProcessingEnvironment processingEnv); static ToolingProvider getTooling(); static void setTooling(ProcessingEnvironment processingEnvironment); static void clearTooling(); Elements getElements(); Filer getFiler(); Messager getMessager(); Types getTypes(); ProcessingEnvironment getProcessingEnvironment(); }
@Test(expected = IllegalArgumentException.class) public void testToolingProviderSetToolingWithNullValue() { ToolingProvider.setTooling(null); }
ToolingProvider { public static void clearTooling() { tooling.remove(); } ToolingProvider(ProcessingEnvironment processingEnv); static ToolingProvider getTooling(); static void setTooling(ProcessingEnvironment processingEnvironment); static void clearTooling(); Elements getElements(); Filer getFiler(); Messager getMessager(); Types getTypes(); ProcessingEnvironment getProcessingEnvironment(); }
@Test public void testToolingProviderSetToolingWithValidProcessingEnvironmentWithClear() { testToolingProviderSetToolingWithValidProcessingEnvironment(); ToolingProvider.clearTooling(); testToolingProviderSetToolingWithValidProcessingEnvironment(); }
UnaryOperationWrapperOperand extends Operand<Object> { @Override public Object value() { if (resultOperand == null) { calculateResultOperand(); } return resultOperand.value(); } UnaryOperationWrapperOperand(Operand operand, OperationType unaryOperationType); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test public void test_unaryOperationType_successfulPath_getValue() { UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.NEGATE); MatcherAssert.assertThat((Boolean) unit.value(), Matchers.is(false)); unit = new UnaryOperationWrapperOperand(new BooleanOperand("false"), OperationType.NEGATE); MatcherAssert.assertThat((Boolean) unit.value(), Matchers.is(true)); } @Test(expected = IllegalArgumentException.class) public void test_nullValuedOperand_mustThrowException() { UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(null, OperationType.NEGATE); MatcherAssert.assertThat(unit.value(), Matchers.nullValue()); }
UnaryOperationWrapperOperand extends Operand<Object> { @Override public Class<Object> getOperandsJavaType() { if (resultOperand == null) { calculateResultOperand(); } return resultOperand.getOperandsJavaType(); } UnaryOperationWrapperOperand(Operand operand, OperationType unaryOperationType); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test public void test_unaryOperationType_successfulPath_getOperandsJavaType() { UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.NEGATE); MatcherAssert.assertThat( (Class)unit.getOperandsJavaType(), Matchers.equalTo((Class)Boolean.class)); }
LongOperand extends ParsedOperand<Long> { @Override public Long value() { return Long.valueOf(getExpressionString()); } LongOperand(String expressionString); @Override Class<Long> getOperandsJavaType(); @Override Long value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new LongOperand(null).value(); } @Test public void test_createLongOperand() { MatcherAssert.assertThat((Long) new LongOperand("6").value(), Matchers.is(6L)); MatcherAssert.assertThat((Long) new LongOperand("-6").value(), Matchers.is(-6L)); }
LongOperand extends ParsedOperand<Long> { @Override public Class<Long> getOperandsJavaType() { return Long.class; } LongOperand(String expressionString); @Override Class<Long> getOperandsJavaType(); @Override Long value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new LongOperand("6").getOperandsJavaType(), Matchers.equalTo((Class) Long.class)); }
BeanUtils { public static boolean checkHasSetter(VariableElement field) { if (field == null || field.getKind() != ElementKind.FIELD) { return false; } TypeElement typeElement = ElementUtils.AccessEnclosingElements.<TypeElement>getFirstEnclosingElementOfKind(field, ElementKind.CLASS); return checkLombokDataAnnotation(typeElement) || checkLombokSetterAnnotationOnType(typeElement) || checkLombokSetterAnnotationOnField(field) || checkHasSetterMethod(field, typeElement) ; } private BeanUtils(); static boolean hasDefaultNoargsConstructor(TypeElement typeElement); static boolean isDefaultNoargConstructor(ExecutableElement element); static boolean isAttribute(VariableElement field); static AttributeResult[] getAttributesWithInheritance(TypeElement typeElement); static AttributeResult[] getAttributes(TypeElement typeElement); static boolean checkHasGetter(VariableElement field); static boolean checkHasSetter(VariableElement field); static boolean checkLombokDataAnnotation(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokGetterAnnotationOnField(VariableElement variableElement); static String getGetterMethodName(VariableElement field); static String getSetterMethodName(VariableElement field); static String getPrefixedName(String prefix, String name); static boolean checkLombokSetterAnnotationOnType(TypeElement typeElement); static boolean checkLombokSetterAnnotationOnField(VariableElement variableElement); }
@Test public void fieldWithImplementedGetterAndSetters_checkHasSetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithImplementedGetterAndSetters") .getResult().get(0); MatcherAssert.assertThat("Should detect setter ", BeanUtils.checkHasSetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithImplementedGetterAndSetterAnnotation_checkHasSetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithImplementedGetterAndSetterAnnotation") .getResult().get(0); MatcherAssert.assertThat("Should detect lombok generated setter ", BeanUtils.checkHasSetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithoutSetter_checkHasSetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("fieldWithoutSetter") .getResult().get(0); MatcherAssert.assertThat("Should not detect setter ", !BeanUtils.checkHasSetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithoutSetter_checkHasLombokSetter() { unitTestBuilder .useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/LombokDataOnClass.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testField") .getResult().get(0); MatcherAssert.assertThat("Should detect setter ", BeanUtils.checkHasSetter(field)); } }) .compilationShouldSucceed() .executeTest(); } @Test public void fieldWithoutSetter_checkHasLombokSetterOnClass() { unitTestBuilder .useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/LombokSetterOnClass.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElement field = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.IS_FIELD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testField") .getResult().get(0); MatcherAssert.assertThat("Should detect setter ", BeanUtils.checkHasSetter(field)); } }) .compilationShouldSucceed() .executeTest(); }
OperandFactory { public static Operand createOperand(OperandType operandType, String expressionString, OperationType[] unaryOperationsToBeApplied, Expression expression) { if ((operandType == null) || (expressionString == null)) { throw new IllegalArgumentException("operandType and expressionString must not be null"); } Operand operand = null; switch (operandType) { case BOOLEAN: { operand = new BooleanOperand(expressionString); break; } case LONG: { operand = new LongOperand(expressionString); break; } case DOUBLE: { operand = new DoubleOperand(expressionString); break; } case STRING: { operand = new StringOperand(expressionString); break; } case DYNAMIC_VALUE: { operand = new DynamicOperand(expressionString); break; } case EXPRESSION: { operand = new ExpressionOperand(expressionString, expression); break; } case NULL_VALUE: { operand = new NullValueOperand(expressionString); break; } default: throw new IllegalArgumentException("operandType " + operandType + " currently not implemented"); } if (unaryOperationsToBeApplied != null && unaryOperationsToBeApplied.length >= 1) { for (int i = unaryOperationsToBeApplied.length - 1; i >= 0; i--) { operand = OperandFactory.createUnaryOperand(operand, unaryOperationsToBeApplied[i]); } } return operand; } private OperandFactory(); static Operand createOperand(OperandType operandType, String expressionString, OperationType[] unaryOperationsToBeApplied, Expression expression); static OperationResultOperand createOperationResult(Class type, Object value); static UnaryOperationWrapperOperand createUnaryOperand(Operand operand, OperationType operationType); }
@Test(expected = IllegalArgumentException.class) public void createOperand_nullValued_operandType() { OperandFactory.createOperand(null, "ABC", new OperationType[0], null); } @Test(expected = IllegalArgumentException.class) public void createOperand_nullValued_expressionString() { OperandFactory.createOperand(OperandType.BOOLEAN, null, new OperationType[0], null); }
Operand { public abstract OperandType getOperandType(); Operand(); abstract OperandType getOperandType(); abstract Class<? extends T> getOperandsJavaType(); abstract T value(); static String getStringRepresentationOfOperandsJavaTypes(Operand[] operandsArray); }
@Test(expected = IllegalArgumentException.class) public void OperandType_getOperand_testNullValue() { OperandType.getOperandType(null); } @Test public void OperandType_getOperand_testLong() { MatcherAssert.assertThat(OperandType.getOperandType("1234"), Matchers.is(OperandType.LONG)); } @Test public void OperandType_getOperand_testDouble() { MatcherAssert.assertThat(OperandType.getOperandType("12.34"), Matchers.is(OperandType.DOUBLE)); } @Test public void OperandType_getOperand_testString() { MatcherAssert.assertThat(OperandType.getOperandType("'1234'"), Matchers.is(OperandType.STRING)); } @Test public void OperandType_getOperand_testBoolean_true() { MatcherAssert.assertThat(OperandType.getOperandType("true"), Matchers.is(OperandType.BOOLEAN)); } @Test public void OperandType_getOperand_testBoolean_false() { MatcherAssert.assertThat(OperandType.getOperandType("false"), Matchers.is(OperandType.BOOLEAN)); } @Test public void OperandType_getOperand_testExpression() { MatcherAssert.assertThat(OperandType.getOperandType("abc.def.hij"), Matchers.is(OperandType.DYNAMIC_VALUE)); MatcherAssert.assertThat(OperandType.getOperandType("abc.def"), Matchers.is(OperandType.DYNAMIC_VALUE)); MatcherAssert.assertThat(OperandType.getOperandType("abc"), Matchers.is(OperandType.DYNAMIC_VALUE)); }
NullValueOperand extends ParsedOperand<Object> { @Override public Object value() { return null; } NullValueOperand(String expressionString); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new BooleanOperand(null).value(); } @Test public void test_getValue() { MatcherAssert.assertThat(new NullValueOperand("null").value(), Matchers.nullValue()); }
NullValueOperand extends ParsedOperand<Object> { @Override public Class<Object> getOperandsJavaType() { return null; } NullValueOperand(String expressionString); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new NullValueOperand("null").getOperandsJavaType(), Matchers.nullValue()); }
BooleanOperand extends ParsedOperand<Boolean> { @Override public Boolean value() { return Boolean.valueOf(getExpressionString()); } BooleanOperand(String expressionString); @Override Class<Boolean> getOperandsJavaType(); @Override Boolean value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new BooleanOperand(null).value(); } @Test public void test_createBooleanOperand() { MatcherAssert.assertThat((Boolean) new BooleanOperand("true").value(), Matchers.is(true)); MatcherAssert.assertThat((Boolean) new BooleanOperand("false").value(), Matchers.is(false)); } @Test public void test_nonBooleanValue() { MatcherAssert.assertThat((Boolean) new BooleanOperand("XYZ").value(), Matchers.is(false)); }
BooleanOperand extends ParsedOperand<Boolean> { @Override public Class<Boolean> getOperandsJavaType() { return Boolean.class; } BooleanOperand(String expressionString); @Override Class<Boolean> getOperandsJavaType(); @Override Boolean value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new BooleanOperand("true").getOperandsJavaType(), Matchers.equalTo((Class) Boolean.class)); }
StringOperand extends ParsedOperand<String> { @Override public Class<String> getOperandsJavaType() { return String.class; } StringOperand(String expressionString); @Override Class<String> getOperandsJavaType(); @Override String value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new StringOperand("'test'").getOperandsJavaType(), Matchers.equalTo((Class) String.class)); }
StringOperand extends ParsedOperand<String> { @Override public String value() { return internalValue; } StringOperand(String expressionString); @Override Class<String> getOperandsJavaType(); @Override String value(); @Override OperandType getOperandType(); }
@Test public void testStringWithoutEscapes() { MatcherAssert.assertThat(new StringOperand("'ABC DEF'").value(), Matchers.is("ABC DEF")); MatcherAssert.assertThat(new StringOperand("' MatcherAssert.assertThat(new StringOperand("'A%§GS34234|||F'").value(), Matchers.is("A%§GS34234|||F")); } @Test public void testStringWithEscapedQuotes() { MatcherAssert.assertThat(new StringOperand("'ABC\\' DEF'").value(), Matchers.is("ABC' DEF")); MatcherAssert.assertThat(new StringOperand("' } @Test public void testNonMatchingStringPattern() { MatcherAssert.assertThat(new StringOperand("'ABC").value(), Matchers.nullValue()); MatcherAssert.assertThat(new StringOperand("ABC'").value(), Matchers.nullValue()); MatcherAssert.assertThat(new StringOperand("ABC").value(), Matchers.nullValue()); } @Test @Ignore public void testStringWithEscapedEscapeChars() { MatcherAssert.assertThat(new StringOperand("'ABC\\\\ DEF'").value(), Matchers.is("ABC\\ DEF")); MatcherAssert.assertThat(new StringOperand("'ABC\\\\\\' DEF'").value(), Matchers.is("ABC\\' DEF")); }
DynamicOperand extends ParsedOperand<Object> { @Override public Object value() { ModelPathResolver.ResolvedModelPathResult result = ModelPathResolver.resolveModelPath(ModelPathResolver.modelMapThreadLocal.get(), getExpressionString()); return result.getValue(); } DynamicOperand(String expressionString); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new DynamicOperand(null).value(); } @Test public void testResolveModelValue() { Map<String, Object> model = new HashMap<String, Object>(); model.put("longKey", 5L); model.put("integerKey", 5); model.put("doubleKey", 5.0); model.put("floatKey", 5.0f); model.put("stringKey", "stringValue"); model.put("booleanKey", true); model.put("objectKey", this); ModelPathResolver.modelMapThreadLocal.set(model); MatcherAssert.assertThat((Long) new DynamicOperand("longKey").value(), Matchers.is(5L)); MatcherAssert.assertThat((Integer) new DynamicOperand("integerKey").value(), Matchers.is(5)); MatcherAssert.assertThat((Double) new DynamicOperand("doubleKey").value(), Matchers.is(5.0)); MatcherAssert.assertThat((Float) new DynamicOperand("floatKey").value(), Matchers.is(5.0f)); MatcherAssert.assertThat((String) new DynamicOperand("stringKey").value(), Matchers.is("stringValue")); MatcherAssert.assertThat((Boolean) new DynamicOperand("booleanKey").value(), Matchers.is(true)); MatcherAssert.assertThat((Object) new DynamicOperand("objectKey").value(), Matchers.is((Object) this)); } @Test(expected = InvalidPathException.class) public void test_nonExistingPath() { Map<String, Object> model = new HashMap<String, Object>(); ModelPathResolver.modelMapThreadLocal.set(model); new DynamicOperand("nonExistingKey").value(); } @Test public void test_complexPaths() { Map<String, Object> model = new HashMap<String, Object>(); model.put("test", new TestClass2()); ModelPathResolver.modelMapThreadLocal.set(model); MatcherAssert.assertThat((TestClass2) new DynamicOperand("test").value(), Matchers.is((Object) model.get("test"))); MatcherAssert.assertThat(((TestClass1) new DynamicOperand("test.testClass1").value()).getValue(), Matchers.is(5)); MatcherAssert.assertThat(((TestClass1) new DynamicOperand("test.getTestClass1").value()).getValue(), Matchers.is(5)); MatcherAssert.assertThat((Integer) new DynamicOperand("test.testClass1.value").value(), Matchers.is(5)); MatcherAssert.assertThat((Integer) new DynamicOperand("test.getTestClass1.getValue").value(), Matchers.is(5)); }
DoubleOperand extends ParsedOperand<Double> { @Override public Double value() { return Double.valueOf(getExpressionString()); } DoubleOperand( String expressionString); @Override Class<Double> getOperandsJavaType(); @Override Double value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new DoubleOperand(null).value(); } @Test public void test_createDoubleOperand() { MatcherAssert.assertThat((Double) new DoubleOperand("6.0").value(), Matchers.is(6.0)); MatcherAssert.assertThat((Double) new DoubleOperand("-6.0").value(), Matchers.is(-6.0)); }
DoubleOperand extends ParsedOperand<Double> { @Override public Class<Double> getOperandsJavaType() { return Double.class; } DoubleOperand( String expressionString); @Override Class<Double> getOperandsJavaType(); @Override Double value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new DoubleOperand("6.0").getOperandsJavaType(), Matchers.equalTo((Class) Double.class)); }
ExpressionParser { public static OperationTypeSearchResult getOperationType(String expressionString, int index) { for (OperationType operationType : OperationType.getOperationsByOperationTypeMode(OperationTypeMode.BINARY)) { Matcher matcher = operationType.getOperationPattern().matcher(expressionString); if (matcher.find(index) && matcher.start() == index) { return new OperationTypeSearchResult(operationType, matcher.start(), matcher.end()); } } throw new IllegalArgumentException("Can't determine operation type for string : " + expressionString.substring(index)); } static Expression parseExpression(String expressionString, Map<String, Object> model); static ExpressionParseResult parseExpressionRecursively(String expressionString, boolean usedBrackets); static OperationTypeSearchResult getOperationType(String expressionString, int index); static OperandTypeSearchResult getOperandType(String expressionString, int index); }
@Test(expected = IllegalArgumentException.class) public void getOperationType_operationTypeNotFound() { ExpressionParser.getOperationType(" == sdsadasda", 12); } @Test public void getOperationType_getEquals() { assertOperationTypeSearchResult(ExpressionParser.getOperationType(" == sdsadasda", 0), 0, 8, OperationType.EQUAL); assertOperationTypeSearchResult(ExpressionParser.getOperationType(" == sdsadasda", 2), 2, 8, OperationType.EQUAL); }
ExpressionParser { public static Expression parseExpression(String expressionString, Map<String, Object> model) { ModelPathResolver.modelMapThreadLocal.set(model); return parseExpression(expressionString); } static Expression parseExpression(String expressionString, Map<String, Object> model); static ExpressionParseResult parseExpressionRecursively(String expressionString, boolean usedBrackets); static OperationTypeSearchResult getOperationType(String expressionString, int index); static OperandTypeSearchResult getOperandType(String expressionString, int index); }
@Test public void parseExpression_parseNegation_negatedTrue_Test() { Expression expression = ExpressionParser.parseExpression("!true"); MatcherAssert.assertThat(expression.getOperands().length, Matchers.is(1)); MatcherAssert.assertThat(expression.getOperationTypes().length, Matchers.is(0)); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(false)); } @Test public void parseExpression_parseNegation_negatedFalse_Test() { Expression expression = ExpressionParser.parseExpression("!false"); MatcherAssert.assertThat(expression.getOperands().length, Matchers.is(1)); MatcherAssert.assertThat(expression.getOperationTypes().length, Matchers.is(0)); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void parseExpression_parseNegation_bracesA_Test() { MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("'' + (40 * (2+3)) == '200'").evaluateExpression().value(), Matchers.is(true)); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("!(!false || !true)").evaluateExpression().value(), Matchers.is(false)); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("!(!false || (!true || true))").evaluateExpression().value(), Matchers.is(false)); MatcherAssert.assertThat((Long) ExpressionParser.parseExpression("(40 * (2+3))").evaluateExpression().value(), Matchers.is(200L)); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("40 * (2+3) == 200").evaluateExpression().value(), Matchers.is(true)); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("40 * (2+3) == 200.0 || false && true").evaluateExpression().value(), Matchers.is(true)); MatcherAssert.assertThat((String) ExpressionParser.parseExpression("'' + (40 * (2+3))").evaluateExpression().value(), Matchers.is("200")); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("'' + (40 * (2+3)) == '200'").evaluateExpression().value(), Matchers.is(true)); MatcherAssert.assertThat((Boolean) ExpressionParser.parseExpression("'' + (40 * (2+3)) == '200' || false && true").evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_equalWithTwoDynamicNullValues() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", null); model.put("value2", null); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_equalOneDynamicNullValue1() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", null); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(false)); } @Test public void evaluateExpression_withModel_equalOneDynamicNullValue2() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", null); model.put("value2", 5L); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(false)); } @Test public void evaluateExpression_withModel_equalOperands() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 5L); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_equalOperandsWithDifferentTypes() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 5); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_notEqualOperands() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 6L); Expression expression = ExpressionParser.parseExpression("value1 == value2", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(false)); } @Test public void evaluateExpression_withModel_moreComplexMixedExpression() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 6L); Expression expression = ExpressionParser.parseExpression("(value1 == 5) && (value2 == 6.0)", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); expression = ExpressionParser.parseExpression("(value1 == 5) && (value2 == 6.0)", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_evenMoreComplexMixedExpression() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 6L); model.put("value3", null); Expression expression = ExpressionParser.parseExpression("(value1 == 5) || value3 != null && (value2 == 6.0) ", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_evenMoreComplexMixedExpressionWithStringConcatenation() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 6L); model.put("value3", null); model.put("value4", "Text"); Expression expression = ExpressionParser.parseExpression("(value1 == 5) || value3 != null && (value2 == 6.0 ) && value4 + '1' == 'Text1'", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_withModel_testVariationOfWhitespaces() { Map<String, Object> model = new HashMap<String, Object>(); model.put("value1", 5L); model.put("value2", 6L); model.put("value3", null); Expression expression = ExpressionParser.parseExpression(" (value1==5 +6 -2*3) ||value3 !=null && ( value2 *3 ==18.0 ) ", model); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testLeadingWhitespaces() { Expression expression = ExpressionParser.parseExpression(" 5==5"); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testTrailingWhitespaces() { Expression expression = ExpressionParser.parseExpression("5==5 "); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testLeadingWhitespacesInBraces() { Expression expression = ExpressionParser.parseExpression("( 5==5)"); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testTrailingWhitespacesInBraces() { Expression expression = ExpressionParser.parseExpression("(5==5 )"); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testInbetweenWhitespaces1() { Expression expression = ExpressionParser.parseExpression("5== 5"); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); } @Test public void evaluateExpression_testInbetweenWhitespaces2() { Expression expression = ExpressionParser.parseExpression("5 ==5"); MatcherAssert.assertThat((Boolean) expression.evaluateExpression().value(), Matchers.is(true)); }
ParseUtilities { public static String readResourceToString(String resourcefileName) throws IOException { InputStream inputStream = ParseUtilities.class.getResourceAsStream(resourcefileName); if (inputStream != null) { return readFromInputStream(inputStream); } else { throw new IllegalArgumentException("Can't open resource file '" + resourcefileName + "'"); } } static TemplateBlockBinder parseString(String templateString); static String readResourceToString(String resourcefileName); static String readFromInputStream(InputStream stream); static String trimContentString(String content); static Map<String, String> parseNamedAttributes(String attributeString); static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString); static final Pattern DYNAMIC_TEXT_BLOCK_REGEX; }
@Test public void readResourceToStringTest() throws Exception { final String EXPECTED_RESULT = "ABC" + System.lineSeparator() + "DEF" + System.lineSeparator() + "HIJ"; MatcherAssert.assertThat(ParseUtilities.readResourceToString("/ReadResourceToStringTest.txt"), Matchers.is(EXPECTED_RESULT)); }
ParseUtilities { public static String trimContentString(String content) { String tmpContentString = content; tmpContentString = tmpContentString.replaceFirst("^[ ]*?\n", ""); tmpContentString = tmpContentString.replaceAll("[ ]+$", ""); return tmpContentString; } static TemplateBlockBinder parseString(String templateString); static String readResourceToString(String resourcefileName); static String readFromInputStream(InputStream stream); static String trimContentString(String content); static Map<String, String> parseNamedAttributes(String attributeString); static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString); static final Pattern DYNAMIC_TEXT_BLOCK_REGEX; }
@Test public void trimContentString_trimContentString_Test() { MatcherAssert.assertThat(ParseUtilities.trimContentString(" \nabc"), Matchers.is("abc")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \n abc"), Matchers.is(" abc")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \n \nabc"), Matchers.is(" \nabc")); MatcherAssert.assertThat(ParseUtilities.trimContentString("\nabc"), Matchers.is("abc")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \nabc\n "), Matchers.is("abc\n")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \nabc\n"), Matchers.is("abc\n")); }
ParseUtilities { public static Map<String, String> parseNamedAttributes(String attributeString) { Map<String, String> attributeMap = new HashMap<>(); final String attributePatternString = "\\s*(\\w+)\\s*:\\s*'(.*?)'\\s*"; Pattern attributePattern = Pattern.compile("(" + attributePatternString + ")(?:,(\" + attributePatternString+ \"))*"); Matcher matcher = attributePattern.matcher(attributeString); if (matcher.matches()) { Pattern findPattern = Pattern.compile(attributePatternString); Matcher findMatcher = findPattern.matcher(attributeString); while (findMatcher.find()) { String attributeName = findMatcher.group(1); String attributeValue = findMatcher.group(2); attributeMap.put(attributeName, attributeValue); } } return attributeMap; } static TemplateBlockBinder parseString(String templateString); static String readResourceToString(String resourcefileName); static String readFromInputStream(InputStream stream); static String trimContentString(String content); static Map<String, String> parseNamedAttributes(String attributeString); static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString); static final Pattern DYNAMIC_TEXT_BLOCK_REGEX; }
@Test public void parseNamedAttributes_parseAttributes() { String stringToParse = " abc : '/val1' , def : 'v.a.l2',hij:'val 3' "; Map<String, String> map = ParseUtilities.parseNamedAttributes(stringToParse); MatcherAssert.assertThat(map.get("abc"), Matchers.is("/val1")); MatcherAssert.assertThat(map.get("def"), Matchers.is("v.a.l2")); MatcherAssert.assertThat(map.get("hij"), Matchers.is("val 3")); }
ParseUtilities { public static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString) { if (outerModel == null) { throw new IllegalArgumentException("passed outerModel must not be null"); } if (modelString == null) { throw new IllegalArgumentException("passed modelString must not be null"); } Map<String, Object> result = new HashMap<>(); String[] modelStringLines = modelString.split("\\r{0,1}\\n"); for (String line : modelStringLines) { Pattern keyValueExtractionPattern = Pattern.compile("^\\s*(\\w+(?:[.]\\w+)*)\\s*[:]\\s*(.+)\\s*$"); if (line.trim().isEmpty() || line.trim().startsWith(" continue; } Matcher matcher = keyValueExtractionPattern.matcher(line); if (matcher.matches()) { try { String key = matcher.group(1); String value = matcher.group(2); ParseUtilities.addKeyValuePair(outerModel, result, key, value); } catch (Exception e) { throw new InvalidIncludeModelExpression("couldn't add get key/value pair for expression : " + line, e); } } else { throw new InvalidIncludeModelExpression("key/value pair expression for generating a model isn't syntactically correct ( '<TARGET MODEL ACCESS PATH SEPARATED BY .>:<VALUE EXPRESSION>'): " + line); } } return result; } static TemplateBlockBinder parseString(String templateString); static String readResourceToString(String resourcefileName); static String readFromInputStream(InputStream stream); static String trimContentString(String content); static Map<String, String> parseNamedAttributes(String attributeString); static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString); static final Pattern DYNAMIC_TEXT_BLOCK_REGEX; }
@Test public void extractModelFromString_correctUsage() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("value1", "value_1"); outerModelModel.put("value2", "value_2"); Map<String, Object> result = ParseUtilities.extractModelFromString(outerModel, "targetModel.targetValue1 : model.value1\r\n \n MatcherAssert.assertThat(((Map<String, Object>) result.get("targetModel")).get("targetValue1").toString(), CoreMatchers.is("value_1")); MatcherAssert.assertThat(((Map<String, Object>) result.get("targetModel")).get("targetValue2").toString(), CoreMatchers.is("value_2")); } @Test(expected = InvalidIncludeModelExpression.class) public void extractModelFromString_invalidUsage_syntacticallyIncorrectKeyValueExpression() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("value1", "value_1"); ParseUtilities.extractModelFromString(outerModel, "targetModel.targetValue1 = model.value1"); } @Test(expected = InvalidIncludeModelExpression.class) public void extractModelFromString_invalidUsage_invalidValueExpression() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("value1", "value_1"); ParseUtilities.extractModelFromString(outerModel, "targetModel.targetValue1 = !model.value1"); }
ParseUtilities { static void addKeyValuePair(Map<String, Object> outerModel, Map<String, Object> modelToBuild, String key, String valueExpression) { String[] keyAccessPath = key.split("[.]"); String valueKey = keyAccessPath[keyAccessPath.length - 1]; Map<String, Object> targetMap = modelToBuild; for (int i = 0; i < keyAccessPath.length - 1; i++) { Object accessChainObject = targetMap.get(keyAccessPath[i]); if (accessChainObject == null) { Map<String, Object> nextMap = new HashMap<>(); targetMap.put(keyAccessPath[i], nextMap); targetMap = nextMap; } else if (Map.class.isAssignableFrom(accessChainObject.getClass())) { targetMap = (Map<String, Object>) accessChainObject; } else { throw new IllegalArgumentException("key path must not include Objects others than of type Map"); } } targetMap.put(valueKey, ExpressionParser.parseExpression(valueExpression, outerModel).evaluateExpression().value()); } static TemplateBlockBinder parseString(String templateString); static String readResourceToString(String resourcefileName); static String readFromInputStream(InputStream stream); static String trimContentString(String content); static Map<String, String> parseNamedAttributes(String attributeString); static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString); static final Pattern DYNAMIC_TEXT_BLOCK_REGEX; }
@Test public void addKeyValuePair_correctUsage() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("abc", "yes"); Map<String, Object> modelToFill = new HashMap<>(); ParseUtilities.addKeyValuePair(outerModel, modelToFill, "abc.def.hij", "model.abc"); MatcherAssert.assertThat(((Map<String, Object>) ((Map<String, Object>) modelToFill.get("abc")).get("def")).get("hij").toString(), CoreMatchers.is("yes")); } @Test(expected = IllegalArgumentException.class) public void addKeyValuePair_incorrectUsage_accessesNonMapInKey() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("value1", "yes"); outerModelModel.put("value2", "no"); Map<String, Object> modelToFill = new HashMap<>(); ParseUtilities.addKeyValuePair(outerModel, modelToFill, "abc", "model.value1"); MatcherAssert.assertThat(modelToFill.get("abc").toString(), CoreMatchers.is("yes")); ParseUtilities.addKeyValuePair(outerModel, modelToFill, "abc.def", "model.value2"); } @Test(expected = InvalidPathException.class) public void addKeyValuePair_incorrectUsage_irregularValueExpression() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); Map<String, Object> modelToFill = new HashMap<>(); ParseUtilities.addKeyValuePair(outerModel, modelToFill, "abc", "(model.value1)"); }
ForTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.FOR; } ForTemplateBlock(String attributeString, String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> outerVariables); TemplateBlockBinder getBinder(); void setBinder(TemplateBlockBinder binder); String getLoopVariableName(); String getAccessPath(); String getTemplateString(); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new ForTemplateBlock("test:abc.def", "DEF").getTemplateBlockType(), Matchers.is(TemplateBlockType.FOR)); }
ForTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> outerVariables) { Map<String, Object> variables = new HashMap<>(); variables.putAll(outerVariables); Object values = ModelPathResolver.resolveModelPath(outerVariables, accessPath).getValue(); StringBuilder stringBuilder = new StringBuilder(); if (values != null) { if (values.getClass().isArray()) { for (Object value : (Object[]) values) { variables.put(loopVariableName, value); stringBuilder.append(binder.getContent(variables)); } } else if (values instanceof Collection) { for (Object value : (Collection) values) { variables.put(loopVariableName, value); stringBuilder.append(binder.getContent(variables)); } } else { throw new InvalidPathException("Unable to iterate over Type '" + values.getClass().getCanonicalName() + "' in FOR block. Just Arrays and Collections are supported !"); } } else { throw new InvalidExpressionResult("For template accessPath '" + accessPath + "' must not evaluate to null value!"); } return stringBuilder.toString(); } ForTemplateBlock(String attributeString, String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> outerVariables); TemplateBlockBinder getBinder(); void setBinder(TemplateBlockBinder binder); String getLoopVariableName(); String getAccessPath(); String getTemplateString(); }
@Test(expected = InvalidPathException.class) public void test_getContent_invalidPath() { ForTemplateBlock unit = new ForTemplateBlock(" abc : def ", "${abc}"); Map<String, Object> model = new HashMap<String, Object>(); unit.getContent(model); } @Test(expected = InvalidPathException.class) public void test_getContent_invalidType() { ForTemplateBlock unit = new ForTemplateBlock(" abc : def ", "${abc}"); Map<String, Object> model = new HashMap<String, Object>(); model.put("def", "NOPE"); unit.getContent(model); } @Test(expected = InvalidExpressionResult.class) public void test_getContent_nullValueInModel_mustReturnEmptyString() { ForTemplateBlock unit = new ForTemplateBlock(" abc : def ", "${abc}"); Map<String, Object> model = new HashMap<String, Object>(); model.put("def", null); MatcherAssert.assertThat(unit.getContent(model), Matchers.equalTo("")); }
IfTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.IF; } IfTemplateBlock(String attributeString, String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> outerVariables); TemplateBlockBinder getBinder(); void setBinder(TemplateBlockBinder binder); String getAccessPath(); String getTemplateString(); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new IfTemplateBlock("abc", "").getTemplateBlockType(), Matchers.is(TemplateBlockType.IF)); }
StaticTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.STATIC; } StaticTemplateBlock(String content); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new StaticTemplateBlock("").getTemplateBlockType(), Matchers.is(TemplateBlockType.STATIC)); }
PlainTextTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.PLAIN_TEXT; } PlainTextTemplateBlock(String content); @Override TemplateBlockType getTemplateBlockType(); String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new PlainTextTemplateBlock("").getTemplateBlockType(), Matchers.is(TemplateBlockType.PLAIN_TEXT)); }
VariableTextTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.DYNAMIC_TEXT; } VariableTextTemplateBlock(String accessPath); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new VariableTextTemplateBlock("abc").getTemplateBlockType(), Matchers.is(TemplateBlockType.DYNAMIC_TEXT)); }
VariableTextTemplateBlock implements TemplateBlock { protected String getAccessPath() { return this.accessPath; } VariableTextTemplateBlock(String accessPath); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_constructor_ValidAccessPath() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); MatcherAssert.assertThat(unit.getAccessPath(), Matchers.equalTo("abc")); }
VariableTextTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> variables) { Expression expression = ExpressionParser.parseExpression(accessPath, variables); Operand result = expression.evaluateExpression(); return result.value() != null ? result.value().toString() : null; } VariableTextTemplateBlock(String accessPath); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test(expected = InvalidPathException.class) public void test_getContent_invalidPath() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); Map<String,Object> model = new HashMap<String, Object>(); unit.getContent(model); } @Test public void test_getContent_nullValuedValue() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); Map<String,Object> model = new HashMap<String, Object>(); model.put("abc", null); MatcherAssert.assertThat(unit.getContent(model), Matchers.nullValue()); } @Test public void test_getContent_nonNullValuedValue() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); Map<String,Object> model = new HashMap<String, Object>(); model.put("abc", "ABC"); MatcherAssert.assertThat(unit.getContent(model), Matchers.equalTo("ABC")); }
TemplateBlockBinder implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.BINDER; } TemplateBlockBinder( String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); void addTemplateBlock(TemplateBlock templateBlock); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new TemplateBlockBinder("").getTemplateBlockType(), Matchers.is(TemplateBlockType.BINDER)); }
IncludeTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.INCLUDE; } IncludeTemplateBlock(String attributeString, String modelDefinitionString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); String getModelDefinitionString(); String getTemplateResource(); String getTemplateString(); String getModelAccessPath(); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl'", "").getTemplateBlockType(), Matchers.is(TemplateBlockType.INCLUDE)); }
IncludeTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> variables) { Map<String, Object> model; if (this.modelAccessPath != null) { Object values = ModelPathResolver.resolveModelPath(variables, this.modelAccessPath).getValue(); model = new HashMap<>(); model.put("model", values); } else if (!this.modelDefinitionString.isEmpty()) { model = ParseUtilities.extractModelFromString(variables, this.modelDefinitionString); } else { model = variables; } return TemplateProcessor.processTemplate(templateString, model); } IncludeTemplateBlock(String attributeString, String modelDefinitionString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); String getModelDefinitionString(); String getTemplateResource(); String getTemplateString(); String getModelAccessPath(); }
@Test public void test_getContent_successfully() { IncludeTemplateBlock unit = new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl'",""); Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> subModel = new HashMap<String, Object>(); subModel.put("value", "test"); model.put("model", subModel); MatcherAssert.assertThat(unit.getContent(model), Matchers.equalTo("test : test")); } @Test public void test_getContent_successfully_withModelAttribute() { IncludeTemplateBlock unit = new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl', model : 'model.bridge'",""); Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> subModel = new HashMap<String, Object>(); Map<String, Object> subSubModel = new HashMap<String, Object>(); subSubModel.put("value", "test"); model.put("model", subModel); subModel.put("bridge", subSubModel); MatcherAssert.assertThat(unit.getContent(model), Matchers.equalTo("test : test")); } @Test public void test_getContent_successfully_withModelDefinitionInContentBlock() { IncludeTemplateBlock unit = new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl'","model : model.bridge"); Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> subModel = new HashMap<String, Object>(); Map<String, Object> subSubModel = new HashMap<String, Object>(); subSubModel.put("value", "test"); model.put("model", subModel); subModel.put("bridge", subSubModel); MatcherAssert.assertThat(unit.getContent(model), Matchers.equalTo("test : test")); } @Test(expected = InvalidPathException.class) public void test_getContent_missingModelValue() { IncludeTemplateBlock unit = new IncludeTemplateBlock("resource: '/IncludeTemplateBlockTest.tpl'",""); Map<String, Object> model = new HashMap<String, Object>(); unit.getContent(model); }