+ * This allows pass in of an Element or a processor instance before defining the un it test.
+ *
+ * @return the next fluent api instance
+ */
+ UnitTestWhenInterface when();
+
+ /**
+ * Directly defines unit test. Disables passing in of processor and Element.
+ *
+ * @return the next fluent api instance
+ */
+ UnitTestInterface when(@FluentApiBackingBeanMapping(value = "unitTest", action = MappingAction.SET) @NotNull UnitTestWithoutPassIn unitTest);
+
+ }
+
+ @FluentApiInterface(CompilerTestBB.class)
+ public interface UnitTestGivenInterface {
+
+ /**
+ * Use compiler options.
+ * Options with parameters can, but must not be split over two consecutive Strings.
+ * Those options can be put in one single String (e.g. "-source 1.7" or "-target 1.7").
+ *
+ * @param compilerOptions the options to use
+ * @return the next builder instance
+ */
+ UnitTestGivenInterface useCompilerOptions(@FluentApiBackingBeanMapping(value = "compilerOptions") @NotNull String... compilerOptions);
+
+ /**
+ * Defines modules used during compilation.
+ * This configuration will be ignored for Java versions < 9.
+ *
+ * @param modules The modules to use during compilation
+ * @return the next builder instance
+ */
+ UnitTestGivenInterface useModules(@FluentApiBackingBeanMapping(value = "modules") @NotNull String... modules);
+
+ /**
+ * Convenience method to add multiple source files via resource strings.
+ *
+ * @param resources the source file resource strings
+ * @return the next builder instance
+ */
+ default UnitTestGivenInterface useSourceFiles(String... resources) {
+ UnitTestGivenInterface next = this;
+ if (resources != null) {
+ for (String resource : resources) {
+ next = next.useSourceFile(resource);
+ }
+ }
+ return next;
+ }
+
+ /**
+ * Adds a source file by its resource path string.
+ *
+ * @param resource the resource path string
+ * @return the next fluent interface
+ */
+ default UnitTestGivenInterface useSourceFile(String resource) {
+ return useSourceFile(JavaFileObjectUtils.readFromResource(resource));
+ }
+
+ /**
+ * Adds a source file by its fully qualified class name and a source string.
+ *
+ * @param className the fully qualified class name
+ * @param content the source code of the class as a String
+ * @return the next fluent interface
+ */
+ default UnitTestGivenInterface useSourceFile(String className, String content) {
+ return useSourceFile(JavaFileObjectUtils.readFromString(className, content));
+ }
+
+ /**
+ * Adds a source file as a JavaFileObject.
+ * Use {@link JavaFileObjectUtils} to provide JavaFileObjects.
+ *
+ * @param sourceFile the source file
+ * @return the next fluent interface
+ */
+ UnitTestGivenInterface useSourceFile(@FluentApiBackingBeanMapping(value = "sourceFiles") @NotNull JavaFileObject sourceFile);
+
+
+ /**
+ * Traverse to when section to pass in an Element or a processor instant and to define the unit test scenario.
+ *
+ * @return the next fluent interface
+ */
+ UnitTestWhenInterface when();
+
+
+ }
+
+
+ @FluentApiInterface(CompilerTestBB.class)
+ public interface UnitTestWhenInterface {
+
+ /**
+ * Passes in an Element.
+ *
+ * @return the next fluent interface
+ */
+ PassInElementInterface passInElement();
+
+ /**
+ * Passes in a processor instance.
+ * Processor class must have an accessible noarg constructor.
+ *
+ * @param processorClass The processor type to create the instance for - must not be null and have an accessible no args constructor
+ * @param unitTest);
+ }
+
+
+ // --------------------------------------------------------------------
+ // Common "then" Interfaces
+ // --------------------------------------------------------------------
+
+ @FluentApiInterface(CompilerTestBB.class)
+ public interface UnitTestInterface {
+
+ /**
+ * Traverse to section to define checks
+ *
+ * @return the next fluent interface
+ */
+ UnitTestOutcomeInterface thenExpectThat();
+
+ /**
+ * Executes the test.
+ * All AssertionError triggered inside the unit test will bepassed through to your unit test framework.
+ */
+ @FluentApiCommand(ExecuteTestCommand.class)
+ void executeTest();
+
+
+ }
+
+ @FluentApiInterface(CompilerTestBB.class)
+ public interface BlackBoxTestInterface
+ * Some IDEs like Eclipse don't like resource files ending with *.java.
+ * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
+ * The suffix will be ignored for looking up files via the compile-test file manager.
+ * *
+ *
+ * @param location the location
+ * @param relativeLocationRoot relative location root class
+ * @return The SimpleJavaFileObject for resource
+ */
+ public static SimpleJavaFileObject readFromResource(String location, Class> relativeLocationRoot) {
+
+ if (location == null) {
+ throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("location"));
+ }
+
+ return new JavaSourceFromResource(location, relativeLocationRoot);
+ }
+
+ /**
+ * Read a java source file from resources.
+ * Passed location will be handled as absolute path and will be used to both read resource and as location in compile test file manager.
+ *
+ * Some IDEs like Eclipse don't like resource files ending with *.java.
+ * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
+ * The suffix will be ignored for looking up files via the compile-test file manager.
+ *
+ * @param location the location
+ * @return The SimpleJavaFileObject for resource
+ */
+ public static SimpleJavaFileObject readFromResource(String location) {
+
+ if (location == null) {
+ throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("location"));
+ }
+
+ return new JavaSourceFromResource((!location.startsWith("/") ? "/" : "") + location, null);
+ }
+
+ /**
+ * Reads multiple java source files from resources.
+ * Passed locations will be handled as absolute path and will be used to both read resource and as location in compile test file manager.
+ *
+ * Some IDEs like Eclipse don't like resource files ending with *.java.
+ * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
+ * The suffix will be ignored for looking up files via the compile-test file manager.
+ *
+ * @param locations the location
+ * @return The SimpleJavaFileObject for resource
+ */
+ public static SimpleJavaFileObject[] readFromResources(String... locations) {
+
+ List
* Please use {@link UnitTestForTestingAnnotationProcessors} if you want to unit test annotation processor methods.
*/
-public interface UnitTest *
+ * Please use {@link UnitTestForTestingAnnotationProcessors} if you want to unit test annotation processor methods.
+ */
+public interface UnitTestWithoutPassIn extends UnitTestBase{
+
+ /**
+ * The unit test method.
+ *
+ * @param processingEnvironment the processingEnvironment
+ */
+ void unitTest(ProcessingEnvironment processingEnvironment);
+
+}
diff --git a/cute/src/main/java/io/toolisticon/cute/impl/AnnotationProcessorWrapper.java b/cute/src/main/java/io/toolisticon/cute/impl/AnnotationProcessorWrapper.java
deleted file mode 100644
index 647c932..0000000
--- a/cute/src/main/java/io/toolisticon/cute/impl/AnnotationProcessorWrapper.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package io.toolisticon.cute.impl;
-
-import io.toolisticon.cute.Constants;
-import io.toolisticon.cute.FailingAssertionException;
-
-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.
- */
-final class AnnotationProcessorWrapper implements Processor {
-
- private final Processor wrappedProcessor;
- private final Class extends Throwable> expectedThrownException;
- private Messager messager;
-
- private boolean firstRound = true;
- private boolean expectedExceptionWasThrown = false;
-
- private AnnotationProcessorWrapper(Processor processor) {
- this(processor, null);
- }
-
- private AnnotationProcessorWrapper(Processor processor, Class extends Throwable> expectedThrownException) {
- this.wrappedProcessor = processor;
- this.expectedThrownException = expectedThrownException;
- }
-
-
- @Override
- public Set
+ * }
+ * @CustomPassInAnnotation private static class PassInProcessorAndElementWithCustomAnnotation {
+ *
+ * }
+ * @Test public void test_UnitTest_successfulCompilation_withInitializedProcessorUnderTestAndPassInWithCustomAnnotation_build() {
+ *
+ * CuteFluentApiStarter
+ * .unitTest()
+ * .when()
+ * .passInProcessor(SimpleTestProcessor1.class)
+ * .andPassInElement().fromClass(PassInProcessorAndElementWithCustomAnnotation.class)
+ * .defineTestWithPassedInElement(SimpleTestProcessor1.class, PassInProcessorAndElementWithCustomAnnotation.class, CustomPassInAnnotation.class, new UnitTestForTestingAnnotationProcessors
+ * MatcherAssert.assertThat(typeElement, Matchers.notNullValue());
+ * MatcherAssert.assertThat(typeElement.getQualifiedName().toString(), Matchers.is(PassInProcessorAndElementWithCustomAnnotation.class.getCanonicalName()));
+ *
+ * }
+ * })
+ * .compilationShouldSucceed()
+ * .executeTest();
+ *
+ *
+ * }
+ */
+
+ @Test
+ public void test_UnitTest_failingCompilation_build() {
+
+ JavaFileObject testSource = Mockito.mock(JavaFileObject.class);
+ JavaFileObject expectedGeneratedSource = Mockito.mock(JavaFileObject.class);
+
+ Cute
+ .unitTest()
+ .when().unitTestWithoutPassIn(new UnitTestWithoutPassIn() {
+ @Override
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
+
+ processingEnvironment.getMessager().printMessage(Diagnostic.Kind.ERROR, "ERROR");
+ }
+ })
+ .thenExpectThat()
+ .compilationFails()
+ .andThat().compilerMessage().ofKindError().contains("ERROR")
+ .executeTest();
+
+
+ }
+
+/*-
+ private void assertCompilerMessages(Set
+ * The {@link javax.annotation.processing.ProcessingEnvironment} and an Element of type ELEMENT_TYPE will passed to the UnitTestProcessor.unitTest method.
+ *
+ * The {@link TestAnnotation} will be used to look up this Element during compilation.
+ *
+ * So please make sure that the {@link TestAnnotation} is used exactly once, when you are using a custom source files
+ *
+ * @param unitTest the processor to use
+ * @param