diff --git a/.travis.yml b/.travis.yml index 2be21da2..13ddcadd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,14 @@ jdk: - openjdk7 - openjdk8 - oraclejdk8 +- oraclejdk9 +- oraclejdk11 +- openjdk10 install: mvn install -DskipTests=true -q script: - mvn verify -B -q -- mvn -Danimal.sniffer.skip=true cobertura:cobertura after_success: - bash <(curl -s https://codecov.io/bash) -- ! '[[ $TRAVIS_BRANCH == "master" && $TRAVIS_REPO_SLUG == "holisticon/annotation-processor-toolkit" +- ! '[[ $TRAVIS_BRANCH == "master" && $TRAVIS_REPO_SLUG == "tobiasstamann/annotation-processor-toolkit" && $TRAVIS_PULL_REQUEST == "false" ]] && { curl https://raw.githubusercontent.com/holisticon/travis-configuration/master/settings.xml --location --create-dirs -o target/travis/settings.xml; }' diff --git a/README.md b/README.md index c535e81e..6d4242d7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Annotation-Processor-Toolkit [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.annotationprocessortoolkit/annotationprocessortoolkit-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.annotationprocessortoolkit/annotationprocessortoolkit-parent) -[![Build Status](https://api.travis-ci.org/toolisticon/annotation-processor-toolkit.svg)](https://travis-ci.org/toolisticon/annotation-processor-toolkit) -[![codecov](https://codecov.io/gh/toolisticon/annotation-processor-toolkit/branch/master/graph/badge.svg)](https://codecov.io/gh/toolisticon/annotation-processor-toolkit) +[![Build Status](https://api.travis-ci.org/tobiasstamann/annotation-processor-toolkit.svg)](https://travis-ci.org/tobiasstamann/annotation-processor-toolkit) +[![codecov](https://codecov.io/gh/tobiasstamann/annotation-processor-toolkit/branch/master/graph/badge.svg)](https://codecov.io/gh/tobiasstamann/annotation-processor-toolkit) Please check detailed documentation at the projects [github page](https://toolisticon.github.io/annotation-processor-toolkit/) diff --git a/annotationprocessor/pom.xml b/annotationprocessor/pom.xml index f1647f91..aa9ecf8a 100644 --- a/annotationprocessor/pom.xml +++ b/annotationprocessor/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 annotationprocessor @@ -31,13 +32,6 @@ - - com.google.testing.compile - compile-testing - test - - - @@ -55,9 +49,84 @@ + + maven-enforcer-plugin + + + enforce + + enforce + + + + + [3.0.4,) + + + 1.6 + + + false + + * + + + io.toolisticon.annotationprocessortoolkit:* + com.sun:tools:* + *:*:*:*:test:* + *:*:*:*:provided:* + + + + + + + + - + + + + + tools-jar + + false + + ${java.home}/../lib/tools.jar + + + + + com.sun + tools + ${java.version} + system + ${java.home}/../lib/tools.jar + + + + + classes-jar + + false + + ${java.home}/../Classes/classes.jar + + + + + com.sun + tools + + system + ${java.home}/../Classes/classes.jar + + + + + + diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtils.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtils.java index 17a62be7..239d52aa 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtils.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtils.java @@ -274,7 +274,7 @@ public static String createMessage(ValidationMessage message, Object... messageP } - private static String argToString(Object arg){ + protected static String argToString(Object arg){ if(arg == null) { diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java index 671d3594..03023079 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java @@ -81,8 +81,11 @@ public static List convertVarargsToList(T... varargs) { * @param * @return a array that contains all varargs arguments or an array of length 0 if no varargs arguments have been used */ - public static T[] convertVarargsToArray(T... varargs) { + public static T[] convertVarargsToArray(T... varargs) { final Object[] e = {}; + if (varargs == null) { + return (T[])new Object[0]; + } return varargs; } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatcherValidationMessages.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatcherValidationMessages.java index 5df09e40..efbf29a2 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatcherValidationMessages.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatcherValidationMessages.java @@ -27,6 +27,7 @@ public enum CoreMatcherValidationMessages implements ValidationMessage { HAS_PUBLIC_NOARG_CONSTRUCTOR("CM_HAS_PUBLIC_NOARG_CONSTURCTOR", "Element must ${0} have a public noarg constructor or just the default constructor"), IS_GETTER_METHOD("CM_IS_GETTER_METHOD", "Element must ${0} be a getter method : public, not abstract, not static, non void return type, no parameters, with 'get' as name prefix or 'is' or 'has' for boolean return types."), IS_SETTER_METHOD("CM_IS_SETTER_METHOD", "Element must ${0} be a setter method : public, not abstract, not static, void return type, one parameter, with 'set' as name prefix"), + IS_ATTRIBUTE_FIELD("CM_IS_ATTRIBUTE_FIELD", "Element must ${0} not be static and must have a public getter and setter method"), IS_EXECUTABLE_ELEMENT("CM_IS_EXECTUABLE_ELEMENT", "Element must ${0} be a ExecutableElement"), IS_TYPE_ELEMENT("CM_IS_TYPE_ELEMENT", "Element must ${0} be a TypeElement"), IS_VARIABLE_ELEMENT("CM_IS_VARIABLE_ELEMENT", "Element must ${0} be a VariableElement"), diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java index 5667c318..6fd6ca0a 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java @@ -21,6 +21,7 @@ import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.HasVoidReturnTypeMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsAnnotationTypeMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsAssignableToMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsAttributeFieldMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsClassMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsConstructorMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsEnumMatcher; @@ -185,6 +186,13 @@ private CoreMatchers() { */ public final static ImplicitCoreMatcher IS_SETTER_METHOD = new ImplicitCoreMatcher(new IsSetterMethodMatcher(), CoreMatcherValidationMessages.IS_SETTER_METHOD); + /** + * Matcher to check if passed element represents an attribute. + * Passed VariableElement for field must not be static and must have valid getter and setter methods. + */ + public final static ImplicitCoreMatcher IS_ATTRIBUTE_FIELD = new ImplicitCoreMatcher(new IsAttributeFieldMatcher(), CoreMatcherValidationMessages.IS_ATTRIBUTE_FIELD); + + // --------------------------------------------------------------------------------- // -- IS CORE MATCHER @@ -256,4 +264,6 @@ private CoreMatchers() { public final static IsElementBasedCoreMatcher IS_PARAMETER = new IsElementBasedCoreMatcher(new IsParameterMatcher(), CoreMatcherValidationMessages.IS_PARAMETER); + + } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/PlainValidationMessage.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/PlainValidationMessage.java index 7a907f26..7da30e0c 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/PlainValidationMessage.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/PlainValidationMessage.java @@ -47,4 +47,6 @@ public static PlainValidationMessage create(String message) { public static PlainValidationMessage create(String code, String message) { return new PlainValidationMessage(code, message); } + + } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matcher.java index c0a5fe60..e962c7dc 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matcher.java @@ -13,19 +13,12 @@ public class Matcher { /** * Constructor that allows passing in of the {@link Matcher} to be wrapped. * - * @param matcher + * @param matcher the matcher to be wrapped within */ public Matcher(MT matcher) { this.matcher = matcher; } - /** - * Hidden constructor. - */ - private Matcher() { - this.matcher = null; - } - /** * Gets the wrapped Matcher. * diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/AbstractAnnotationProcessorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/AbstractAnnotationProcessorTest.java index 0425bfe5..1b7260fe 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/AbstractAnnotationProcessorTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/AbstractAnnotationProcessorTest.java @@ -5,10 +5,12 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.TestAnnotation; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -27,6 +29,11 @@ public AbstractAnnotationProcessorTest(String message, AnnotationProcessorUnitTe super(configuration); } + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); + } + @Parameterized.Parameters(name = "{index}: {0}") public static List data() { return Arrays.asList( diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationUtilsTest.java index 7f0b8f99..6fcf011d 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationUtilsTest.java @@ -1,6 +1,5 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; @@ -10,6 +9,7 @@ import io.toolisticon.annotationprocessortoolkit.tools.annotationutilstestclasses.DefaultValueAnnotation; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -380,7 +380,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationClassAttributeTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationClassAttributeTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationValueUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationValueUtilsTest.java index e415f718..96be6538 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationValueUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/AnnotationValueUtilsTest.java @@ -1,11 +1,11 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.annotationvalueutilstestclasses.AnnotationValueTestAnnotation; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -1094,7 +1094,6 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat(AnnotationValueUtils.isAnnotationArray(null), Matchers.is(false)); - } } ) @@ -1112,7 +1111,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationValueUtilsTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationValueUtilsTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java index aed06e30..2d7fdc0b 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java @@ -1,12 +1,12 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.FilterTestAnnotation1; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -450,7 +450,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessTypeHierarchyTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessTypeHierarchyTest.java index 62bdb6af..502c0a8c 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessTypeHierarchyTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessTypeHierarchyTest.java @@ -1,10 +1,10 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -138,8 +138,6 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat(ElementUtils.AccessTypeHierarchy.getDirectSuperTypeElementOfKindType(typeElement), Matchers.nullValue()); - - } } ) @@ -251,7 +249,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FilerUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FilerUtilsTest.java index 18c1abe2..5a20412f 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FilerUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FilerUtilsTest.java @@ -1,10 +1,10 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorIntegrationTest; import io.toolisticon.annotationprocessortoolkit.testhelper.integrationtest.AnnotationProcessorIntegrationTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.integrationtest.AnnotationProcessorIntegrationTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.generators.FileObjectUtilsTestAnnotationProcessor; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -32,9 +32,9 @@ public static List data() { { "Test valid usage", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("testcases/generators/FilerUtilsTestClass.java") + .setSourceFileToCompile("/testcases/generators/FilerUtilsTestClass.java") .compilationShouldSucceed() - .javaFileObjectShouldMatch(JavaFileObjects.forResource("testcases/generators/expectedResult.txt")) + .javaFileObjectShouldMatch(JavaFileObjectUtils.readFromResource("/testcases/generators/expectedResult.txt")) .build() }, diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FluentElementFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FluentElementFilterTest.java index 6d8a5230..8f5504d6 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FluentElementFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/FluentElementFilterTest.java @@ -1,6 +1,5 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.FilterTestAnnotation1; import io.toolisticon.annotationprocessortoolkit.FilterTestAnnotation2; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; @@ -10,6 +9,7 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.TestAnnotation; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -196,7 +196,7 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - List results = FluentElementFilter.createFluentElementFilter((List)null) + List results = FluentElementFilter.createFluentElementFilter((List) null) .applyInvertedFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.FIELD) .getResult(); @@ -382,7 +382,7 @@ protected void testCase(TypeElement element) { // null valued element list List result = - FluentElementFilter.createFluentElementFilter((List)null) + FluentElementFilter.createFluentElementFilter((List) null) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf(null) .getResult(); @@ -530,7 +530,7 @@ protected void testCase(TypeElement element) { // null valued element list List result = - FluentElementFilter.createFluentElementFilter((List)null) + FluentElementFilter.createFluentElementFilter((List) null) .applyInvertedFilter(CoreMatchers.BY_NAME).filterByOneOf(null) .getResult(); @@ -674,7 +674,7 @@ protected void testCase(TypeElement element) { // handle nulls correctly - List result = FluentElementFilter.createFluentElementFilter((List)null) + List result = FluentElementFilter.createFluentElementFilter((List) null) .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(null) .getResult(); @@ -819,7 +819,7 @@ protected void testCase(TypeElement element) { // handle nulls correctly - List result = FluentElementFilter.createFluentElementFilter((List)null) + List result = FluentElementFilter.createFluentElementFilter((List) null) .applyFilter(CoreMatchers.BY_ANNOTATION).filterByOneOf(FilterTestAnnotation1.class) .getResult(); @@ -971,7 +971,7 @@ protected void testCase(TypeElement element) { // handle nulls correctly - List result = FluentElementFilter.createFluentElementFilter((List)null) + List result = FluentElementFilter.createFluentElementFilter((List) null) .applyInvertedFilter(CoreMatchers.BY_ANNOTATION).filterByOneOf(FilterTestAnnotation1.class) .getResult(); @@ -1098,7 +1098,7 @@ protected void testCase(TypeElement element) { // detects multiple elements correctly - MatcherAssert.assertThat(FluentElementFilter.createFluentElementFilter((List)null).hasSingleElement(), Matchers.is(false)); + MatcherAssert.assertThat(FluentElementFilter.createFluentElementFilter((List) null).hasSingleElement(), Matchers.is(false)); } @@ -1286,7 +1286,7 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { // detects empty results correctly - MatcherAssert.assertThat(FluentElementFilter.createFluentElementFilter((List)null).getResultSize(), Matchers.is(0)); + MatcherAssert.assertThat(FluentElementFilter.createFluentElementFilter((List) null).getResultSize(), Matchers.is(0)); } @@ -1322,7 +1322,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtilsTest.java index a69ab5d5..b75ccebf 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/MessagerUtilsTest.java @@ -13,6 +13,7 @@ import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.tools.Diagnostic; +import java.util.Arrays; /** * Unit test for {@link MessagerUtils}. @@ -63,6 +64,64 @@ public void testGetMessaggerUtils() { } + @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}")); + + } + + + @Test + public void argToString_nullValue() { + MatcherAssert.assertThat(MessagerUtils.argToString(null), Matchers.is("")); + } + + @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")); + + } + // ---------------------------------------------------- // Test different number of args and it's stability @@ -105,6 +164,37 @@ public void testErrorElementMessageNullValuedArgumentEvenMessageHas2Placeholders } + // ---------------------------------------------------- + // Test string based pribtMessage methods + // ---------------------------------------------------- + + @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); + + } + // ---------------------------------------------------- // Test different kind of MessagerUtils methods // passed element, annotationmirror, message, message arguments diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtilsTest.java index 6dc0ea80..30c80ce4 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtilsTest.java @@ -1,13 +1,13 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -1439,7 +1439,7 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); - MatcherAssert.assertThat("Should detect matching array correctly", TypeUtils.Arrays.isArrayOfType(typeMirror,String.class)); + MatcherAssert.assertThat("Should detect matching array correctly", TypeUtils.Arrays.isArrayOfType(typeMirror, String.class)); } } @@ -1458,7 +1458,7 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); - MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror,StringBuilder.class)); + MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror, StringBuilder.class)); } } @@ -1495,9 +1495,9 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String.class); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType(typeMirror, (Class)null)); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, String.class)); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, (Class)null)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType(typeMirror, (Class) null)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, String.class)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, (Class) null)); } } @@ -1518,7 +1518,7 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); - MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror,StringBuilder.class.getCanonicalName())); + MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror, StringBuilder.class.getCanonicalName())); } } @@ -1555,9 +1555,9 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String.class); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType(typeMirror, (String)null)); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, String.class.getCanonicalName())); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, (String)null)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType(typeMirror, (String) null)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, String.class.getCanonicalName())); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, (String) null)); } } @@ -1579,7 +1579,7 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); TypeMirror componentTypeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String.class); - MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayOfType(typeMirror,componentTypeMirror)); + MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayOfType(typeMirror, componentTypeMirror)); } } @@ -1600,7 +1600,7 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); TypeMirror componentTypeMirror = TypeUtils.TypeRetrieval.getTypeMirror(StringBuilder.class); - MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror,componentTypeMirror)); + MatcherAssert.assertThat("Should detect mismatching array type correctly", !TypeUtils.Arrays.isArrayOfType(typeMirror, componentTypeMirror)); } } @@ -1639,8 +1639,8 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String.class); MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType(typeMirror, (TypeMirror) null)); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, typeMirror)); - MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror)null, (TypeMirror) null)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, typeMirror)); + MatcherAssert.assertThat("Should return false for null value", !TypeUtils.Arrays.isArrayOfType((TypeMirror) null, (TypeMirror) null)); } } @@ -1660,7 +1660,7 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); - MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror,Object.class)); + MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror, Object.class)); } } @@ -1680,7 +1680,7 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); - MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror,Object.class.getCanonicalName())); + MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror, Object.class.getCanonicalName())); } } @@ -1701,7 +1701,7 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(String[].class); TypeMirror componentTypeMirror = TypeUtils.TypeRetrieval.getTypeMirror(Object.class); - MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror,componentTypeMirror)); + MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isArrayAssignableTo(typeMirror, componentTypeMirror)); } } @@ -1722,13 +1722,13 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(List[].class); TypeMirror componentTypeMirror = TypeUtils.TypeRetrieval.getTypeMirror(Collection.class); - MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isErasedArrayAssignableTo(typeMirror,componentTypeMirror)); + MatcherAssert.assertThat("Should detect matching array type correctly", TypeUtils.Arrays.isErasedArrayAssignableTo(typeMirror, componentTypeMirror)); // null safety - MatcherAssert.assertThat("Should return false if first typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(null,componentTypeMirror)); - MatcherAssert.assertThat("Should return false if second typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(typeMirror,null)); - MatcherAssert.assertThat("Should return false if both typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(null,null)); + MatcherAssert.assertThat("Should return false if first typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(null, componentTypeMirror)); + MatcherAssert.assertThat("Should return false if second typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(typeMirror, null)); + MatcherAssert.assertThat("Should return false if both typeMirror is null", !TypeUtils.Arrays.isErasedArrayAssignableTo(null, null)); } } ) @@ -1748,13 +1748,12 @@ protected void testCase(TypeElement element) { TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(List[].class); TypeMirror componentTypeMirror = TypeUtils.TypeRetrieval.getTypeMirror(Collection.class); - MatcherAssert.assertThat("Should return false if typeMirror is null", !TypeUtils.Arrays.isArrayAssignableTo(null,componentTypeMirror)); - MatcherAssert.assertThat("Should return false if componentType is null", !TypeUtils.Arrays.isArrayAssignableTo(typeMirror,(TypeMirror) null)); - MatcherAssert.assertThat("Should return false if both typeMirror and componentType are null", !TypeUtils.Arrays.isArrayAssignableTo(null,(TypeMirror) null)); + MatcherAssert.assertThat("Should return false if typeMirror is null", !TypeUtils.Arrays.isArrayAssignableTo(null, componentTypeMirror)); + MatcherAssert.assertThat("Should return false if componentType is null", !TypeUtils.Arrays.isArrayAssignableTo(typeMirror, (TypeMirror) null)); + MatcherAssert.assertThat("Should return false if both typeMirror and componentType are null", !TypeUtils.Arrays.isArrayAssignableTo(null, (TypeMirror) null)); - - MatcherAssert.assertThat("Should return for non array typeMirror", !TypeUtils.Arrays.isArrayAssignableTo(TypeUtils.TypeRetrieval.getTypeMirror(List.class),componentTypeMirror)); + MatcherAssert.assertThat("Should return for non array typeMirror", !TypeUtils.Arrays.isArrayAssignableTo(TypeUtils.TypeRetrieval.getTypeMirror(List.class), componentTypeMirror)); } } @@ -1773,7 +1772,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); + return JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtils_GenericsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtils_GenericsTest.java index 6bedb606..e8b00b8d 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtils_GenericsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/TypeUtils_GenericsTest.java @@ -1,6 +1,5 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; @@ -10,6 +9,7 @@ import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericTypeKind; import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericTypeWildcard; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -1511,7 +1511,7 @@ protected void testCase(TypeElement element) { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("GenericsTestClass.java"); + return JavaFileObjectUtils.readFromResource("/GenericsTestClass.java"); } @Test diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/UtilitiesTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/UtilitiesTest.java new file mode 100644 index 00000000..62b52fe2 --- /dev/null +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/UtilitiesTest.java @@ -0,0 +1,112 @@ +package io.toolisticon.annotationprocessortoolkit.tools; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Unit test for {@link Utilities}. + */ +public class UtilitiesTest { + + // ----------------------------------------------- + // convertArrayToSet + // ----------------------------------------------- + + + @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")); + + } + + // ----------------------------------------------- + // convertArrayToSet + // ----------------------------------------------- + + @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)); + + } + + // ----------------------------------------------- + // convertVarargsToList + // ----------------------------------------------- + + @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")); + + } + + // ----------------------------------------------- + // convertVarargsToList + // ----------------------------------------------- + + @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")); + + } + +} diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandTest.java index 492846fd..7c4f1bd1 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandTest.java @@ -1,360 +1,321 @@ package io.toolisticon.annotationprocessortoolkit.tools.command.impl; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.BeanUtils; import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; -import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; -import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; -import java.util.List; /** * Unit Test for {@link GetAttributesCommand}. */ -@RunWith(Parameterized.class) -public class GetAttributesCommandTest extends AbstractAnnotationProcessorUnitTest { - - public GetAttributesCommandTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); - } - - +public class GetAttributesCommandTest { @Before public void init() { MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/testcases.commands/GetAttributesCommandTestClass.java")); - new Object[][]{ + @Test + public void shouldExecuteSuccessfullyDataAnnotatedClass() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - { - "execute - Data annotated class", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestDataAnnotatedClass") + .getResult().get(0); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestDataAnnotatedClass") - .getResult().get(0); - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + } + }) - } - } - ) - .build() + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyGetterAnnotatedClass() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "execute - Getter annotated class", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedClass") + .getResult().get(0); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedClass") - .getResult().get(0); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + } + }) - } - } - ) - .build() + .compilationShouldSucceed() + .testCompilation(); + } - }, - { - "execute - Setter annotated class", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void shouldExecuteSuccessfullySetterAnnotatedClass() { - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedClass") - .getResult().get(0); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedClass") + .getResult().get(0); - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - } - } - ) - .build() + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + } + }) - }, - { - "execute - Getter and Setter annotated class", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .compilationShouldSucceed() + .testCompilation(); + } - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedClass") - .getResult().get(0); + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedClass() { - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); - } - } - ) - .build() + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedClass") + .getResult().get(0); - }, - { - "execute - Mixed Getter and Setter annotated class and field 2", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField1") - .getResult().get(0); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + } + }) - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + .compilationShouldSucceed() + .testCompilation(); - } - } - ) - .build() + } - }, - { - "execute - Mixed Getter and Setter annotated class and field 2", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void shouldExecuteSuccessfullyMixedGetterAndSetterAnnotatedClassAndField2() { - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField2") - .getResult().get(0); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField1") + .getResult().get(0); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - } - } - ) - .build() + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + } + }) - }, - { - "execute - getter annotated field", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .compilationShouldSucceed() + .testCompilation(); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedField") - .getResult().get(0); + } - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + @Test + public void shouldExecuteSuccessfullyMixedGetterAndSetterAnnotatedClassAndField2_() { - } - } - ) - .build() + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField2") + .getResult().get(0); - }, - { - "execute - setter annotated field", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedField") - .getResult().get(0); + } + }) - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + .compilationShouldSucceed() + .testCompilation(); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + } - } - } - ) - .build() + @Test + public void shouldExecuteSuccessfullyGetterAnnotatedField() { - }, - { - "execute - getter and setter annotated field", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedField") - .getResult().get(0); + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedField") + .getResult().get(0); - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); - } - } - ) - .build() + } + }) + .compilationShouldSucceed() + .testCompilation(); - }, + } - { - "execute - getter and setter annotated method", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void shouldExecuteSuccessfullySetterAnnotatedField() { - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethods") - .getResult().get(0); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); - MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedField") + .getResult().get(0); - } - } - ) - .build() + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); - }, + } + }) - { - "execute - getter and setter annotated method with invalid parameter type", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .useCustomSourceFile("testcases.commands/GetAttributesCommandTestClass.java") - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .compilationShouldSucceed() + .testCompilation(); - TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_CLASS) - .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethodsWithInvalidSetterParameterType") - .getResult().get(0); + } - BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedField() { - MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedField") + .getResult().get(0); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); - }, - } + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); - ); + } + }) + .compilationShouldSucceed() + .testCompilation(); } + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedMethod() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethods") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); - @Test - public void test() { - super.test(); } - public static List convertToList(T... element) { + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedMethodWithInvalidParameterType() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethodsWithInvalidSetterParameterType") + .getResult().get(0); - return Arrays.asList(element); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommand.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); } + } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandWithInheritanceTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandWithInheritanceTest.java new file mode 100644 index 00000000..33ce7d51 --- /dev/null +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/command/impl/GetAttributesCommandWithInheritanceTest.java @@ -0,0 +1,355 @@ +package io.toolisticon.annotationprocessortoolkit.tools.command.impl; + + +import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; +import io.toolisticon.annotationprocessortoolkit.tools.BeanUtils; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; +import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; + +import javax.lang.model.element.TypeElement; +import java.util.HashSet; +import java.util.Set; + +/** + * Unit Test for {@link GetAttributesCommandWithInheritance}. + */ +public class GetAttributesCommandWithInheritanceTest { + + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); + } + + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/testcases.commands/GetAttributesCommandWithInheritanceTestClass.java")); + + @Test + public void shouldExecuteSuccessfullyDataAnnotatedClass() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestDataAnnotatedClass") + .getResult().get(0); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyInheritedDataAnnotatedClass() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestInheritedDataAnnotatedClass") + .getResult().get(0); + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(2)); + + Set fields = new HashSet(); + for (BeanUtils.AttributeResult item : attributeResult) { + fields.add(item.getFieldName()); + } + + MatcherAssert.assertThat(fields, Matchers.containsInAnyOrder("field1", "field3")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyGetterAnnotatedClass() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedClass") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullySetterAnnotatedClass() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedClass") + .getResult().get(0); + + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedClass() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedClass") + .getResult().get(0); + + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + + @Test + public void shouldExecuteSuccessfullyMixedGetterAndSetterAnnotatedClassAndField2() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField1") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + + @Test + public void shouldExecuteSuccessfullyMixedGetterAndSetterAnnotatedClassAndField2_() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestMixedGetterAndSetterAnnotatedClassAndField2") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + + @Test + public void shouldExecuteSuccessfullyGetterAnnotatedField() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustGetterAnnotatedField") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullySetterAnnotatedField() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestJustSetterAnnotatedField") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedField() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestGetterAndSetterAnnotatedField") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedMethod() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethods") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(1)); + MatcherAssert.assertThat(attributeResult[0].getFieldName(), Matchers.is("field1")); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void shouldExecuteSuccessfullyGetterAndSetterAnnotatedMethodWithInvalidParameterType() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + TypeElement typeElement = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_CLASS) + .applyFilter(CoreMatchers.BY_REGEX_NAME).filterByOneOf(".*TestFieldGetterAndSetterMethodsWithInvalidSetterParameterType") + .getResult().get(0); + + BeanUtils.AttributeResult[] attributeResult = GetAttributesCommandWithInheritance.INSTANCE.execute(typeElement); + + MatcherAssert.assertThat(attributeResult.length, Matchers.is(0)); + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + +} diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCriteriaElementFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCriteriaElementFilterTest.java index 61156924..1e6e8702 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCriteriaElementFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCriteriaElementFilterTest.java @@ -1,79 +1,55 @@ package io.toolisticon.annotationprocessortoolkit.tools.filter; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * unit test for {@link InclusiveCriteriaElementFilter}. */ -@RunWith(Parameterized.class) -public class InclusiveCriteriaElementFilterTest extends AbstractAnnotationProcessorUnitTest { +public class InclusiveCriteriaElementFilterTest { - public InclusiveCriteriaElementFilterTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); } - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); - } - - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - - new Object[][]{ - - { - "findByAll : happy path", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor( - new AbstractUnitTestAnnotationProcessorClass() { - - @Override - protected void testCase(TypeElement element) { - - List filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) 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")); + @Test + public void findByAll_happyPath() { - // shouldn't find anything - filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED, Modifier.PROTECTED); - MatcherAssert.assertThat("Must have noelement'", filteredList, Matchers.empty()); + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + List filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) 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")); - } - } - ); + // shouldn't find anything + filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED, Modifier.PROTECTED); + MatcherAssert.assertThat("Must have noelement'", filteredList, Matchers.empty()); - } + } + }) + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java")) + .compilationShouldSucceed() + .testCompilation(); - @Test - public void test() { - super.test(); } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ChildElementsTransitionFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ChildElementsTransitionFilterTest.java index afe889e5..ff97f632 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ChildElementsTransitionFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ChildElementsTransitionFilterTest.java @@ -1,30 +1,25 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.impl; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.TransitionFilters; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link ChildElementsTransitionFilter}. */ -@RunWith(Parameterized.class) -public class ChildElementsTransitionFilterTest extends AbstractAnnotationProcessorUnitTest { +public class ChildElementsTransitionFilterTest { public static class TestClass { @@ -49,97 +44,80 @@ private String testMethod2() { } - public ChildElementsTransitionFilterTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationClassAttributeTestClass.java")); - new Object[][]{ + @Test + public void childElementsTransitionFilter_testTransitionWithSingleInputElement() { - { - "ChildElementsTransitionFilter test - test transition with single input element", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); - - MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); - - List expectedElements = (List) testElement.getEnclosedElements(); - + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.CHILD_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedElements.get(0), expectedElements.get(1), expectedElements.get(2))); + TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); + MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); - } - } - ) - .build() + List expectedElements = (List) testElement.getEnclosedElements(); + List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.CHILD_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedElements.get(0), expectedElements.get(1), expectedElements.get(2))); - }, - { - "ChildElementsTransitionFilter test - test transition with multiple input elements", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - TypeElement testElement1 = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); - TypeElement testElement2 = TypeUtils.TypeRetrieval.getTypeElement(TestClass2.class); + } + }) - MatcherAssert.assertThat("PRECONDITION : testELement1 must not be null", testElement1, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : testELement2 must not be null", testElement2, Matchers.notNullValue()); + .compilationShouldSucceed() + .testCompilation(); - List expectedElements1 = (List) testElement1.getEnclosedElements(); - List expectedElements2 = (List) testElement2.getEnclosedElements(); + } + @Test + public void childElementsTransitionFilter_testTransitionWithMultipleInputElement() { - List list = FluentElementFilter.createFluentElementFilter(testElement1, testElement2).applyTransitionFilter(TransitionFilters.CHILD_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder( - expectedElements1.get(0), - expectedElements1.get(1), - expectedElements1.get(2), - expectedElements2.get(0), - expectedElements2.get(1), - expectedElements2.get(2) - )); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement testElement1 = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); + TypeElement testElement2 = TypeUtils.TypeRetrieval.getTypeElement(TestClass2.class); - } - } - ) - .build() + MatcherAssert.assertThat("PRECONDITION : testELement1 must not be null", testElement1, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : testELement2 must not be null", testElement2, Matchers.notNullValue()); + List expectedElements1 = (List) testElement1.getEnclosedElements(); + List expectedElements2 = (List) testElement2.getEnclosedElements(); - }, + List list = FluentElementFilter.createFluentElementFilter(testElement1, testElement2).applyTransitionFilter(TransitionFilters.CHILD_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder( + expectedElements1.get(0), + expectedElements1.get(1), + expectedElements1.get(2), + expectedElements2.get(0), + expectedElements2.get(1), + expectedElements2.get(2) + )); - } - ); + } + }) + .compilationShouldSucceed() + .testCompilation(); } - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationClassAttributeTestClass.java"); - } - @Test - public void test() { - super.test(); - } } \ No newline at end of file diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ParentElementTransitionFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ParentElementTransitionFilterTest.java index 031ff7d5..69782bcb 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ParentElementTransitionFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/ParentElementTransitionFilterTest.java @@ -1,30 +1,25 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.impl; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.TransitionFilters; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link ParentElementTransitionFilter}. */ -@RunWith(Parameterized.class) -public class ParentElementTransitionFilterTest extends AbstractAnnotationProcessorUnitTest { +public class ParentElementTransitionFilterTest { public static class TestClass { @@ -48,93 +43,72 @@ private String testMethod2() { } + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationClassAttributeTestClass.java")); - public ParentElementTransitionFilterTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - - - new Object[][]{ - - - { - "ParentElementTransitionFilter test - test transition with single input elements", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); - - MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); + @Test + public void parentElementTransitionFilter_testTransitionWithSingleInputElement() { - TypeElement expectedParentElement = (TypeElement) testElement.getEnclosingElement(); + unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); - List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.PARENT_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder((Element)expectedParentElement)); + MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); + TypeElement expectedParentElement = (TypeElement) testElement.getEnclosingElement(); - } - } - ) - .build() + List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.PARENT_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder((Element) expectedParentElement)); - }, - { - "ParentElementTransitionFilter test - test transition with multiple input elements", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - TypeElement testElement1 = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); - TypeElement testElement2 = TypeUtils.TypeRetrieval.getTypeElement(TestClass2.class); + } + }) - MatcherAssert.assertThat("PRECONDITION : testElement1 must not be null", testElement1, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : testElement2 must not be null", testElement2, Matchers.notNullValue()); + .compilationShouldSucceed() + .testCompilation(); - Element expectedElements1 = testElement1.getEnclosingElement(); - Element expectedElements2 = testElement2.getEnclosingElement(); + } + @Test + public void parentElementTransitionFilter_testTransitionWithMultipleInputElement() { - List list = FluentElementFilter.createFluentElementFilter(testElement1, testElement2).applyTransitionFilter(TransitionFilters.PARENT_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder( - expectedElements1, - expectedElements2 - )); + unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement testElement1 = TypeUtils.TypeRetrieval.getTypeElement(TestClass.class); + TypeElement testElement2 = TypeUtils.TypeRetrieval.getTypeElement(TestClass2.class); - } - } - ) - .build() + MatcherAssert.assertThat("PRECONDITION : testElement1 must not be null", testElement1, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : testElement2 must not be null", testElement2, Matchers.notNullValue()); + Element expectedElements1 = testElement1.getEnclosingElement(); + Element expectedElements2 = testElement2.getEnclosingElement(); - }, + List list = FluentElementFilter.createFluentElementFilter(testElement1, testElement2).applyTransitionFilter(TransitionFilters.PARENT_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder( + expectedElements1, + expectedElements2 + )); - } - ); + } + }) + .compilationShouldSucceed() + .testCompilation(); } - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationClassAttributeTestClass.java"); - } - @Test - public void test() { - super.test(); - } } \ No newline at end of file diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/RemoveDuplicatesTransitionFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/RemoveDuplicatesTransitionFilterTest.java index 92173e9e..270051cb 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/RemoveDuplicatesTransitionFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/RemoveDuplicatesTransitionFilterTest.java @@ -1,84 +1,51 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.impl; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; -import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.TransitionFilters; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link RemoveDuplicatesTransitionFilter}. */ -@RunWith(Parameterized.class) -public class RemoveDuplicatesTransitionFilterTest extends AbstractAnnotationProcessorUnitTest { +public class RemoveDuplicatesTransitionFilterTest { - - - public RemoveDuplicatesTransitionFilterTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - - - new Object[][]{ - - - { - "RemoveDuplicatesTransitionFilter test - test transition to remove duplicate values", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - - - List list = FluentElementFilter.createFluentElementFilter(element, element).applyTransitionFilter(TransitionFilters.REMOVE_DUPLICATES_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder((Element)element)); - - - } - } - ) - .build() - - - }, - + @Test + public void removeDuplicatesTransitionFilter_testTransitionToRemoveDuplicateValues() { + CompileTestBuilder.unitTest() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - ); + List list = FluentElementFilter.createFluentElementFilter(element, element).applyTransitionFilter(TransitionFilters.REMOVE_DUPLICATES_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder((Element) element)); - } + } + }) + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationClassAttributeTestClass.java")) + .compilationShouldSucceed() + .testCompilation(); - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationClassAttributeTestClass.java"); } - @Test - public void test() { - super.test(); - } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/SuperTypesTransitionFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/SuperTypesTransitionFilterTest.java index 8cb1f30f..6242c482 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/SuperTypesTransitionFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/impl/SuperTypesTransitionFilterTest.java @@ -1,31 +1,25 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.impl; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.TransitionFilters; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link SuperTypesTransitionFilter}. */ -@RunWith(Parameterized.class) -public class SuperTypesTransitionFilterTest extends AbstractAnnotationProcessorUnitTest { +public class SuperTypesTransitionFilterTest { public interface TestInterface { @@ -40,100 +34,78 @@ public static class InheritingClass extends SuperClass { } - public SuperTypesTransitionFilterTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); + @Before + public void init() { + MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - - - new Object[][]{ - - - { - "ParentElementTransitionFilter test - test transition with single input elements", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(InheritingClass.class); - - MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); - - TypeElement expectedSuperType1 = TypeUtils.TypeRetrieval.getTypeElement(SuperClass.class); - TypeElement expectedSuperType2 = TypeUtils.TypeRetrieval.getTypeElement(Object.class); - TypeElement expectedSuperType3 = TypeUtils.TypeRetrieval.getTypeElement(TestInterface.class); - - MatcherAssert.assertThat("PRECONDITION : expectedSuperType1 must not be null", expectedSuperType1, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : expectedSuperType2 must not be null", expectedSuperType2, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : expectedSuperType3 must not be null", expectedSuperType3, Matchers.notNullValue()); + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationClassAttributeTestClass.java")); + @Test + public void parentElementTransitionFilter_testTransitionWithSingleInputElements() { - List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.SUPER_TYPE_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedSuperType1,expectedSuperType2,expectedSuperType3)); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(InheritingClass.class); - } - } - ) - .build() + MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); + TypeElement expectedSuperType1 = TypeUtils.TypeRetrieval.getTypeElement(SuperClass.class); + TypeElement expectedSuperType2 = TypeUtils.TypeRetrieval.getTypeElement(Object.class); + TypeElement expectedSuperType3 = TypeUtils.TypeRetrieval.getTypeElement(TestInterface.class); - }, - { - "ParentElementTransitionFilter test - test transition with single input elements", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat("PRECONDITION : expectedSuperType1 must not be null", expectedSuperType1, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : expectedSuperType2 must not be null", expectedSuperType2, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : expectedSuperType3 must not be null", expectedSuperType3, Matchers.notNullValue()); - TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(InheritingClass.class); - MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); + List list = FluentElementFilter.createFluentElementFilter(testElement).applyTransitionFilter(TransitionFilters.SUPER_TYPE_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedSuperType1, expectedSuperType2, expectedSuperType3)); - TypeElement expectedSuperType1 = TypeUtils.TypeRetrieval.getTypeElement(SuperClass.class); - TypeElement expectedSuperType2 = TypeUtils.TypeRetrieval.getTypeElement(Object.class); - TypeElement expectedSuperType3 = TypeUtils.TypeRetrieval.getTypeElement(TestInterface.class); - MatcherAssert.assertThat("PRECONDITION : expectedSuperType1 must not be null", expectedSuperType1, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : expectedSuperType2 must not be null", expectedSuperType2, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : expectedSuperType3 must not be null", expectedSuperType3, Matchers.notNullValue()); + } + }) + .compilationShouldSucceed() + .testCompilation(); + } + @Test + public void parentElementTransitionFilter_testTransitionWithMultipleInputElements() { - List list = FluentElementFilter.createFluentElementFilter(testElement, testElement).applyTransitionFilter(TransitionFilters.SUPER_TYPE_ELEMENTS).getResult(); - MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedSuperType1,expectedSuperType2,expectedSuperType3,expectedSuperType1,expectedSuperType2,expectedSuperType3)); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + TypeElement testElement = TypeUtils.TypeRetrieval.getTypeElement(InheritingClass.class); - } - } - ) - .build() + MatcherAssert.assertThat("PRECONDITION : testELement must not be null", testElement, Matchers.notNullValue()); + TypeElement expectedSuperType1 = TypeUtils.TypeRetrieval.getTypeElement(SuperClass.class); + TypeElement expectedSuperType2 = TypeUtils.TypeRetrieval.getTypeElement(Object.class); + TypeElement expectedSuperType3 = TypeUtils.TypeRetrieval.getTypeElement(TestInterface.class); - }, + MatcherAssert.assertThat("PRECONDITION : expectedSuperType1 must not be null", expectedSuperType1, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : expectedSuperType2 must not be null", expectedSuperType2, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : expectedSuperType3 must not be null", expectedSuperType3, Matchers.notNullValue()); - } + List list = FluentElementFilter.createFluentElementFilter(testElement, testElement).applyTransitionFilter(TransitionFilters.SUPER_TYPE_ELEMENTS).getResult(); + MatcherAssert.assertThat(list, Matchers.containsInAnyOrder(expectedSuperType1, expectedSuperType2, expectedSuperType3, expectedSuperType1, expectedSuperType2, expectedSuperType3)); - ); + } + }) + .compilationShouldSucceed() + .testCompilation(); } - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationClassAttributeTestClass.java"); - } - - @Test - public void test() { - super.test(); - } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidatorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidatorTest.java index 3ccd42ca..87fe274a 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidatorTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidatorTest.java @@ -1,10 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; import io.toolisticon.annotationprocessortoolkit.tools.ProcessingEnvironmentUtils; @@ -15,18 +11,17 @@ import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.PlainValidationMessage; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ValidationMessage; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; import java.util.Arrays; import java.util.List; @@ -34,2240 +29,2444 @@ /** * Unit test for {@link FluentElementValidator}. */ -@RunWith(Parameterized.class) -public class FluentElementValidatorTest extends AbstractAnnotationProcessorUnitTest { - - public FluentElementValidatorTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); - } +public class FluentElementValidatorTest { @Before public void init() { MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java")); - new Object[][]{ + @Test + public void validateByNoneOfCriteriaWithDefaults() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - { - "validate by none of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + } + }) - } - } - ) - .build() + .compilationShouldSucceed() + .testCompilation(); + } - }, - { - "validate by none of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validateByNoneOfCriteriaWithDefaults_failingValidation() { - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by one of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + } + }) + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + .compilationShouldFail() + .testCompilation(); - } - } - ) - .build() + } - }, - { - "validate by one of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validateByOneOfCriteriaWithDefaults() { - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + + @Test + public void validateByOneOfCriteriaWithDefaults_failingValidation() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + }) + + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + + .compilationShouldFail() + .testCompilation(); + + } + + @Test + public void validateByAllOfCriteriaWithDefaults() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + }) + + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void validateByAllOfCriteriaWithDefaults_failingValidation() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC, Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + }) + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + .compilationShouldFail() + .testCompilation(); + + } + + @Test + public void validateByAtLeastOneOfCriteriaWithDefaults() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + } + }) + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void validateByAtLeastOneOfCriteriaWithDefaults_failingValidation() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + + + } + }) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + .compilationShouldFail() + .testCompilation(); + + } + + @Test + public void validateByIsCriteria_elementBasedAndTypeElementBased_withDefaults() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + }) + .compilationShouldSucceed() + .testCompilation(); + + } + + @Test + public void validateByIsCriteria_elementBasedAndTypeElementBased_withDefaults_failingValidation_ELEMENT_CHECK() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + }) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_EXECUTABLE_ELEMENT.getCode()) + + .compilationShouldFail() + .testCompilation(); + + } + + + @Test + public void validateByIsCriteria_elementBasedAndTypeElementBased_withDefaults_failingValidation_ELEMENT_KIND_CHECK() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).is(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + + + } + }) + .compilationShouldFail() + .expectedErrorMessages(CoreMatcherValidationMessages.IS_INTERFACE.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validateByImplicitCriteria_hasReturnType_withDefaults() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + }) + .compilationShouldSucceed() + .testCompilation(); + + + } + + @Test + public void validateByImplicitCriteria_hasReturnType_withDefaults_failibgValidation() { + unitTestBuilder.compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) + + .testCompilation(); + + + } + + + // Now do the same test_with_custom_message or message scope + + @Test + public void validateByNoneOfCriteriaWithCustomSettings() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + }) + + .compilationShouldSucceed() + + .testCompilation(); + + + } + + @Test + public void validateByNoneOfCriteriaWithCustomSettings_failingValidation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validatByOneOfCriteriaWithCustomSettings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validateByOneOfCriteriaWithCustomSettings_failingValidation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validateByAllOfCriteriaWithCustomSettings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validateByAllOfCriteriaWithCustomSettings_failingValidation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC, Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validateByAtLeastOneOfCriteriaWithCustomSettings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_by_at_least_one_of_criteria_with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validateby_is_criteria__element_based_and_type_element_based__with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").is(CoreMatchers.IS_TYPE_ELEMENT).setCustomMessage("UPS").is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_by_is_criteria__element_based_and_type_element_based__with_custom_settings__failing_validation__ELEMENT_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").is(CoreMatchers.IS_EXECUTABLE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_EXECUTABLE_ELEMENT.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_by_is_criteria__element_based_and_type_element_based__with_custom_settings__failing_validation__ELEMENT_KIND_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).setCustomMessage("UPS").is(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_INTERFACE.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_by_implicit_criteria__has_return_type__with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).warning().applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_by_implicit_criteria__has_return_type__with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).setCustomMessage("UPS").applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "UPS") + + .testCompilation(); + + + } + + // -------------------------------------------------- + // -- Now do the same_with_inverted validator + // -------------------------------------------------- + + + @Test + public void validate_inverted_by_none_of_criteria_with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_none_of_criteria_with_defaults__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_one_of_criteria_with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_one_of_criteria_with_defaults__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_all_of_criteria_with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PROTECTED, Modifier.FINAL).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_all_of_criteria_with_defaults__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_at_least_one_of_criteria_with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_at_least_one_of_criteria_with_defaults__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC, Modifier.ABSTRACT).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).isNot(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_defaults__failing_validation__ELEMENT_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_TYPE_ELEMENT).isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_TYPE_ELEMENT.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_defaults__failing_validation__ELEMENT_KIND_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_CLASS.getCode()) + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_implicit_criteria__has_return_type__with_defaults() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + @Test + public void validate_inverted_by_implicit_criteria__has_return_type__with_defaults__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) + + .testCompilation(); + + + } + + + // Now do the same test_with_custom_message or message scope + + @Test + public void validate_inverted_by_none_of_criteria_with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_none_of_criteria_with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_one_of_criteria_with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_one_of_criteria_with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_all_of_criteria_with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PROTECTED).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_all_of_criteria_with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_at_least_one_of_criteria_with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_at_least_one_of_criteria_with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).setCustomMessage("UPS").isNot(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_custom_settings__failing_validation__ELEMENT_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").isNot(CoreMatchers.IS_TYPE_ELEMENT).isNot(CoreMatchers.IS_METHOD).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_TYPE_ELEMENT.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_is_criteria__element_based_and_type_element_based__with_custom_settings__failing_validation__ELEMENT_KIND_CHECK() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).setCustomMessage("UPS").isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.IS_CLASS.getCode(), "UPS") + + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_implicit_criteria__has_return_type__with_custom_settings() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).warning().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + .testCompilation(); + + + } + + + @Test + public void validate_inverted_by_implicit_criteria__has_return_type__with_custom_settings__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + + + FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + + + } + } + ) + + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "UPS") + + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by all of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + } - } - } - ) - .build() + @Test + public void validate_note_warning_and_error_message__failing_validation_with_setCustomMessage_done_upfront() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); - }, - { - "validate by all of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC, Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .setCustomMessage("NOTE").note().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .setCustomMessage("WARNING").warning().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by at least one of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .setCustomMessage("ERROR").error().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + } + } + ) + .expectedNoteMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "NOTE") + .expectedWarningMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "WARNING") + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "ERROR") - } - } - ) - .build() + .testCompilation(); - }, - { - "validate by at least one of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + @Test + public void validate_note_warning_and_error_message__failing_validation() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by is criteria (element based and type element based) with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); + MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); + MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); - FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .note().setCustomMessage("NOTE").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); - } - } - ) - .build() + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .warning().setCustomMessage("WARNING").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); + MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) + .error().setCustomMessage("ERROR").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) + .validateAndIssueMessages() + , Matchers.equalTo(false)); - }, - { - "validate by is criteria (element based and type element based) with defaults - failing validation (ELEMENT CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + .expectedNoteMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "NOTE") + .expectedWarningMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "WARNING") + .expectedErrorMessages(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "ERROR") + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_EXECUTABLE_ELEMENT.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by is criteria (element based and type element based) with defaults - failing validation (ELEMENT KIND CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).is(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_INTERFACE.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate by implicit criteria (has return type) with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_Implicit_Element_based_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("SUCCESS", true)).validateAndIssueMessages() + , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("FAILURE", false)).validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .build() + .testCompilation(); - }, - { - "validate by implicit criteria (has return type) with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + @Test + public void validate_Implicit_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) - .finishMessageValidator() - .build() + .expectedErrorMessages("FAILURE") + .testCompilation(); - }, + } - // Now do the same test with custom message or message scope - { - "validate by none of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + @Test + public void validate_INVERTED_Implicit_Element_based_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("SUCCESS", false)).validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .build() + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("FAILURE", true)).validateAndIssueMessages(); + } + } + ) - }, - { - "validate by none of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by one of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + @Test + public void validate_INVERTED_Implicit_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "SUCCESS", false)).validateAndIssueMessages() + , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "FAILURE", true)).validateAndIssueMessages(); - }, - { - "validate by one of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by all of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + } - } - } - ) - .build() + @Test + public void validate_Inclusive_Characteristics_Element_based_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - }, - { - "validate by all of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC, Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by at least one of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element).warning().applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + } - } - } - ) - .build() + @Test + public void validate_Inclusive_Characteristics_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "validate by at least one of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by is criteria (element based and type element based) with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").is(CoreMatchers.IS_TYPE_ELEMENT).setCustomMessage("UPS").is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .build() + } - }, - { - "validate by is criteria (element based and type element based) with custom settings - failing validation (ELEMENT CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_INVERTED_Inclusive_Characteristics_Element_based_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").is(CoreMatchers.IS_EXECUTABLE_ELEMENT).is(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_EXECUTABLE_ELEMENT.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by is criteria (element based and type element based) with custom settings - failing validation (ELEMENT KIND CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator((Element) element).is(CoreMatchers.IS_TYPE_ELEMENT).setCustomMessage("UPS").is(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_INTERFACE.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate by implicit criteria (has return type) with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + } - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).warning().applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + @Test + public void validate_INVERTED_Inclusive_Characteristics_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - }, - { - "validate by implicit criteria (has return type) with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + } + } + ) + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).setCustomMessage("UPS").applyValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "UPS") - .finishMessageValidator() - .build() + } - }, + @Test + public void validate_Inclusive_Characteristics_Element_based_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - // -------------------------------------------------- - // -- Now do the same with inverted validator - // -------------------------------------------------- + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - { - "validate inverted by none of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .build() + .testCompilation(); - }, - { - "validate inverted by none of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + @Test + public void validate_Inclusive_Characteristics_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by one of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - } - } - ) - .build() + .expectedErrorMessages("FAILURE") + .testCompilation(); - }, - { - "validate inverted by one of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by all of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_INVERTED_Inclusive_Characteristics_Element_based_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PROTECTED, Modifier.FINAL).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .build() + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - }, - { - "validate inverted by all of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by at least one of criteria with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + @Test + public void validate_INVERTED_Inclusive_Characteristics_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - }, - { - "validate inverted by at least one of criteria with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element).applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC, Modifier.ABSTRACT).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by is criteria (element based and type element based) with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).isNot(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + } - } - } - ) - .build() + @Test + public void validate_Inclusive_Characteristics_Element_based_validator___at_least_one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "validate inverted by is criteria (element based and type element based) with defaults - failing validation (ELEMENT CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_TYPE_ELEMENT).isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_TYPE_ELEMENT.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by is criteria (element based and type element based) with defaults - failing validation (ELEMENT KIND CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_CLASS.getCode()) - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by implicit criteria (has return type) with defaults", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + } - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + @Test + public void validate_Inclusive_Characteristics_validator__at_least_one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .build() + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - }, - { - "validate inverted by implicit criteria (has return type) with defaults - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + .expectedErrorMessages("FAILURE") + .testCompilation(); - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) - .finishMessageValidator() - .build() + @Test + public void validate_INVERTED_Inclusive_Characteristics_Element_based_validator___at_least_one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").justValidate() + , Matchers.equalTo(false)); - // Now do the same test with custom message or message scope - { - "validate inverted by none of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + } + } + ) + .expectedErrorMessages("FAILURE") - } - } - ) - .build() + .testCompilation(); - }, - { - "validate inverted by none of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + @Test + public void validate_INVERTED_Inclusive_Characteristics_validator__at_least_one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by one of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PROTECTED).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS!", false, true)).hasAtLeastOneOf("XX", "YY").justValidate() + , Matchers.equalTo(false)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .build() + } + } + ) + .expectedErrorMessages("FAILURE") - }, - { - "validate inverted by one of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.ABSTRACT, Modifier.PUBLIC).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by all of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PROTECTED).validateAndIssueMessages(); + @Test + public void validate_Inclusive_Characteristics_Element_based_validator__all_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .build() + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - }, - { - "validate inverted by all of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by at least one of criteria with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element).warning().applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PROTECTED, Modifier.ABSTRACT).validateAndIssueMessages(); + @Test + public void validate_Inclusive_Characteristics_validator__all_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); - }, - { - "validate inverted by at least one of criteria with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - FluentElementValidator.createFluentElementValidator(element).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.PUBLIC).validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_MODIFIER.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by is criteria (element based and type element based) with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).setCustomMessage("UPS").isNot(CoreMatchers.IS_INTERFACE).validateAndIssueMessages(); + } - } - } - ) - .build() + @Test + public void validate_INVERTED_Inclusive_Characteristics_Element_based_validator__all_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - }, - { - "validate inverted by is criteria (element based and type element based) with custom settings - failing validation (ELEMENT CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator((Element) element).setCustomMessage("UPS").isNot(CoreMatchers.IS_TYPE_ELEMENT).isNot(CoreMatchers.IS_METHOD).validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_TYPE_ELEMENT.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by is criteria (element based and type element based) with custom settings - failing validation (ELEMENT KIND CHECK)", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator((Element) element).isNot(CoreMatchers.IS_EXECUTABLE_ELEMENT).setCustomMessage("UPS").isNot(CoreMatchers.IS_CLASS).validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_CLASS.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate inverted by implicit criteria (has return type) with custom settings", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndParameters"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + @Test + public void validate_INVERTED_Inclusive_Characteristics_validator__all_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).warning().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasAllOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .build() + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); - }, - { - "validate inverted by implicit criteria (has return type) with custom settings - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + .expectedErrorMessages("FAILURE") + .testCompilation(); - FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))).setCustomMessage("UPS").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "UPS") - .finishMessageValidator() - .build() - - - }, - { - "validate note, warning and error message - failing validation with setCustomMessage done upfront", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + @Test + public void validate_Exclusive_Characteristics_Element_based_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .setCustomMessage("NOTE").note().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .setCustomMessage("WARNING").warning().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); + } + } + ) - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .setCustomMessage("ERROR").error().applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setNoteChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "NOTE") - .setWarningChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "WARNING") - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "ERROR") - .finishMessageValidator() - .build() - - - }, - { - "validate note, warning and error message - failing validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - List methods = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod"); - MatcherAssert.assertThat("Precondition : must have found exactly one element", methods.size() == 1); - MatcherAssert.assertThat("Precondition : element must be method", ElementUtils.CheckKindOfElement.isMethod(methods.get(0))); + } - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .note().setCustomMessage("NOTE").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .warning().setCustomMessage("WARNING").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); + @Test + public void validate_Exclusive_Characteristics_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat(FluentElementValidator.createFluentElementValidator(ElementUtils.CastElement.castMethod(methods.get(0))) - .error().setCustomMessage("ERROR").applyInvertedValidator(CoreMatchers.HAS_VOID_RETURN_TYPE) - .validateAndIssueMessages() - , Matchers.equalTo(false)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .addMessageValidator() - .setNoteChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "NOTE") - .setWarningChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "WARNING") - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode(), "ERROR") - .finishMessageValidator() - .build() - - - }, - { - "validate Implicit Element based validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("SUCCESS", true)).validateAndIssueMessages() - , Matchers.equalTo(true)); + } + } + ) - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("FAILURE", false)).validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Implicit validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Implicit Element based validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("SUCCESS", false)).validateAndIssueMessages() - , Matchers.equalTo(true)); + @Test + public void validate_INVERTED_Exclusive_Characteristics_Element_based_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("FAILURE", true)).validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Implicit validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "SUCCESS", false)).validateAndIssueMessages() - , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createImplicitCoreMatcher(TypeElement.class, "FAILURE", true)).validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics Element based validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); + @Test + public void validate_INVERTED_Exclusive_Characteristics_validator__none_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics Element based validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedErrorMessages("FAILURE") - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics Element based validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + @Test + public void validate_Exclusive_Characteristics_Element_based_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + } + } + ) - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics Element based validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + } - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_Exclusive_Characteristics_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, false)).hasOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics Element based validator - at least one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .expectedErrorMessages("FAILURE") - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics validator - at least one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + @Test + public void validate_INVERTED_Exclusive_Characteristics_Element_based_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics Element based validator - at least one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator(element) + .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, false)).hasOneOf("XX", "YY").validateAndIssueMessages(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAtLeastOneOf("XX", "YY").justValidate() - , Matchers.equalTo(false)); + } + } + ) - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); + .expectedErrorMessages("FAILURE") - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics validator - at least one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS!", false, true)).hasAtLeastOneOf("XX", "YY").justValidate() - , Matchers.equalTo(false)); + } - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasAtLeastOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics Element based validator - all of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_INVERTED_Exclusive_Characteristics_validator__one_of() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element) + .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Inclusive Characteristics validator - all of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics Element based validator - all of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + } - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedInclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + @Test + public void validate_IS_Element_based_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Inclusive Characteristics validator - all of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator((Element) element).is(TestCoreMatcherFactory.createElementBasedIsCoreMatcher(TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() + , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + FluentElementValidator.createFluentElementValidator((Element) element).is(TestCoreMatcherFactory.createElementBasedIsCoreMatcher(TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasAllOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + } + } + ) + .expectedErrorMessages("FAILURE") - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createInclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasAllOf("XX", "YY").validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Exclusive Characteristics Element based validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + } - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Exclusive Characteristics validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void validate_IS_validator() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() + , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, true)).hasNoneOf("XX", "YY").validateAndIssueMessages(); + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Exclusive Characteristics Element based validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .expectedErrorMessages("FAILURE") - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Exclusive Characteristics validator - none of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, false)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasNoneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + @Test + public void execute_command__if_validation_succeeds() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", false, false)).hasNoneOf("XX", "YY").validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Exclusive Characteristics Element based validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)) + .executeCommand( + new Command() { + @Override + public void execute(TypeElement element) { + ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.NOTE, "EXECUTED COMMAND"); + } + }); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + } + } + ) - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate Exclusive Characteristics validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + .expectedNoteMessages("EXECUTED COMMAND") - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, false)).hasOneOf("XX", "YY").validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Exclusive Characteristics Element based validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", false, false)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + @Test + public void execute_command_with_return_value__if_validation_succeeds() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "SUCCESS", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element) - .error().applyInvertedValidator(TestCoreMatcherFactory.createElementBasedExclusiveCriteriaCoreMatcher(String.class, "FAILURE", true, false)).hasOneOf("XX", "YY").validateAndIssueMessages(); + MatcherAssert.assertThat( + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)) + .executeCommand( + new CommandWithReturnType() { + @Override + public String execute(TypeElement element) { + ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.NOTE, "EXECUTED COMMAND"); + return "YES!"; + } + }), + Matchers.is("YES!") + ); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate INVERTED Exclusive Characteristics validator - one of", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + } + ) - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "SUCCESS", false, true)).hasOneOf("XX", "YY").validateAndIssueMessages() - , Matchers.equalTo(true)); + .expectedNoteMessages("EXECUTED COMMAND") - FluentElementValidator.createFluentElementValidator(element) - .error().applyValidator(TestCoreMatcherFactory.createExclusiveCriteriaCoreMatcher(TypeElement.class, String.class, "FAILURE", true, true)).hasOneOf("XX", "YY").validateAndIssueMessages(); + .testCompilation(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate IS Element based validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator((Element) element).is(TestCoreMatcherFactory.createElementBasedIsCoreMatcher(TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() - , Matchers.equalTo(true)); + } - FluentElementValidator.createFluentElementValidator((Element) element).is(TestCoreMatcherFactory.createElementBasedIsCoreMatcher(TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "validate IS validator", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Test + public void dont_execute_command_but_trigger_validation_message__if_validation_fails() { + unitTestBuilder + .compilationShouldSucceed() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) + .executeCommand( + new Command() { @Override - protected void testCase(TypeElement element) { + public void execute(TypeElement element) { + ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.ERROR, "EXECUTED COMMAND"); + } + }); + } + } + ) + .testCompilation(); - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)).validateAndIssueMessages() - , Matchers.equalTo(true)); - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)).validateAndIssueMessages(); + } - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "execute command - if validation succeeds", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void dont_execute_command__if_validation_fails() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) + .executeCommandAndIssueMessages( + new Command() { + @Override + public void execute(TypeElement element) { + throw new IllegalStateException("Shouldn't execute_command if_validation_fails"); + } + }); + } + } + ) + + .expectedErrorMessages("FAILURE") + + .testCompilation(); - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)) - .executeCommand( - new Command() { - @Override - public void execute(TypeElement element) { - ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.NOTE, "EXECUTED COMMAND"); - } - }); + } - } - } - ) - .addMessageValidator() - .setNoteChecks("EXECUTED COMMAND") - .finishMessageValidator() - .build() - - - }, - { - "execute command with return value - if validation succeeds", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - - MatcherAssert.assertThat( - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "SUCCESS", true)) - .executeCommand( - new CommandWithReturnType() { - @Override - public String execute(TypeElement element) { - ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.NOTE, "EXECUTED COMMAND"); - return "YES!"; - } - }), - Matchers.is("YES!") - ); - } - } - ) - .addMessageValidator() - .setNoteChecks("EXECUTED COMMAND") - .finishMessageValidator() - .build() - - - }, - { - "don't execute command but trigger validation message - if validation fails", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) - .executeCommand( - new Command() { - @Override - public void execute(TypeElement element) { - ProcessingEnvironmentUtils.getMessager().printMessage(Diagnostic.Kind.ERROR, "EXECUTED COMMAND"); - } - }); - } - } - ) - .build() + @Test + public void dont_execute_command_with_return_value__if_validation_fails() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) + .executeCommandAndIssueMessages( + new CommandWithReturnType() { + @Override + public String execute(TypeElement element) { + throw new IllegalStateException("Shouldn't execute_command if_validation_fails"); + } + }); + } + } + ) + + .expectedErrorMessages("FAILURE") + + .testCompilation(); - }, - { - "don't execute command - if validation fails", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) - .executeCommandAndIssueMessages( - new Command() { - @Override - public void execute(TypeElement element) { - throw new IllegalStateException("Shouldn't execute command if validation fails"); - } - }); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "don't execute command with return value - if validation fails", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - FluentElementValidator.createFluentElementValidator(element).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) - .executeCommandAndIssueMessages( - new CommandWithReturnType() { - @Override - public String execute(TypeElement element) { - throw new IllegalStateException("Shouldn't execute command if validation fails"); - } - }); - } - } - ) - .addMessageValidator() - .setErrorChecks("FAILURE") - .finishMessageValidator() - .build() - - - }, - { - "custom message - with ValidationMessage class and Messageargs", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - FluentElementValidator.createFluentElementValidator(element) - .error().setCustomMessage( - new ValidationMessage() { - @Override - public String getCode() { - return "XXX"; - } - - @Override - public String getMessage() { - return "ERROR ${0} ${0} ${1}!"; - } - }, "YES", "AGAIN" - ).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) - .validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("ERROR YES YES AGAIN!") - .finishMessageValidator() - .build() - - - }, - { - "custom message - with ValidationMessage class without MessageArgs", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } - FluentElementValidator.createFluentElementValidator(element) - .error().setCustomMessage( - PlainValidationMessage.create("XXX", "ERROR!") - ).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) - .validateAndIssueMessages(); - } - } - ) - .addMessageValidator() - .setErrorChecks("ERROR!") - .finishMessageValidator() - .build() + @Test + public void custom_message__with_ValidationMessage_class_and_Messageargs() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + FluentElementValidator.createFluentElementValidator(element) + .error().setCustomMessage( + new ValidationMessage() { + @Override + public String getCode() { + return "XXX"; + } + + @Override + public String getMessage() { + return "ERROR ${0} ${0} ${1}!"; + } + }, "YES", "AGAIN" + ).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) + .validateAndIssueMessages(); + } + } + ) + + .expectedErrorMessages("ERROR YES YES AGAIN!") + + .testCompilation(); - }, + } - } + public void custom_message__with_ValidationMessage_class_without_MessageArgs() { + unitTestBuilder + .compilationShouldFail() + .useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - ); + FluentElementValidator.createFluentElementValidator(element) + .error().setCustomMessage( + PlainValidationMessage.create("XXX", "ERROR!") + ).is(TestCoreMatcherFactory.createIsCoreMatcher(TypeElement.class, TypeElement.class, "FAILURE", false)) + .validateAndIssueMessages(); + } + } + ) - } + .expectedErrorMessages("ERROR!") + .testCompilation(); - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); - } - @Test - public void test() { - super.test(); } + public static List convertToList(T... element) { return Arrays.asList(element); } + } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessageTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessageTest.java index c7976f91..ee57322b 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessageTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessageTest.java @@ -1,190 +1,143 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.impl; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.FilterTestAnnotation1; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.AnnotationUtils; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatcherValidationMessages; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.PlainValidationMessage; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link FluentValidatorMessage}. */ -@RunWith(Parameterized.class) -public class FluentValidatorMessageTest extends AbstractAnnotationProcessorUnitTest { - - public FluentValidatorMessageTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); - } +public class FluentValidatorMessageTest { @Before public void init() { MessagerUtils.setPrintMessageCodes(true); } - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - - new Object[][]{ - - - { - "Check error element message", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - - FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.ERROR, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); - message.issueMessage(); - - } - } - ) - .addMessageValidator() - .setErrorChecks("TEST SUCCESS") - .finishMessageValidator() - .build() - + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java")); - }, - { - "Check warning element message", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { - FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.WARNING, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); - message.issueMessage(); - - } - } - ) - .addMessageValidator() - .setWarningChecks("TEST SUCCESS") - .finishMessageValidator() - .build() + @Test + public void checkErrorElementMessage() { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "Check info element message", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.ERROR, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); + message.issueMessage(); - FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); - message.issueMessage(); + } + }) + .compilationShouldFail() + .testCompilation(); - } - } - ) - .addMessageValidator() - .setNoteChecks("TEST SUCCESS") - .finishMessageValidator() - .build() + } + @Test + public void checkWarningElementMessage() { - }, - { - "Check element with AnnotationMirror", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - List annotatedElement = ElementUtils.AccessEnclosedElements.getEnclosedElementsWithAllAnnotationsOf(element, FilterTestAnnotation1.class); - MatcherAssert.assertThat("PRECONDITION : Must have found one element", annotatedElement.size() == 1); - AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(annotatedElement.get(0), FilterTestAnnotation1.class); - MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror, Matchers.notNullValue()); + FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.WARNING, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); + message.issueMessage(); + } + }) + .compilationShouldSucceed() + .testCompilation(); - FluentValidatorMessage message = new FluentValidatorMessage(annotatedElement.get(0),annotationMirror, Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); - message.issueMessage(); + } + @Test + public void checkInfoElementMessage() { - } - } - ) - .build() + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + FluentValidatorMessage message = new FluentValidatorMessage(element, Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); + message.issueMessage(); - }, - { - "Check element with AnnotationMirror and AnnotationValue", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + }) + .compilationShouldSucceed() + .testCompilation(); - List annotatedElement = ElementUtils.AccessEnclosedElements.getEnclosedElementsWithAllAnnotationsOf(element, FilterTestAnnotation1.class); - MatcherAssert.assertThat("PRECONDITION : Must have found one element", annotatedElement.size() == 1); - AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(annotatedElement.get(0), FilterTestAnnotation1.class); - MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror, Matchers.notNullValue()); - MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror.getElementValues().size() == 1); + } - FluentValidatorMessage message = new FluentValidatorMessage(element, annotatedElement.get(0).getAnnotationMirrors().get(0), annotationMirror.getElementValues().get(0), Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); - message.issueMessage(); + @Test + public void checkElementWithAnnotationMirror() { - } - } - ) - .build() + unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + List annotatedElement = ElementUtils.AccessEnclosedElements.getEnclosedElementsWithAllAnnotationsOf(element, FilterTestAnnotation1.class); + MatcherAssert.assertThat("PRECONDITION : Must have found one element", annotatedElement.size() == 1); + AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(annotatedElement.get(0), FilterTestAnnotation1.class); + MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror, Matchers.notNullValue()); - }, + FluentValidatorMessage message = new FluentValidatorMessage(annotatedElement.get(0), annotationMirror, Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); + message.issueMessage(); - } - ); + } + }) + .compilationShouldSucceed() + .testCompilation(); } + @Test + public void checkElementWithAnnotationMirrorAndAnnotationValue() { - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); - } + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - @Test - public void test() { - super.test(); - } + List annotatedElement = ElementUtils.AccessEnclosedElements.getEnclosedElementsWithAllAnnotationsOf(element, FilterTestAnnotation1.class); + MatcherAssert.assertThat("PRECONDITION : Must have found one element", annotatedElement.size() == 1); + AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(annotatedElement.get(0), FilterTestAnnotation1.class); + MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror, Matchers.notNullValue()); + MatcherAssert.assertThat("PRECONDITION : Must have found one annotation", annotationMirror.getElementValues().size() == 1); - public static List convertToList(T... element) { + FluentValidatorMessage message = new FluentValidatorMessage(element, annotatedElement.get(0).getAnnotationMirrors().get(0), annotationMirror.getElementValues().get(0), Diagnostic.Kind.NOTE, PlainValidationMessage.create("TEST ${0}"), "SUCCESS"); + message.issueMessage(); - return Arrays.asList(element); + } + }) + + .compilationShouldSucceed() + .testCompilation(); } + } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/MatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/MatcherTest.java new file mode 100644 index 00000000..6f271049 --- /dev/null +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/MatcherTest.java @@ -0,0 +1,28 @@ +package io.toolisticon.annotationprocessortoolkit.tools.matcher; + + +import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByAnnotationMatcher; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Unit test for {@link Matcher}. + */ +public class MatcherTest { + + public static class UnitTestMatcher implements BaseMatcher { + + } + + private final static UnitTestMatcher MATCHER = new UnitTestMatcher(); + + @Test + public void testMatcher() { + + Matcher matcher = new Matcher(MATCHER); + MatcherAssert.assertThat(matcher.getMatcher(), Matchers.is(MATCHER)); + + } + +} diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAttributeFieldMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAttributeFieldMatcherTest.java new file mode 100644 index 00000000..f9c6d8cb --- /dev/null +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAttributeFieldMatcherTest.java @@ -0,0 +1,180 @@ +package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; + +import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; +import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; +import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; +import io.toolisticon.compiletesting.CompileTestBuilder; +import org.hamcrest.MatcherAssert; +import org.junit.Test; + +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import java.util.List; + + +/** + * Unit test for {@link IsAttributeFieldMatcher}. + */ +public class IsAttributeFieldMatcherTest { + + public static class TestClass { + + private String validAttributeField; + private static String staticField; + private String fieldWithoutGetter; + private String fieldWithoutSetter; + + + public String getValidAttributeField() { + return validAttributeField; + } + + public void setValidAttributeField(String validAttributeField) { + this.validAttributeField = validAttributeField; + } + + public String getFieldWithoutSetter() { + return fieldWithoutSetter; + } + + public void setFieldWithoutGetter(String fieldWithoutGetter) { + this.fieldWithoutGetter = fieldWithoutGetter; + } + } + + + @Test + public void test_isAttributeField_match__shouldReturnTrue() { + + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + // Do test + MatcherAssert.assertThat("Should return true for non static field with getter and setter : ", + CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("validAttributeField"))); + + + } + + }) + .compilationShouldSucceed() + .testCompilation(); + ; + + } + + @Test + public void test_isNoAttributeField_noGetter_shouldReturnFalse() { + + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + // Do test + MatcherAssert.assertThat("Should return false for non static field without getter : ", + !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("fieldWithoutGetter"))); + + + } + + }) + .compilationShouldSucceed() + .testCompilation(); + ; + + } + + @Test + public void test_isNoAttributeField_noSetter_shouldReturnFalse() { + + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + // Do test + MatcherAssert.assertThat("Should return false for non static field without setter : ", + !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("fieldWithoutSetter"))); + + + } + + }) + .compilationShouldSucceed() + .testCompilation(); + ; + + } + + @Test + public void test_isNoAttributeField_isStatic_shouldReturnFalse() { + + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + // Do test + MatcherAssert.assertThat("Should return false for static field : ", + !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(getField("staticField"))); + + + } + + }) + .compilationShouldSucceed() + .testCompilation(); + ; + + } + + @Test + public void test_passedNullValue_shouldReturnFalse() { + + CompileTestBuilder + .unitTest() + .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + // Do test + MatcherAssert.assertThat("Should return false for passed null value : ", + !CoreMatchers.IS_ATTRIBUTE_FIELD.getMatcher().check(null)); + + + } + + }) + .compilationShouldSucceed() + .testCompilation(); + ; + + } + + + private static VariableElement getField(String fieldName) { + List variableElement = FluentElementFilter.createFluentElementFilter( + TypeUtils.TypeRetrieval.getTypeElement(TestClass.class) + .getEnclosedElements()) + .applyFilter(CoreMatchers.IS_FIELD) + .applyFilter(CoreMatchers.BY_NAME).filterByOneOf(fieldName) + .getResult(); + + // Check precondition + MatcherAssert.assertThat("PRECONDITION : must have found VariableElement of field '" + fieldName + "' for test", variableElement.size() == 1); + + return variableElement.get(0); + } + + +} + + diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsGetterMethodMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsGetterMethodMatcherTest.java index 51f69a35..27e11baa 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsGetterMethodMatcherTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsGetterMethodMatcherTest.java @@ -4,11 +4,9 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; -import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -17,7 +15,6 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import java.io.Serializable; import java.util.Arrays; import java.util.List; @@ -76,17 +73,17 @@ public String isGetterInvalid() { } - public static void checkGetter (TypeElement typeElement, String methodName, boolean expectedResult) { + public static void checkGetter(TypeElement typeElement, String methodName, boolean expectedResult) { List executableElements = - FluentElementFilter.createFluentElementFilter(typeElement.getEnclosedElements()) - .applyFilter(CoreMatchers.IS_METHOD) - .applyFilter(CoreMatchers.BY_NAME).filterByOneOf(methodName) - .getResult(); + FluentElementFilter.createFluentElementFilter(typeElement.getEnclosedElements()) + .applyFilter(CoreMatchers.IS_METHOD) + .applyFilter(CoreMatchers.BY_NAME).filterByOneOf(methodName) + .getResult(); MatcherAssert.assertThat("Precondition: Single result for " + methodName, executableElements.size() == 1); - MatcherAssert.assertThat("methodName",CoreMatchers.IS_GETTER_METHOD.getMatcher().check(executableElements.get(0)), Matchers.is(expectedResult)); + MatcherAssert.assertThat("methodName", CoreMatchers.IS_GETTER_METHOD.getMatcher().check(executableElements.get(0)), Matchers.is(expectedResult)); } @@ -121,8 +118,6 @@ protected void testCase(TypeElement element) { checkGetter(typeElement, "isGetterInvalid", false); - - } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/validators/FluentElementValidatorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/validators/FluentElementValidatorTest.java index 32afdac6..1beddac6 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/validators/FluentElementValidatorTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/validators/FluentElementValidatorTest.java @@ -1,344 +1,322 @@ package io.toolisticon.annotationprocessortoolkit.validators; -import com.google.testing.compile.JavaFileObjects; -import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; -import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatcherValidationMessages; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.FluentElementValidator; +import io.toolisticon.compiletesting.CompileTestBuilder; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import java.util.Arrays; import java.util.List; /** * Unit test for {@link io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.FluentElementValidator}. */ -@RunWith(Parameterized.class) -public class FluentElementValidatorTest extends AbstractAnnotationProcessorUnitTest { +//@RunWith(Parameterized.class) +public class FluentElementValidatorTest { //extends AbstractAnnotationProcessorUnitTest { + @Before public void init() { MessagerUtils.setPrintMessageCodes(true); } - public FluentElementValidatorTest(String message, AnnotationProcessorUnitTestConfiguration configuration) { - super(configuration); - } + private CompileTestBuilder.UnitTestBuilder unitTestBuilder = CompileTestBuilder + .unitTest() + .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorTestClass.java")); + + + @Test + public void shouldValidateSuccessfullyWithAllOf() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - @Parameterized.Parameters(name = "{index}: {0}") - public static List data() { - return Arrays.asList( - new Object[][]{ + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - { - "Should validate succesfully with 'all of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + // Test + MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + } + }) + .compilationShouldSucceed() + .testCompilation(); + + } - // Test - MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); + @Test + public void shouldValidateWithFailureWithAllOf() { - } - } - ) - .build() + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "Validate should fail with 'all of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + // Test + MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC, Modifier.FINAL).validateAndIssueMessages()); + } + }) - // Test - MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC, Modifier.FINAL).validateAndIssueMessages()); + .compilationShouldFail() + .testCompilation(); - } - } - ) - .build() + } + @Test + public void shouldValidateSuccessfullyWithAtLeastOneOf() { - }, - { - "Should validate succesfully with 'at least one of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - // Test - MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); + // Test + MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); - } - } - ) - .build() + } + }) + .compilationShouldSucceed() + .testCompilation(); - }, - { - "Validation should fail with 'at least one of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + @Test + public void shouldValidateWithFailureWithAtLeastOneOf() { - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - // Test - MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.STATIC, Modifier.FINAL).validateAndIssueMessages()); + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - } - } - ) - .build() + // Test + MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasAtLeastOneOf(Modifier.STATIC, Modifier.FINAL).validateAndIssueMessages()); - }, - { - "Should validate succesfully with 'one of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + }) + .compilationShouldFail() + .testCompilation(); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + } - // Test - MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.SYNCHRONIZED, Modifier.FINAL, Modifier.ABSTRACT).validateAndIssueMessages()); + @Test + public void shouldValidateSuccessfullyWithOneOf() { - } - } - ) - .build() + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - }, - { - "validation should fail with 'one of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + // Test + MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasOneOf(Modifier.SYNCHRONIZED, Modifier.FINAL, Modifier.ABSTRACT).validateAndIssueMessages()); + } + }) - // Test - MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); + .compilationShouldSucceed() + .testCompilation(); - } - } - ) - .build() + } + @Test + public void shouldValidateWithFailureWithOneOf() { - }, + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - { - "Validation should succeed with 'none of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + // Test + MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); - // Test - MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.FINAL, Modifier.STATIC).validateAndIssueMessages()); + } + }) - } - } - ) - .build() + .compilationShouldFail() + .testCompilation(); + } - }, - { - "Validation should fail with 'none of'", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + @Test + public void shouldValidateSuccessfullyWithNoneOf() { - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - // Test - MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - } - } - ) - .build() + // Test + MatcherAssert.assertThat("Should be validated as true", FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.FINAL, Modifier.STATIC).validateAndIssueMessages()); - }, - { - "test is matcher - Successful Validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldSucceed() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + } + }) + .compilationShouldSucceed() + .testCompilation(); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + } + @Test + public void shouldValidateWithFailureWithNoneOf() { - // Test - MatcherAssert.assertThat("Should be successfully validated", FluentElementValidator.createFluentElementValidator(elements.get(0)).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).validateAndIssueMessages()) - ; + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } - } - ) - .build() + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); + ExecutableElement testElement = ElementUtils.CastElement.castMethod(elements.get(0)); - }, - { - "test is matcher - Failing Validation", - AnnotationProcessorUnitTestConfigurationBuilder.createTestConfig() - .compilationShouldFail() - .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.IS_EXECUTABLE_ELEMENT.getCode()) - .finishMessageValidator() - .setProcessor(new AbstractUnitTestAnnotationProcessorClass() { - @Override - protected void testCase(TypeElement element) { + // Test + MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(testElement).applyValidator(CoreMatchers.BY_MODIFIER).hasNoneOf(Modifier.SYNCHRONIZED, Modifier.PUBLIC).validateAndIssueMessages()); - // check null value - List elements = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) - .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.FIELD) - .getResult(); - MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() >= 1); + } + }) - // Test - MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(elements.get(0)).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC,Modifier.STATIC).validateAndIssueMessages()) - ; + .compilationShouldFail() + .testCompilation(); - } - } - ) - .build() + } + @Test + public void shouldValidateSuccessfullyIsMatcher() { - }, + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { - } + // check null value + List elements = FluentElementFilter.createFluentElementFilter(ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "synchronizedMethod")) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() == 1); - ); + // Test + MatcherAssert.assertThat("Should be successfully validated", FluentElementValidator.createFluentElementValidator(elements.get(0)).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).validateAndIssueMessages()) + ; - } + } + }) + .compilationShouldSucceed() + .testCompilation(); - @Override - protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource("AnnotationProcessorTestClass.java"); } @Test - public void test() { - super.test(); + public void shouldValidateWithFailureIsMatcher() { + + unitTestBuilder.useProcessor( + new AbstractUnitTestAnnotationProcessorClass() { + @Override + protected void testCase(TypeElement element) { + + + // check null value + List elements = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) + .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.FIELD) + .getResult(); + MatcherAssert.assertThat("precondition : must have found unique testelement", elements.size() >= 1); + + + // Test + MatcherAssert.assertThat("Should be validated as false", !FluentElementValidator.createFluentElementValidator(elements.get(0)).is(CoreMatchers.IS_EXECUTABLE_ELEMENT).applyValidator(CoreMatchers.BY_MODIFIER).hasAllOf(Modifier.PUBLIC, Modifier.STATIC).validateAndIssueMessages()) + ; + + } + }) + + .compilationShouldFail() + .testCompilation(); + } } diff --git a/annotationprocessor/src/test/resources/testcases.commands/GetAttributesCommandWithInheritanceTestClass.java b/annotationprocessor/src/test/resources/testcases.commands/GetAttributesCommandWithInheritanceTestClass.java new file mode 100644 index 00000000..2611fc14 --- /dev/null +++ b/annotationprocessor/src/test/resources/testcases.commands/GetAttributesCommandWithInheritanceTestClass.java @@ -0,0 +1,119 @@ +package io.toolisticon.annotationprocessortoolkit.test; + +import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.TestAnnotation; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +@TestAnnotation +public class GetAttributesCommandWithInheritanceTestClass { + @Data + private static class TestDataAnnotatedClass { + + private String field1; + private static String field2; + + } + + @Getter + private static class TestJustGetterAnnotatedClass { + + private String field1; + private static String field2; + + } + + @Getter + private static class TestJustSetterAnnotatedClass { + + private String field1; + private static String field2; + + } + + @Getter + @Setter + private static class TestGetterAndSetterAnnotatedClass { + + private String field1; + private static String field2; + + } + + @Setter + private static class TestMixedGetterAndSetterAnnotatedClassAndField1 { + + @Getter + private String field1; + + } + + @Getter + private static class TestMixedGetterAndSetterAnnotatedClassAndField2 { + + @Setter + private String field1; + + } + + + private static class TestJustSetterAnnotatedField { + + @Setter + private String field1; + + } + + private static class TestJustGetterAnnotatedField { + + @Setter + private String field1; + + } + + private static class TestGetterAndSetterAnnotatedField { + + @Setter + @Getter + private String field1; + + } + + + private static class TestFieldGetterAndSetterMethods { + + private String field1; + + public String getField1() { + return field1; + } + + public void setField1(String field) { + field1 = field; + } + + } + + private static class TestFieldGetterAndSetterMethodsWithInvalidSetterParameterType { + + private String field1; + + public String getField1() { + return field1; + } + + public void setField1(Long field) { + + } + + } + + @Data + private static class TestInheritedDataAnnotatedClass extends TestDataAnnotatedClass{ + + private String field3; + private static String field4; + + } + +} \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index 27ebb6fe..948fb789 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 common @@ -16,13 +17,6 @@ - - com.google.testing.compile - compile-testing - ${google-compile-testing.version} - compile - - junit junit @@ -78,9 +72,6 @@ * - io.toolisticon.annotationprocessortoolkit:* - com.google.testing.compile:compile-testing - com.sun:tools:* *:*:*:*:test:* *:*:*:*:provided:* diff --git a/example/example-annotationprocessor/src/main/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodHasStringParameterAndVoidReturnTypeCheckAnnotationProcessor.java b/example/example-annotationprocessor/src/main/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodHasStringParameterAndVoidReturnTypeCheckAnnotationProcessor.java index 7dad5db5..15736fd8 100644 --- a/example/example-annotationprocessor/src/main/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodHasStringParameterAndVoidReturnTypeCheckAnnotationProcessor.java +++ b/example/example-annotationprocessor/src/main/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodHasStringParameterAndVoidReturnTypeCheckAnnotationProcessor.java @@ -7,7 +7,6 @@ import io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.FluentElementValidator; import io.toolisticon.example.annotationprocessortoolkit.annotations.MethodWithOneStringParameterAndVoidReturnTypeAnnotation; import io.toolisticon.spiap.api.Service; -import sun.misc.MessageUtils; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; @@ -50,7 +49,6 @@ public boolean processAnnotations(Set annotations, RoundE .validateAndIssueMessages(); - } diff --git a/example/example-annotationprocessor/src/test/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodWithOneStringParameterAndVoidReturnTypeProcessorTest.java b/example/example-annotationprocessor/src/test/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodWithOneStringParameterAndVoidReturnTypeProcessorTest.java index b4d353e8..6d21422e 100644 --- a/example/example-annotationprocessor/src/test/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodWithOneStringParameterAndVoidReturnTypeProcessorTest.java +++ b/example/example-annotationprocessor/src/test/java/io/toolisticon/example/annotationprocessortoolkit/annotationprocessor/MethodWithOneStringParameterAndVoidReturnTypeProcessorTest.java @@ -41,7 +41,7 @@ public static List data() { AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() .setSourceFileToCompile("testcases/methodWithOneStringParameterAndVoidReturn/ValidUsageTest.java") .addMessageValidator() - .setInfoChecks("Start processing") + .setNoteChecks("Start processing") .finishMessageValidator() .compilationShouldSucceed() .build() @@ -52,7 +52,7 @@ public static List data() { .setSourceFileToCompile("testcases/methodWithOneStringParameterAndVoidReturn/InvalidUsageNonVoidReturnType.java") .compilationShouldFail() .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) + .setErrorChecks(CoreMatcherValidationMessages.HAS_VOID_RETURN_TYPE.getCode()) .finishMessageValidator() .build() }, @@ -62,7 +62,7 @@ public static List data() { .setSourceFileToCompile("testcases/methodWithOneStringParameterAndVoidReturn/InvalidUsageNonStringParameter.java") .compilationShouldFail() .addMessageValidator() - .setErrorChecks(CoreMatcherValidationMessages.BY_PARAMETER_TYPE.getCode()) + .setErrorChecks(CoreMatcherValidationMessages.BY_PARAMETER_TYPE.getCode()) .finishMessageValidator() .build() }, diff --git a/pom.xml b/pom.xml index d188e532..4bec5fdd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 io.toolisticon.annotationprocessortoolkit @@ -27,12 +28,12 @@ - org.sonatype.oss - oss-parent - 9 - + io.toolisticon.maven + maven-oss-parent + 0.7.0 + Holisticon AG http://www.holisticon.de/ @@ -84,16 +85,27 @@ 1.6 1.6 - 1.8.0 + 1.6.0 0.5.1 + 0.2.0 4.12 1.3 1.10.19 - 1.16.6 - 0.9 + 1.18.2 + + + 1.16 + 2.4 + 2.5.3 + 2.18.1 + 2.2.4 + 2.18.1 + + 2.10.4 + @@ -101,21 +113,24 @@ clean install + - org.codehaus.mojo - cobertura-maven-plugin - - - true - - - xml - html - - 256m - - true - + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + test + + report + + + maven-enforcer-plugin @@ -140,10 +155,8 @@ io.toolisticon.annotationprocessortoolkit:* - com.sun:tools:* *:*:*:*:test:* *:*:*:*:provided:* - @@ -185,126 +198,19 @@ - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.16 - - - - - - check_java17 - - test - - - check - - - - - - org.codehaus.mojo.signature - java16 - 1.0 - - - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.6 - - - maven-clean-plugin - 2.6.1 - - - maven-resources-plugin - 2.7 - + maven-compiler-plugin - 3.6.0 ${java.compile.source.version} ${java.compile.target.version} - - - - - - - maven-dependency-plugin - 2.9 - - - maven-jar-plugin - 2.5 - - - maven-war-plugin - 2.4 - - - maven-surefire-plugin - 2.18.1 - - - maven-failsafe-plugin - 2.18.1 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - maven-release-plugin - 2.5 - - - maven-javadoc-plugin - 2.10.4 - - - maven-site-plugin - 3.4 - - - maven-enforcer-plugin - 1.3.1 - - - maven-project-info-reports-plugin - 2.7 - - false + org.apache.felix maven-bundle-plugin @@ -314,30 +220,42 @@ io.toolisticon.annotationprocessortoolkit - 2.5.3 + ${maven-bundle-plugin.version} + + + + maven-project-info-reports-plugin + + false + + + - maven-ejb-plugin - 2.5 + org.jacoco + jacoco-maven-plugin + 0.8.2 + - maven-ear-plugin - 2.10 + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + - org.mortbay.jetty - jetty-maven-plugin - 8.1.15.v20140411 + maven-surefire-plugin + ${maven-surefire-plugin.version} + org.bsc.maven maven-processor-plugin - 2.2.4 + ${maven-processor-plugin.version} org.apache.maven.plugins maven-assembly-plugin - 2.4 + ${maven-assembly-plugin.version} @@ -432,41 +350,116 @@ - tools-jar + jdksmallerthan9 - false - - ${java.home}/../lib/tools.jar - + [1.6,9) - - - com.sun - tools - ${java.version} - system - ${java.home}/../lib/tools.jar - - + + + + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.16 + + + + + + check_java17 + + test + + + check + + + + + + org.codehaus.mojo.signature + java16 + 1.0 + + + + + + + + + + + + + + + + - classes-jar + jdkgreaterthan8 - false - - ${java.home}/../Classes/classes.jar - + [9,20) - - - com.sun - tools - - system - ${java.home}/../Classes/classes.jar - - + + + + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.16 + + + + + com.sun.source.util.Trees + com.sun.source.tree.* + + + + + + + + check_java17 + + test + + + check + + + + + + org.codehaus.mojo.signature + java16 + 1.0 + + + + + + + + + + + + + + + + + @@ -502,6 +495,11 @@ test + + io.toolisticon.compiletesting + compiletesting + + @@ -526,7 +524,6 @@ ${project.version} - io.toolisticon.annotationprocessortoolkit testhelper @@ -540,6 +537,7 @@ ${spiap.version} provided + io.toolisticon.spiap spiap-processor @@ -548,9 +546,9 @@ - com.google.testing.compile - compile-testing - ${google-compile-testing.version} + io.toolisticon.compiletesting + compiletesting + ${compileTesting.version} test diff --git a/testhelper/Test.class b/testhelper/Test.class new file mode 100644 index 00000000..953ab82b Binary files /dev/null and b/testhelper/Test.class differ diff --git a/testhelper/Test.java b/testhelper/Test.java new file mode 100644 index 00000000..4b0e152d --- /dev/null +++ b/testhelper/Test.java @@ -0,0 +1 @@ +public class Test{} \ No newline at end of file diff --git a/testhelper/TestClass.class b/testhelper/TestClass.class new file mode 100644 index 00000000..b0fa9ff7 Binary files /dev/null and b/testhelper/TestClass.class differ diff --git a/testhelper/pom.xml b/testhelper/pom.xml index cb5dbb56..9e5591be 100644 --- a/testhelper/pom.xml +++ b/testhelper/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 testhelper @@ -20,13 +21,6 @@ common - - com.google.testing.compile - compile-testing - ${google-compile-testing.version} - compile - - junit junit @@ -38,9 +32,26 @@ org.hamcrest hamcrest-library ${hamcrest.version} + test + + + + io.toolisticon.spiap + spiap-api provided + + io.toolisticon.spiap + spiap-processor + provided + + + + io.toolisticon.compiletesting + compiletesting + provided + @@ -83,8 +94,7 @@ io.toolisticon.annotationprocessortoolkit:* - com.google.testing.compile:compile-testing - com.sun:tools:* + io.toolisticon.spiap:provided *:*:*:*:test:* *:*:*:*:provided:* @@ -95,6 +105,29 @@ + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-resource + generate-resources + + add-resource + + + + + target/generated-sources/annotations + + + + + + + + diff --git a/testhelper/root/Jupp.txt b/testhelper/root/Jupp.txt new file mode 100644 index 00000000..e69de29b diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTest.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTest.java index 3e475a21..69c601fc 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTest.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTest.java @@ -1,7 +1,7 @@ package io.toolisticon.annotationprocessortoolkit.testhelper; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.integrationtest.AnnotationProcessorIntegrationTestConfiguration; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import javax.annotation.processing.Processor; import javax.tools.JavaFileObject; @@ -13,7 +13,6 @@ public abstract class AbstractAnnotationProcessorIntegrationTest { - protected AbstractAnnotationProcessorIntegrationTest( AnnotationProcessorIntegrationTestConfiguration annotationProcessorIntegrationTestConfiguration) { @@ -28,6 +27,6 @@ protected T getAnnotationProcessor() { @Override protected JavaFileObject getSourceFileForCompilation() { - return JavaFileObjects.forResource(getAnnotationProcessorTestConfiguration().getSource()); + return JavaFileObjectUtils.readFromResource(getAnnotationProcessorTestConfiguration().getSource()); } } diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorTest.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorTest.java index 7dec2c1c..6f065a5b 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorTest.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorTest.java @@ -1,17 +1,15 @@ package io.toolisticon.annotationprocessortoolkit.testhelper; -import com.google.testing.compile.CompileTester; import io.toolisticon.annotationprocessortoolkit.testhelper.validator.TestMessageValidator; import io.toolisticon.annotationprocessortoolkit.testhelper.validator.TestValidator; import io.toolisticon.annotationprocessortoolkit.testhelper.validator.TestValidatorType; -import org.hamcrest.MatcherAssert; +import io.toolisticon.compiletesting.impl.AnnotationProcessorWrapper; +import io.toolisticon.compiletesting.impl.CompileTest; +import io.toolisticon.compiletesting.impl.CompileTestConfiguration; import javax.annotation.processing.Processor; import javax.tools.JavaFileObject; -import static com.google.common.truth.Truth.assertAbout; -import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; - /** * Abstract base class which allows parameterized tests. @@ -19,7 +17,6 @@ public abstract class AbstractAnnotationProcessorTest { - public static final String TEST_EXECUTION_MESSAGE = "!!!--- TEST WAS EXECUTED ---!!!"; private T annotationProcessorCommonTestConfiguration; @@ -50,91 +47,34 @@ private Processor getWrappedProcessor() { protected void test() { - JavaFileObject testClassSource = getSourceFileForCompilation(); - TestMessageValidator messageValidationTest = (TestMessageValidator) getTestOfType( annotationProcessorCommonTestConfiguration.getTestcases(), TestValidatorType.MESSAGE_VALIDATOR); - // check if error messages and shouldSucceed aren't set contradictionary - if (annotationProcessorCommonTestConfiguration.getCompilingShouldSucceed() - && messageValidationTest != null - && messageValidationTest.getErrors().length > 0) { - throw new InvalidTestConfigurationException("Test configuration error : Compilation should succeed but also error messages !"); + CompileTestConfiguration configuration = new CompileTestConfiguration(); + configuration.addSourceFiles(getSourceFileForCompilation()); + configuration.setCompilationShouldSucceed(annotationProcessorCommonTestConfiguration.getCompilingShouldSucceed()); + if (messageValidationTest != null) { + configuration.addNoteMessageCheck(messageValidationTest.getNotes()); + configuration.addWarningMessageCheck(messageValidationTest.getWarnings()); + configuration.addErrorMessageCheck(messageValidationTest.getErrors()); } + configuration.addProcessors(getWrappedProcessor()); + + new CompileTest(configuration).executeTest(); + - if ( - ( - annotationProcessorCommonTestConfiguration.getCompilingShouldSucceed() - ) && ( - messageValidationTest == null - || messageValidationTest.getErrors().length == 0 - ) - ) { - CompileTester.SuccessfulCompilationClause compileTester = assertAbout(javaSource()) - .that(testClassSource) - .processedWith(this.getWrappedProcessor()).compilesWithoutError(); + +/*- // check for created files if (annotationProcessorCommonTestConfiguration.getExpectedGeneratedJavaFileObjects() != null) { for (JavaFileObject fileObject : annotationProcessorCommonTestConfiguration.getExpectedGeneratedJavaFileObjects()) { compileTester = compileTester.and().generatesFiles(fileObject); } } - - - // check for info messages (notes) - if (messageValidationTest != null && messageValidationTest.getInfos() != null) { - for (String infos : messageValidationTest.getInfos()) { - compileTester.withNoteContaining(infos); - } - } - - // check for warnings - if (messageValidationTest != null) { - for (String warning : messageValidationTest.getWarnings()) { - compileTester.withWarningContaining(warning); - } - } - - - // check if test was executed at all - compileTester.withNoteContaining(TEST_EXECUTION_MESSAGE); - - } else { - CompileTester.UnsuccessfulCompilationClause compileTester = assertAbout(javaSource()) - .that(testClassSource) - .processedWith(this.getWrappedProcessor()).failsToCompile(); - - if (annotationProcessorCommonTestConfiguration.getCompilingShouldSucceed()) { - MatcherAssert.assertThat("Compiling should have failed", !annotationProcessorCommonTestConfiguration.getCompilingShouldSucceed()); - } - - // check for info messages (notes) - if (messageValidationTest != null && messageValidationTest.getInfos() != null) { - for (String infos : messageValidationTest.getInfos()) { - compileTester.withNoteContaining(infos); - } - } - - // check for warnings - if (messageValidationTest != null) { - for (String warning : messageValidationTest.getWarnings()) { - compileTester.withWarningContaining(warning); - } - } - - // check for errors - if (messageValidationTest != null && messageValidationTest.getErrors() != null) { - for (String error : messageValidationTest.getErrors()) { - compileTester.withErrorContaining(error); - } - } - - // check if test was executed at all - compileTester.withNoteContaining(TEST_EXECUTION_MESSAGE); - } +*/ } diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTest.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTest.java index 9edde3c5..096f5ab7 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTest.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTest.java @@ -1,11 +1,10 @@ package io.toolisticon.annotationprocessortoolkit.testhelper; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import javax.annotation.processing.Processor; import javax.tools.JavaFileObject; -import java.net.URL; /** * Abstract base class for testing annotation processor internal stuff where tools offered by {@link ProcessEnvironment} are needed. @@ -21,11 +20,11 @@ public AbstractAnnotationProcessorUnitTest(AnnotationProcessorUnitTestConfigurat @Override protected JavaFileObject getSourceFileForCompilation() { - URL url = AbstractAnnotationProcessorUnitTest.class.getClassLoader().getResource( - getAnnotationProcessorTestConfiguration().getCustomSourceFile() != null ? - getAnnotationProcessorTestConfiguration().getCustomSourceFile() : - "AnnotationProcessorUnitTestClass.java"); - return url != null ? JavaFileObjects.forResource(url) : null; + + return JavaFileObjectUtils.readFromResource(getAnnotationProcessorTestConfiguration().getCustomSourceFile() != null ? + getAnnotationProcessorTestConfiguration().getCustomSourceFile() : + "/AnnotationProcessorUnitTestClass.java"); + } @Override diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractCompileTestingUnitProcesssor.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractCompileTestingUnitProcesssor.java new file mode 100644 index 00000000..879e960a --- /dev/null +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractCompileTestingUnitProcesssor.java @@ -0,0 +1,31 @@ +package io.toolisticon.annotationprocessortoolkit.testhelper; + +import io.toolisticon.annotationprocessortoolkit.ToolingProvider; +import io.toolisticon.compiletesting.UnitTestProcessor; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; + +/** + * Abstract base class for compile testing framework that initializes the ToolingProvider. + */ +public abstract class AbstractCompileTestingUnitProcesssor implements UnitTestProcessor { + + + @Override + public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) { + try { + + ToolingProvider.setTooling(processingEnvironment); + unitTest(typeElement); + + } finally { + ToolingProvider.clearTooling(); + } + + } + + public abstract void unitTest(TypeElement typeElement); + + +} diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorCommonTestConfiguration.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorCommonTestConfiguration.java index 7ab5237c..d9ca19cd 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorCommonTestConfiguration.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorCommonTestConfiguration.java @@ -24,6 +24,7 @@ public AnnotationProcessorCommonTestConfiguration(Boolean compilingShouldSucceed this.compilingShouldSucceed = compilingShouldSucceed; this.expectedGeneratedJavaFileObjects = expectedGeneratedJavaFileObjects; this.testcases = testcases; + } public Boolean getCompilingShouldSucceed() { diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapper.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapper.java deleted file mode 100644 index 7dd1f1a7..00000000 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapper.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.testhelper; - -import javax.annotation.processing.Completion; -import javax.annotation.processing.Messager; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.Processor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.util.Set; - -/** - * Wrapper class for {@link Processor}. Allows generic creation of generic unit tests. - */ -public final class AnnotationProcessorWrapper implements Processor { - - private final Processor wrappedProcessor; - private Messager messager; - - - private AnnotationProcessorWrapper(Processor processor) { - this.wrappedProcessor = processor; - } - - - @Override - public Set getSupportedOptions() { - return wrappedProcessor.getSupportedOptions(); - } - - @Override - public Set getSupportedAnnotationTypes() { - return wrappedProcessor.getSupportedAnnotationTypes(); - } - - @Override - public SourceVersion getSupportedSourceVersion() { - return wrappedProcessor.getSupportedSourceVersion(); - } - - @Override - public void init(ProcessingEnvironment processingEnv) { - - // get messager - messager = processingEnv.getMessager(); - - wrappedProcessor.init(processingEnv); - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - - // now set note message before calling the processor - messager.printMessage(Diagnostic.Kind.NOTE, AbstractAnnotationProcessorTest.TEST_EXECUTION_MESSAGE); - - return wrappedProcessor.process(annotations, roundEnv); - } - - @Override - public Iterable getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) { - return wrappedProcessor.getCompletions(element, annotation, member, userText); - } - - public static Processor wrapProcessor(Processor processorToWrap) { - - if (processorToWrap == null) { - throw new IllegalArgumentException("Passed processor must not be null"); - } - - return new AnnotationProcessorWrapper(processorToWrap); - } - - public static Processor wrapProcessor(Class processorTypeToWrap) { - - if (processorTypeToWrap == null) { - throw new IllegalArgumentException("passed type must not be null"); - } - - try { - return new AnnotationProcessorWrapper(processorTypeToWrap.newInstance()); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot instantiate passed Class. Make sure that a NoArg constructor exists and is accessible.", e); - } - - } - -} diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/InvalidTestConfigurationException.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/InvalidTestConfigurationException.java deleted file mode 100644 index fa758e27..00000000 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/InvalidTestConfigurationException.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.testhelper; - -/** - * Exception thrown in case of an configuration error. - */ -public class InvalidTestConfigurationException extends RuntimeException { - - - public InvalidTestConfigurationException() { - - } - - - public InvalidTestConfigurationException(String message) { - super(message); - } -} diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilder.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilder.java index edab914f..ffdd5081 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilder.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilder.java @@ -75,7 +75,7 @@ public static class MessageEvaluation { private final BaseConfigurationBuilder baseConfigurationBuilder; private String[] warningChecks; private String[] errorChecks; - private String[] infoChecks; + private String[] noteChecks; MessageEvaluation(BaseConfigurationBuilder baseConfigurationBuilder) { @@ -92,8 +92,8 @@ public MessageEvaluation setErrorChecks(String... errorChecksToSet) { return this; } - public MessageEvaluation setInfoChecks(String... infoChecksToSet) { - this.infoChecks = infoChecksToSet; + public MessageEvaluation setNoteChecks(String... noteChecksToSet) { + this.noteChecks = noteChecksToSet; return this; } @@ -101,7 +101,7 @@ public BaseConfigurationBuilder finishMessageValidator() { baseConfigurationBuilder.testMessageValidator = new TestMessageValidator( errorChecks != null ? errorChecks : new String[0], warningChecks != null ? warningChecks : new String[0], - infoChecks != null ? infoChecks : new String[0] + noteChecks != null ? noteChecks : new String[0] ); return baseConfigurationBuilder; } diff --git a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/validator/TestMessageValidator.java b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/validator/TestMessageValidator.java index ae5db14d..2364d230 100644 --- a/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/validator/TestMessageValidator.java +++ b/testhelper/src/main/java/io/toolisticon/annotationprocessortoolkit/testhelper/validator/TestMessageValidator.java @@ -7,12 +7,12 @@ public class TestMessageValidator implements TestValidator { private final String[] errors; private final String[] warnings; - private final String[] infos; + private final String[] notes; - public TestMessageValidator(String[] errors, String[] warnings, String[] infos) { + public TestMessageValidator(String[] errors, String[] warnings, String[] notes) { this.errors = errors; this.warnings = warnings; - this.infos = infos; + this.notes = notes; } @Override @@ -28,5 +28,7 @@ public String[] getWarnings() { return warnings; } - public String[] getInfos() { return infos; } + public String[] getNotes() { + return notes; + } } diff --git a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTestTest.java b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTestTest.java index b15361c0..b9aaa160 100644 --- a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTestTest.java +++ b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorIntegrationTestTest.java @@ -1,9 +1,10 @@ package io.toolisticon.annotationprocessortoolkit.testhelper; -import com.google.testing.compile.JavaFileObjects; import io.toolisticon.annotationprocessortoolkit.testhelper.integrationtest.AnnotationProcessorIntegrationTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.integrationtest.AnnotationProcessorIntegrationTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; +import io.toolisticon.compiletesting.InvalidTestConfigurationException; +import io.toolisticon.compiletesting.JavaFileObjectUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -50,7 +51,7 @@ public static List data() { { "Test compilation that succeeds", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() .build(), @@ -65,7 +66,7 @@ protected void testCase(TypeElement element) { { "Test compilation that succeeds with warning", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() .build(), @@ -81,7 +82,7 @@ protected void testCase(TypeElement element) { { "Test compilation that succeeds with warning - check warning message", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() .addMessageValidator() .setWarningChecks("MURKS") @@ -99,10 +100,10 @@ protected void testCase(TypeElement element) { { "Test compilation that succeeds with warning - check note/info message", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() .addMessageValidator() - .setInfoChecks("MURKS") + .setNoteChecks("MURKS") .finishMessageValidator() .build(), @@ -117,7 +118,7 @@ protected void testCase(TypeElement element) { { "Test compilation that throws error", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldFail() .build(), new AbstractUnitTestAnnotationProcessorClass() { @@ -131,7 +132,7 @@ protected void testCase(TypeElement element) { { "Test compilation that throws error - check error message", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldFail() .addMessageValidator() .setErrorChecks("MURKS") @@ -148,7 +149,7 @@ protected void testCase(TypeElement element) { { "Test invalid test configuration: compilationShouldSucceed and error messages in MessageValidator", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() .addMessageValidator() .setErrorChecks("MURKS") @@ -166,12 +167,12 @@ protected void testCase(TypeElement element) { { "Test failing compilation with and note, warning and error messages in MessageValidator", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldFail() .addMessageValidator() .setErrorChecks("MURKS_ERROR") .setWarningChecks("MURKS_WARNING") - .setInfoChecks("MURKS_NOTE") + .setNoteChecks("MURKS_NOTE") .finishMessageValidator() .build(), new AbstractUnitTestAnnotationProcessorClass() { @@ -188,9 +189,9 @@ protected void testCase(TypeElement element) { { "Test compilation with java file creation", AnnotationProcessorIntegrationTestConfigurationBuilder.createTestConfig() - .setSourceFileToCompile("TestClass.java") + .setSourceFileToCompile("/TestClass.java") .compilationShouldSucceed() - .javaFileObjectShouldMatch(JavaFileObjects.forSourceString("Test", "public class Test{}")) + .javaFileObjectShouldMatch(JavaFileObjectUtils.readFromString("Test", "public class Test{}")) .build(), new AbstractUnitTestAnnotationProcessorClass() { @Override diff --git a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTestTest.java b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTestTest.java index 3c6e0ebf..ab5ae108 100644 --- a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTestTest.java +++ b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AbstractAnnotationProcessorUnitTestTest.java @@ -3,6 +3,7 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.compiletesting.InvalidTestConfigurationException; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; diff --git a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapperTest.java b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapperTest.java deleted file mode 100644 index 3d4c8bcc..00000000 --- a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/AnnotationProcessorWrapperTest.java +++ /dev/null @@ -1,185 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.testhelper; - -import io.toolisticon.annotationprocessortoolkit.testhelper.testcases.TestAnnotation; -import io.toolisticon.annotationprocessortoolkit.testhelper.testcases.TestAnnotationProcessor; -import io.toolisticon.annotationprocessortoolkit.testhelper.testcases.TestAnnotationProcessorWithMissingNoArgConstructor; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; -import org.mockito.Mockito; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Messager; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.Processor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.util.HashSet; -import java.util.Set; - -/** - * Test for Wrapper class {@link AnnotationProcessorWrapper} to be used with {@link AbstractAnnotationProcessorTest}. - */ -public class AnnotationProcessorWrapperTest { - - @Test - public void createWrapperWithInstance() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessor.class); - - MatcherAssert.assertThat("Must return non null valued Processor", unit != null); - - } - - @Test(expected = IllegalArgumentException.class) - public void createWrapperWithNullValuedInstance() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor((AbstractProcessor) null); - - - } - - @Test - public void createWrapperWithType() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessor.class); - - MatcherAssert.assertThat("Must return non null valued Processor", unit != null); - - } - - - @Test(expected = IllegalArgumentException.class) - public void createWrapperWithTypeOnProcessorWithNoArgConstructor() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessorWithMissingNoArgConstructor.class); - - - } - - @Test(expected = IllegalArgumentException.class) - public void createWrapperWithNullValuedType() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor((Class) null); - - } - - @Test - public void testWrappedSupportedOptionsCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.getSupportedOptions(); - - Mockito.verify(processorSpy).getSupportedOptions(); - - - } - - @Test - public void testWrappedSupportedAnnotationTypesCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.getSupportedAnnotationTypes(); - - Mockito.verify(processorSpy).getSupportedAnnotationTypes(); - - - } - - @Test - public void testWrappedSupportedSourceVersionCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.getSupportedSourceVersion(); - - Mockito.verify(processorSpy).getSupportedSourceVersion(); - - - } - - - @Test - public void testWrappedInitCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Messager messager = Mockito.spy(Messager.class); - ProcessingEnvironment processingEnvironment = Mockito.spy(ProcessingEnvironment.class); - Mockito.when(processingEnvironment.getMessager()).thenReturn(messager); - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.init(processingEnvironment); - - Mockito.verify(processorSpy).init(processingEnvironment); - - - } - - - @Test - public void testWrappedProcessCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Messager messager = Mockito.spy(Messager.class); - ProcessingEnvironment processingEnvironment = Mockito.spy(ProcessingEnvironment.class); - Mockito.when(processingEnvironment.getMessager()).thenReturn(messager); - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.init(processingEnvironment); - - - Set set = new HashSet(); - RoundEnvironment roundEnvironment = Mockito.mock(RoundEnvironment.class); - - - unit.process(set, roundEnvironment); - - Mockito.verify(messager).printMessage(Diagnostic.Kind.NOTE, AbstractAnnotationProcessorTest.TEST_EXECUTION_MESSAGE); - Mockito.verify(processorSpy).process(set, roundEnvironment); - - } - - - @Test - public void testWrappedCompletionsCall() { - - AbstractProcessor processorSpy = Mockito.spy(AbstractProcessor.class); - - Element element = Mockito.mock(Element.class); - AnnotationMirror annotationMirror = Mockito.mock(AnnotationMirror.class); - ExecutableElement executableElement = Mockito.mock(ExecutableElement.class); - String str = "XX"; - - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(processorSpy); - unit.getCompletions(element, annotationMirror, executableElement, str); - - Mockito.verify(processorSpy).getCompletions(element, annotationMirror, executableElement, str); - - - } - - @Test - public void getSupportedAnnotationsDefinedPerAnnotationCorrectly() { - - Processor unit = AnnotationProcessorWrapper.wrapProcessor(new TestAnnotationProcessor()); - - MatcherAssert.assertThat(unit.getSupportedAnnotationTypes(), Matchers.contains(TestAnnotation.class - .getCanonicalName())); - - - } - - -} diff --git a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilderTest.java b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilderTest.java index 37aecf86..7eff5585 100644 --- a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilderTest.java +++ b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/integrationtest/AnnotationProcessorIntegrationTestConfigurationBuilderTest.java @@ -88,7 +88,7 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_noWarningsAn MatcherAssert.assertThat(configuration.getTestcases()[0].getAnnotationProcessorTestType(), Matchers.is(TestValidatorType.MESSAGE_VALIDATOR)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayWithSize(0)); - MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getInfos(), Matchers.arrayWithSize(0)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); @@ -111,7 +111,7 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_withErrors() MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayWithSize(3)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayContainingInAnyOrder("A", "B", "C")); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayWithSize(0)); - MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getInfos(), Matchers.arrayWithSize(0)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); @@ -134,7 +134,7 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_withWarnings MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayWithSize(3)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayContainingInAnyOrder("A", "B", "C")); - MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getInfos(), Matchers.arrayWithSize(0)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); @@ -146,7 +146,7 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_withInfos() AnnotationProcessorIntegrationTestConfiguration configuration = AnnotationProcessorIntegrationTestConfigurationBuilder .createTestConfig() .addMessageValidator() - .setInfoChecks("A", "B", "C") + .setNoteChecks("A", "B", "C") .finishMessageValidator() .build(); @@ -156,8 +156,8 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_withInfos() MatcherAssert.assertThat(configuration.getTestcases()[0].getAnnotationProcessorTestType(), Matchers.is(TestValidatorType.MESSAGE_VALIDATOR)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayWithSize(0)); MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayWithSize(0)); - MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getInfos(), Matchers.arrayWithSize(3)); - MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getInfos(), Matchers.arrayContainingInAnyOrder("A", "B", "C")); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayWithSize(3)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayContainingInAnyOrder("A", "B", "C")); MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); diff --git a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/unittest/AnnotationProcessorUnitTestConfigurationBuilderTest.java b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/unittest/AnnotationProcessorUnitTestConfigurationBuilderTest.java index 71acd812..8c430e3b 100644 --- a/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/unittest/AnnotationProcessorUnitTestConfigurationBuilderTest.java +++ b/testhelper/src/test/java/io/toolisticon/annotationprocessortoolkit/testhelper/unittest/AnnotationProcessorUnitTestConfigurationBuilderTest.java @@ -142,11 +142,34 @@ public void testBuildingOfConfiguration_noInput_setMessageValidator_withWarnings MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); + } + + @Test + public void testBuildingOfConfiguration_noInput_setMessageValidator_withNotes() { + + AnnotationProcessorIntegrationTestConfiguration configuration = AnnotationProcessorIntegrationTestConfigurationBuilder + .createTestConfig() + .addMessageValidator() + .setNoteChecks("A", "B", "C") + .finishMessageValidator() + .build(); + + MatcherAssert.assertThat(configuration, Matchers.notNullValue()); + MatcherAssert.assertThat(configuration.getCompilingShouldSucceed(), Matchers.is(true)); + MatcherAssert.assertThat(configuration.getTestcases(), Matchers.arrayWithSize(1)); + MatcherAssert.assertThat(configuration.getTestcases()[0].getAnnotationProcessorTestType(), Matchers.is(TestValidatorType.MESSAGE_VALIDATOR)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getErrors(), Matchers.arrayWithSize(0)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getWarnings(), Matchers.arrayWithSize(0)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayWithSize(3)); + MatcherAssert.assertThat(((TestMessageValidator) configuration.getTestcases()[0]).getNotes(), Matchers.arrayContainingInAnyOrder("A", "B", "C")); + MatcherAssert.assertThat(configuration.getSource(), Matchers.nullValue()); + + } @Test(expected = IllegalArgumentException.class) public void testNullValuedCompilingSholdSucceedParameter() { - new AnnotationProcessorUnitTestConfiguration(null,Mockito.mock(AbstractUnitTestAnnotationProcessorClass.class), null, new JavaFileObject[0]); + new AnnotationProcessorUnitTestConfiguration(null, Mockito.mock(AbstractUnitTestAnnotationProcessorClass.class), null, new JavaFileObject[0]); } } diff --git a/testhelper/src/test/resources/compiletests/TestClass.java b/testhelper/src/test/resources/compiletests/TestClass.java new file mode 100644 index 00000000..32baade1 --- /dev/null +++ b/testhelper/src/test/resources/compiletests/TestClass.java @@ -0,0 +1,6 @@ +package io.toolisticon.annotationprocessortoolkit.testhelper; + +public class TestClass { + +} + diff --git a/testhelper/src/test/resources/compiletests/javafileobjectutilstest/JavaSourceFromResourceTestClass.java b/testhelper/src/test/resources/compiletests/javafileobjectutilstest/JavaSourceFromResourceTestClass.java new file mode 100644 index 00000000..985d7356 --- /dev/null +++ b/testhelper/src/test/resources/compiletests/javafileobjectutilstest/JavaSourceFromResourceTestClass.java @@ -0,0 +1,7 @@ +package io.toolisticon.annotationprocessortoolkit.testhelper.compiletest; + +public class JavaSourceFromResourceTestClass { + + + +} \ No newline at end of file