From 2460da2b91dcec0f44fc73d5d03dd3c1796e767f Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 10:18:35 +0100 Subject: [PATCH 1/6] Update for next development version --- coverage/pom.xml | 2 +- cute/pom.xml | 2 +- extension/api/pom.xml | 2 +- extension/junit4/pom.xml | 2 +- extension/junit5/pom.xml | 2 +- extension/modulesupport/pom.xml | 2 +- extension/plainjava/pom.xml | 2 +- extension/pom.xml | 2 +- extension/testng/pom.xml | 2 +- integration-test/java9/namedAutomaticModule/pom.xml | 2 +- integration-test/java9/pom.xml | 2 +- integration-test/java9/regularTestModule/pom.xml | 2 +- integration-test/java9/test/pom.xml | 2 +- integration-test/java9/unnamedAutomaticModule/pom.xml | 2 +- integration-test/junit4/pom.xml | 2 +- integration-test/junit5/pom.xml | 2 +- integration-test/pom.xml | 2 +- integration-test/testng/pom.xml | 2 +- legacy/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/coverage/pom.xml b/coverage/pom.xml index 449eb3c..04e7c99 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1-SNAPSHOT coverage diff --git a/cute/pom.xml b/cute/pom.xml index eb6ec0a..9c5431b 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1-SNAPSHOT cute diff --git a/extension/api/pom.xml b/extension/api/pom.xml index 78b4fc7..5c1e260 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-SNAPSHOT extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index 9f23335..20e81c3 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-SNAPSHOT extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index fe7c15a..45ad8d2 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-SNAPSHOT extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index a11fc84..afb3226 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-SNAPSHOT extension-modulesupport diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index 88dcbb4..8b2d98c 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-SNAPSHOT extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 95e2171..96669d6 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1-SNAPSHOT extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index 256d193..6ba710d 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-SNAPSHOT extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index 504c455..df2c5b6 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-SNAPSHOT integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index 14b3158..429908d 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-SNAPSHOT integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index 6c871aa..8cebc84 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-SNAPSHOT integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index 2343ef4..f1587bf 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-SNAPSHOT integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index f16e0d2..0c13e87 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-SNAPSHOT integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index b33606e..3614ca6 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-SNAPSHOT integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index de6029c..7536d7b 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-SNAPSHOT integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index c52cc33..6689309 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-SNAPSHOT integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 4e706fe..95e790c 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-SNAPSHOT integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index f6869c7..ff33e1a 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1-SNAPSHOT cute-legacy diff --git a/pom.xml b/pom.xml index fc63683..69c5ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.3.0 + 1.3.1-SNAPSHOT pom cute-parent From 8c7c4f0763f7d963d700eff76eaab5bab923dc5a Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 10:30:02 +0100 Subject: [PATCH 2/6] Fix mvn build warnings --- coverage/pom.xml | 5 ----- pom.xml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/coverage/pom.xml b/coverage/pom.xml index 04e7c99..497e2fd 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -28,11 +28,6 @@ extension-junit4 ${project.version} - - io.toolisticon.cute - extension-junit4 - ${project.version} - io.toolisticon.cute extension-testng diff --git a/pom.xml b/pom.xml index 69c5ae8..0d1f34a 100644 --- a/pom.xml +++ b/pom.xml @@ -56,11 +56,6 @@ 2018 - - 3.6.0 - - - https://github.com/toolisticon/cute/issues GitHub Issues From d5fc65f50d4ff55821129f5fc9dc590df9f0cd6b Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 12:02:34 +0100 Subject: [PATCH 3/6] Cleaned up CuteApi --- .../java/io/toolisticon/cute/CuteApi.java | 75 ++++++++++++------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/cute/src/main/java/io/toolisticon/cute/CuteApi.java b/cute/src/main/java/io/toolisticon/cute/CuteApi.java index 8f8ec12..1b93e2e 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,7 +848,7 @@ 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(); @@ -862,7 +860,8 @@ public interface BlackBoxTestOutcomeInterface { public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { /** - * Expect an Exception to be thrown + * Expect an Exception to be thrown. + * This usually makes sense * * @param exception The exception to check for * @return the next fluent interface @@ -896,7 +895,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 +1259,7 @@ public static class CompilationOutcome { /** * Checks if compilation was successful. + * * @return true if compilation was successful, otherwise false; */ public boolean compilationWasSuccessful() { @@ -1268,6 +1268,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 +1277,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 +1309,7 @@ public static class CompilerMessage { /** * Gets the kind of the compiler message. + * * @return the kind */ public Diagnostic.Kind getKind() { @@ -1315,6 +1319,7 @@ public Diagnostic.Kind getKind() { /** * Gets the compiler message string. * Uses Locale.English per default. + * * @return the message string */ public String getMessage() { @@ -1323,6 +1328,7 @@ public String getMessage() { /** * Gets the compiler message string. + * * @param locale the locale to use * @return the message string */ @@ -1332,6 +1338,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 +1347,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 +1356,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 +1380,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 +1397,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 +1414,7 @@ public Optional getGeneratedResourceFile(String path){ /** * Gets all Resource files (FileObjects). + * * @return All resource files */ public List getFileObjects() { @@ -1411,6 +1423,7 @@ public List getFileObjects() { /** * Gets all java related source or class files(JavaFileObjects). + * * @return All java source and class files */ @@ -1427,12 +1440,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 +1456,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 +1467,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 +1480,7 @@ public static class JavaFileObjectWrapper extends AbstractFileObjectWrapper{ /** * Gets the fully qualified class name. + * * @return the fully qualified class name */ public String getClassName() { @@ -1474,22 +1489,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 +1515,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 +1527,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 +1536,7 @@ public JavaFileManager.Location getLocation() { /** * The package name of file object + * * @return the package name */ public String getPackageName() { @@ -1527,6 +1545,7 @@ public String getPackageName() { /** * The name of the file relative to the package name, + * * @return name of the file */ public String getRelativeName() { @@ -1544,6 +1563,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 +1580,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; From 8220889069670bcad88e60fdef6204a3e7c094a1 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 12:25:54 +0100 Subject: [PATCH 4/6] [#84] allow checks for thrown exceptions for black box tests - even if they shouldn't be there in the first place --- .../java/io/toolisticon/cute/CuteApi.java | 17 ++++++---- .../java/io/toolisticon/cute/CuteTest.java | 11 ++++++ .../common/ExceptionThrowerAnnotation.java | 11 ++++++ .../common/ExceptionThrowerProcessor.java | 34 +++++++++++++++++++ .../ExceptionThrownUsecase.java | 8 +++++ 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerAnnotation.java create mode 100644 cute/src/test/java/io/toolisticon/cute/common/ExceptionThrowerProcessor.java create mode 100644 cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java diff --git a/cute/src/main/java/io/toolisticon/cute/CuteApi.java b/cute/src/main/java/io/toolisticon/cute/CuteApi.java index 1b93e2e..969e2f4 100644 --- a/cute/src/main/java/io/toolisticon/cute/CuteApi.java +++ b/cute/src/main/java/io/toolisticon/cute/CuteApi.java @@ -853,15 +853,12 @@ public interface BlackBoxTestOutcomeInterface { @FluentApiImplicitValue(id = "compilationSucceeded", value = "false") CompilerTestExpectAndThatInterface compilationFails(); - - } - - @FluentApiInterface(CompilerTestBB.class) - public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { - /** * Expect an Exception to be thrown. - * This usually makes sense + * 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 @@ -869,6 +866,12 @@ public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { CompilerTestExpectAndThatInterface exceptionIsThrown(@FluentApiBackingBeanMapping(value = "exceptionIsThrown") Class exception); + } + + @FluentApiInterface(CompilerTestBB.class) + public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { + + } diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index 549d581..aa2f652 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,14 @@ 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(); + } } 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 From be36383017709d3f87e09fdc92a8ddf4eca0dd42 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 12:32:30 +0100 Subject: [PATCH 5/6] [#84] allow checks for thrown exception - added failing assertion test --- .../test/java/io/toolisticon/cute/CuteTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index aa2f652..d32d395 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -1184,4 +1184,19 @@ public void blackBoxTest_checkForExpectedException(){ .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")); + } + } } From 0c2d20bd62e976538a7b8b8e570e2f29757da5a2 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Wed, 20 Mar 2024 12:34:26 +0100 Subject: [PATCH 6/6] Update versions for release --- coverage/pom.xml | 2 +- cute/pom.xml | 2 +- extension/api/pom.xml | 2 +- extension/junit4/pom.xml | 2 +- extension/junit5/pom.xml | 2 +- extension/modulesupport/pom.xml | 2 +- extension/plainjava/pom.xml | 2 +- extension/pom.xml | 2 +- extension/testng/pom.xml | 2 +- integration-test/java9/namedAutomaticModule/pom.xml | 2 +- integration-test/java9/pom.xml | 2 +- integration-test/java9/regularTestModule/pom.xml | 2 +- integration-test/java9/test/pom.xml | 2 +- integration-test/java9/unnamedAutomaticModule/pom.xml | 2 +- integration-test/junit4/pom.xml | 2 +- integration-test/junit5/pom.xml | 2 +- integration-test/pom.xml | 2 +- integration-test/testng/pom.xml | 2 +- legacy/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/coverage/pom.xml b/coverage/pom.xml index 497e2fd..823545e 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 coverage diff --git a/cute/pom.xml b/cute/pom.xml index 9c5431b..85197d2 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 cute diff --git a/extension/api/pom.xml b/extension/api/pom.xml index 5c1e260..3561804 100644 --- a/extension/api/pom.xml +++ b/extension/api/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index 20e81c3..05b6ade 100644 --- a/extension/junit4/pom.xml +++ b/extension/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index 45ad8d2..981f9d8 100644 --- a/extension/junit5/pom.xml +++ b/extension/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index afb3226..5e8138b 100644 --- a/extension/modulesupport/pom.xml +++ b/extension/modulesupport/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-modulesupport diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index 8b2d98c..d988026 100644 --- a/extension/plainjava/pom.xml +++ b/extension/plainjava/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 96669d6..1c614f0 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index 6ba710d..6092338 100644 --- a/extension/testng/pom.xml +++ b/extension/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1-SNAPSHOT + 1.3.1 extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index df2c5b6..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.1-SNAPSHOT + 1.3.1 integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index 429908d..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.1-SNAPSHOT + 1.3.1 integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index 8cebc84..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.1-SNAPSHOT + 1.3.1 integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index f1587bf..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.1-SNAPSHOT + 1.3.1 integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index 0c13e87..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.1-SNAPSHOT + 1.3.1 integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index 3614ca6..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.1-SNAPSHOT + 1.3.1 integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index 7536d7b..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.1-SNAPSHOT + 1.3.1 integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 6689309..35ab65d 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 95e790c..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.1-SNAPSHOT + 1.3.1 integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index ff33e1a..7951e85 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 cute-legacy diff --git a/pom.xml b/pom.xml index 0d1f34a..aeec794 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.3.1-SNAPSHOT + 1.3.1 pom cute-parent