diff --git a/coverage/pom.xml b/coverage/pom.xml index 449eb3c..823545e 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 coverage @@ -28,11 +28,6 @@ extension-junit4 ${project.version} - - io.toolisticon.cute - extension-junit4 - ${project.version} - io.toolisticon.cute extension-testng diff --git a/cute/pom.xml b/cute/pom.xml index eb6ec0a..85197d2 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 cute diff --git a/cute/src/main/java/io/toolisticon/cute/CuteApi.java b/cute/src/main/java/io/toolisticon/cute/CuteApi.java index 8f8ec12..969e2f4 100644 --- a/cute/src/main/java/io/toolisticon/cute/CuteApi.java +++ b/cute/src/main/java/io/toolisticon/cute/CuteApi.java @@ -25,10 +25,8 @@ import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; -import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -262,7 +260,7 @@ public interface MyRootInterface { * This method can be used to start a black-box test (aka compile-test). * Black-box test are compiling some source files with an annotation processor and can check the compilation's outcome. * - * @return + * @return the next fluent interface */ @FluentApiImplicitValue(id = "testType", value = "BLACK_BOX") BlackBoxTestRootInterface blackBoxTest(); @@ -361,7 +359,7 @@ public interface BlackBoxTestSourceFilesInterface { */ // TODO: A validation if passed resource locations are correct would be good default BlackBoxTestFinalGivenInterface andSourceFiles(String... resources) { - return andSourceFiles(Arrays.stream(resources).map(e -> JavaFileObjectUtils.readFromResource(e)).toArray(JavaFileObject[]::new)); + return andSourceFiles(Arrays.stream(resources).map(JavaFileObjectUtils::readFromResource).toArray(JavaFileObject[]::new)); } /** @@ -397,7 +395,7 @@ public interface BlackBoxTestFinalGivenInterface { * @return the next fluent interface */ default BlackBoxTestFinalGivenInterface andSourceFiles(@NotNull String... resources) { - return andSourceFiles(Arrays.stream(resources).map(e -> JavaFileObjectUtils.readFromResource(e)).toArray(String[]::new)); + return andSourceFiles(Arrays.stream(resources).map(JavaFileObjectUtils::readFromResource).toArray(JavaFileObject[]::new)); } /** @@ -603,7 +601,7 @@ public interface PassInElementInterface { * @return the next fluent interface */ default PassInElementAndProcessorInterface fromSourceString(String className, String sourceString) { - return this.fromJavaFileObject(JavaFileObjectUtils.readFromString(className, sourceString)); + return this.fromJavaFileObject(JavaFileObjectUtils.readFromString(className, sourceString)); } /** @@ -617,7 +615,7 @@ default PassInElementAndProcessorInterface PassInElementAndProcessorInterface fromSourceFile(String resourceName) { - return this.fromJavaFileObject(JavaFileObjectUtils.readFromResource(resourceName)); + return this.fromJavaFileObject(JavaFileObjectUtils.readFromResource(resourceName)); } /** @@ -717,7 +715,7 @@ public interface PassInProcessorAndElementInterface UnitTestWhenWithPassedInElementAndProcessorInterface fromSourceString(String className, String sourceString) { - return this.fromJavaFileObject(JavaFileObjectUtils.readFromString(className, sourceString)); + return this.fromJavaFileObject(JavaFileObjectUtils.readFromString(className, sourceString)); } /** @@ -730,7 +728,7 @@ default UnitTestWhenWithPassedInElementAndProcess * @return the next fluent interface */ default UnitTestWhenWithPassedInElementAndProcessorInterface fromSourceFile(String resourceName) { - return this.fromJavaFileObject(JavaFileObjectUtils.readFromResource(resourceName)); + return this.fromJavaFileObject(JavaFileObjectUtils.readFromResource(resourceName)); } /** @@ -814,7 +812,7 @@ public interface UnitTestInterface { } @FluentApiInterface(CompilerTestBB.class) - public interface BlackBoxTestInterface { + public interface BlackBoxTestInterface { /** * Traverse to section to define checks @@ -850,19 +848,17 @@ public interface BlackBoxTestOutcomeInterface { * Expect the compilation to fail. * This means that either a (generated) source file couldn't be compiled ot that an error compiler message has been written. * - * @return the next fluent imnterface + * @return the next fluent interface */ @FluentApiImplicitValue(id = "compilationSucceeded", value = "false") CompilerTestExpectAndThatInterface compilationFails(); - - } - - @FluentApiInterface(CompilerTestBB.class) - public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { - /** - * Expect an Exception to be thrown + * Expect an Exception to be thrown. + * This usually makes sense for unit tests rather than black box tests. + * + * Please keep in mind that it's discouraged for processors to throw exceptions. + * Please catch them in your processor and convert them to compiler messages and maybe trigger a compiler error if needed. * * @param exception The exception to check for * @return the next fluent interface @@ -870,6 +866,12 @@ public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { CompilerTestExpectAndThatInterface exceptionIsThrown(@FluentApiBackingBeanMapping(value = "exceptionIsThrown") Class exception); + } + + @FluentApiInterface(CompilerTestBB.class) + public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { + + } @@ -896,7 +898,7 @@ public interface CompilerTestExpectThatInterface { /** * Sometimes it can become handy to even test the generated code. - * This method can used to do those tests. Compiled classes are provided via the {@link GeneratedClassesTest} interface. + * This method can be used to do those tests. Compiled classes are provided via the {@link GeneratedClassesTest} interface. * Be aware that the binary class names must be used to get classes ( '$' delimiter for inner types,...) * Test rely heavily on reflection api. * So please consider integration test projects for testing generated code if your code doesn't implement a precompiled interface. @@ -1260,6 +1262,7 @@ public static class CompilationOutcome { /** * Checks if compilation was successful. + * * @return true if compilation was successful, otherwise false; */ public boolean compilationWasSuccessful() { @@ -1268,6 +1271,7 @@ public boolean compilationWasSuccessful() { /** * Gets a list of all compiler messages. + * * @return A list of all compiler messages or an empty list if there are none. */ public List getCompilerMessages() { @@ -1276,14 +1280,16 @@ public List getCompilerMessages() { /** * Provides access to the FileManager. + * * @return the FileManager */ - public FileManager getFileManager () { + public FileManager getFileManager() { return new FileManager(compilationResult.getCompileTestFileManager()); } /** * Provides access to the ClassLoader of generated Classes. + * * @return the ClassLoader for generated Classes */ public CuteClassLoader getClassLoader() { @@ -1306,6 +1312,7 @@ public static class CompilerMessage { /** * Gets the kind of the compiler message. + * * @return the kind */ public Diagnostic.Kind getKind() { @@ -1315,6 +1322,7 @@ public Diagnostic.Kind getKind() { /** * Gets the compiler message string. * Uses Locale.English per default. + * * @return the message string */ public String getMessage() { @@ -1323,6 +1331,7 @@ public String getMessage() { /** * Gets the compiler message string. + * * @param locale the locale to use * @return the message string */ @@ -1332,6 +1341,7 @@ public String getMessage(Locale locale) { /** * Allows checking for column number the compiler message is related to. + * * @return the column number of the compiler message */ public long getColumnNumber() { @@ -1340,6 +1350,7 @@ public long getColumnNumber() { /** * Allows checking for line number the compiler message is related to. + * * @return the line number of the compiler message. */ public long getLineNumber() { @@ -1348,10 +1359,11 @@ public long getLineNumber() { /** * Gets the source file name the compiler message is related with. + * * @return The source file name */ public String getSource() { - return ((FileObject) diagnostic.getSource()).getName(); + return diagnostic.getSource().getName(); } @@ -1371,10 +1383,11 @@ public static class FileManager { /** * Gets specific generated source file by className. + * * @param className the fully qualified class name to look for * @return An Optional containing the source file or just an empty Optional if the source file can't be found. */ - public Optional getGeneratedSourceFile(String className){ + public Optional getGeneratedSourceFile(String className) { for (JavaFileObjectWrapper javaFileObjectWrapper : getJavaFileObjects().stream().filter(e -> (e.getKind() == JavaFileObject.Kind.SOURCE)).collect(Collectors.toList())) { if (className.equals(javaFileObjectWrapper.getClassName())) { @@ -1387,10 +1400,11 @@ public Optional getGeneratedSourceFile(String className){ /** * Gets specific generated resource file by path. + * * @param path the path of the resource file. * @return An Optional containing the resource file or just an empty Optional if the resource file can't be found. */ - public Optional getGeneratedResourceFile(String path){ + public Optional getGeneratedResourceFile(String path) { for (FileObjectWrapper fileObjectWrapper : getFileObjects()) { if (path.equals(fileObjectWrapper.getName())) { @@ -1403,6 +1417,7 @@ public Optional getGeneratedResourceFile(String path){ /** * Gets all Resource files (FileObjects). + * * @return All resource files */ public List getFileObjects() { @@ -1411,6 +1426,7 @@ public List getFileObjects() { /** * Gets all java related source or class files(JavaFileObjects). + * * @return All java source and class files */ @@ -1427,12 +1443,13 @@ public AbstractFileObjectWrapper(CompileTestFileManager.AbstractInMemoryOutputFi this.fileObject = fileObject; } - public String getName(){ + public String getName() { return fileObject.getName(); } /** * Gets the content as a byte array. + * * @return the content as a byte array */ public byte[] getContentAsByteArray() { @@ -1442,9 +1459,10 @@ public byte[] getContentAsByteArray() { /** * Gets the content as a string. * Encoding errors will be ignored + * * @return the content as a string */ - public String getContent(){ + public String getContent() { return fileObject.getCharContent(true).toString(); } @@ -1452,11 +1470,10 @@ public String getContent(){ } - /** * Provides read only access to JavaFileObjects. */ - public static class JavaFileObjectWrapper extends AbstractFileObjectWrapper{ + public static class JavaFileObjectWrapper extends AbstractFileObjectWrapper { final CompileTestFileManager.InMemoryOutputJavaFileObject javaFileObject; JavaFileObjectWrapper(CompileTestFileManager.InMemoryOutputJavaFileObject javaFileObject) { @@ -1466,6 +1483,7 @@ public static class JavaFileObjectWrapper extends AbstractFileObjectWrapper{ /** * Gets the fully qualified class name. + * * @return the fully qualified class name */ public String getClassName() { @@ -1474,22 +1492,25 @@ public String getClassName() { /** * Gets the kind of the JavaFileObject. + * * @return the kind of the JavaFileObject */ - public JavaFileObject.Kind getKind(){ + public JavaFileObject.Kind getKind() { return javaFileObject.getKind(); } /** * Gets the nesting kind of the JavaFileObject. - * @return the nesting kind of the JavaFileObject. + * + * @return the nesting kind of the JavaFileObject. */ - public NestingKind getNestingKind(){ + public NestingKind getNestingKind() { return javaFileObject.getNestingKind(); } /** * Gets the location to which the JavaFileObject was written to. + * * @return the location */ public JavaFileManager.Location getLocation() { @@ -1497,11 +1518,9 @@ public JavaFileManager.Location getLocation() { } - - } - public static class FileObjectWrapper extends AbstractFileObjectWrapper{ + public static class FileObjectWrapper extends AbstractFileObjectWrapper { final CompileTestFileManager.InMemoryOutputFileObject fileObject; public FileObjectWrapper(CompileTestFileManager.InMemoryOutputFileObject fileObject) { @@ -1511,6 +1530,7 @@ public FileObjectWrapper(CompileTestFileManager.InMemoryOutputFileObject fileObj /** * Gets the location to which the JavaFileObject was written to. + * * @return the location */ public JavaFileManager.Location getLocation() { @@ -1519,6 +1539,7 @@ public JavaFileManager.Location getLocation() { /** * The package name of file object + * * @return the package name */ public String getPackageName() { @@ -1527,6 +1548,7 @@ public String getPackageName() { /** * The name of the file relative to the package name, + * * @return name of the file */ public String getRelativeName() { @@ -1544,6 +1566,7 @@ public interface DoCustomAssertions { /** * This method can be used to execute custom assertions. + * * @param customAssertion the custom assertions to do (use lambda!) */ void executeCustomAssertions(CustomAssertion customAssertion); @@ -1560,6 +1583,7 @@ public interface DoCustomAssertions { public interface CustomAssertion { /** * The method used to provide custom assertions. Usually this will be used via lambda. + * * @param compilationOutcome the compiler outcome. */ void executeCustomAssertions(CompilationOutcome compilationOutcome) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException; diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index 549d581..d32d395 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -1,5 +1,6 @@ package io.toolisticon.cute; +import io.toolisticon.cute.common.ExceptionThrowerProcessor; import io.toolisticon.cute.common.SimpleTestProcessor1; import io.toolisticon.cute.common.SimpleTestProcessor1Interface; import io.toolisticon.cute.testcases.SimpleTestInterface; @@ -1173,4 +1174,29 @@ public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exce }) .executeTest(); } + + @Test + public void blackBoxTest_checkForExpectedException(){ + Cute.blackBoxTest().given().processor(ExceptionThrowerProcessor.class) + .andSourceFiles("/compiletests/exceptionthrown/ExceptionThrownUsecase.java") + .whenCompiled() + .thenExpectThat() + .exceptionIsThrown(IllegalStateException.class) + .executeTest(); + } + + @Test + public void blackBoxTest_checkForExpectedException_failure(){ + try { + Cute.blackBoxTest().given().processor(ExceptionThrowerProcessor.class) + .andSourceFiles("/compiletests/exceptionthrown/ExceptionThrownUsecase.java") + .whenCompiled() + .thenExpectThat() + .exceptionIsThrown(IllegalArgumentException.class) + .executeTest(); + throw new AssertionError("FAIL"); + } catch (AssertionError e) { + MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("WHOOP")); + } + } } diff --git a/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerAnnotation.java b/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerAnnotation.java new file mode 100644 index 0000000..de1d8d0 --- /dev/null +++ b/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerAnnotation.java @@ -0,0 +1,11 @@ +package io.toolisticon.cute.common; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExceptionThrowerAnnotation { +} diff --git a/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerProcessor.java b/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerProcessor.java new file mode 100644 index 0000000..bc9fc2b --- /dev/null +++ b/cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerProcessor.java @@ -0,0 +1,34 @@ +package io.toolisticon.cute.common; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class ExceptionThrowerProcessor extends AbstractProcessor { + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + + throw new IllegalStateException("WHOOPS!!!"); + + } + + + @Override + public Set getSupportedAnnotationTypes() { + + return new HashSet(Arrays.asList(ExceptionThrowerAnnotation.class.getCanonicalName())); + + } + + public ProcessingEnvironment getProcessingEnvironment() { + return this.processingEnv; + } +} \ No newline at end of file diff --git a/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java b/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java new file mode 100644 index 0000000..9165381 --- /dev/null +++ b/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java @@ -0,0 +1,8 @@ +package io.toolisticon.cute.testhelper.compiletest; + +import io.toolisticon.cute.common.ExceptionThrowerAnnotation; + +@ExceptionThrowerAnnotation +public class ExceptionThrownUsecase { + +} \ No newline at end of file diff --git a/extension/api/pom.xml b/extension/api/pom.xml index 78b4fc7..3561804 100644 --- a/extension/api/pom.xml +++ b/extension/api/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index 9f23335..05b6ade 100644 --- a/extension/junit4/pom.xml +++ b/extension/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index fe7c15a..981f9d8 100644 --- a/extension/junit5/pom.xml +++ b/extension/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index a11fc84..5e8138b 100644 --- a/extension/modulesupport/pom.xml +++ b/extension/modulesupport/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-modulesupport diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index 88dcbb4..d988026 100644 --- a/extension/plainjava/pom.xml +++ b/extension/plainjava/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 95e2171..1c614f0 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index 256d193..6092338 100644 --- a/extension/testng/pom.xml +++ b/extension/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.0 + 1.3.1 extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index 504c455..df8710e 100644 --- a/integration-test/java9/namedAutomaticModule/pom.xml +++ b/integration-test/java9/namedAutomaticModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.0 + 1.3.1 integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index 14b3158..434e4c7 100644 --- a/integration-test/java9/pom.xml +++ b/integration-test/java9/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.0 + 1.3.1 integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index 6c871aa..c0e8200 100644 --- a/integration-test/java9/regularTestModule/pom.xml +++ b/integration-test/java9/regularTestModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.0 + 1.3.1 integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index 2343ef4..833ce6d 100644 --- a/integration-test/java9/test/pom.xml +++ b/integration-test/java9/test/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.0 + 1.3.1 integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index f16e0d2..f9f6ab8 100644 --- a/integration-test/java9/unnamedAutomaticModule/pom.xml +++ b/integration-test/java9/unnamedAutomaticModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.0 + 1.3.1 integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index b33606e..3275cb7 100644 --- a/integration-test/junit4/pom.xml +++ b/integration-test/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.0 + 1.3.1 integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index de6029c..b16d709 100644 --- a/integration-test/junit5/pom.xml +++ b/integration-test/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.0 + 1.3.1 integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index c52cc33..35ab65d 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 4e706fe..159803e 100644 --- a/integration-test/testng/pom.xml +++ b/integration-test/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute integration-test-parent - 1.3.0 + 1.3.1 integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index f6869c7..7951e85 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 cute-legacy diff --git a/pom.xml b/pom.xml index fc63683..aeec794 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1 pom cute-parent @@ -56,11 +56,6 @@ 2018 - - 3.6.0 - - - https://github.com/toolisticon/cute/issues GitHub Issues