From 222ab7828f49b3adc7b08135a1de18a623c13937 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Thu, 25 Jan 2024 11:09:20 +0100 Subject: [PATCH 1/4] 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 bf4e4b1..c361684 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT coverage diff --git a/cute/pom.xml b/cute/pom.xml index 2e80e2c..78186e5 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT cute diff --git a/extension/api/pom.xml b/extension/api/pom.xml index fd11b05..6597e79 100644 --- a/extension/api/pom.xml +++ b/extension/api/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index a244193..aed95d0 100644 --- a/extension/junit4/pom.xml +++ b/extension/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index cba2bdb..54a499a 100644 --- a/extension/junit5/pom.xml +++ b/extension/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index 32561b6..e5642c4 100644 --- a/extension/modulesupport/pom.xml +++ b/extension/modulesupport/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-modulesupport diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index 51cdd6b..e7c89ed 100644 --- a/extension/plainjava/pom.xml +++ b/extension/plainjava/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 435cafa..58cb287 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index 39d8b3b..a68bbf5 100644 --- a/extension/testng/pom.xml +++ b/extension/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index 2d3c80d..c1b55a1 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.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index aaf3609..e90219a 100644 --- a/integration-test/java9/pom.xml +++ b/integration-test/java9/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index b43dbe2..01741a0 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.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index c43b601..badf038 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.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index b8f0858..80c2e71 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.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index 5c75e30..debfd18 100644 --- a/integration-test/junit4/pom.xml +++ b/integration-test/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index 827f037..06fb180 100644 --- a/integration-test/junit5/pom.xml +++ b/integration-test/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index e54323e..e036e7e 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 822617a..51e1a34 100644 --- a/integration-test/testng/pom.xml +++ b/integration-test/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index 5ef0937..51165a5 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT cute-legacy diff --git a/pom.xml b/pom.xml index 50ee5b9..accc29c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC1 + 1.0.0_RC2-SNAPSHOT pom cute-parent From fa41fee85463ba80cd6960e362d904de3e3420b0 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 26 Jan 2024 13:27:04 +0100 Subject: [PATCH 2/4] Enhanced API to directly test generated classes. This can be quite useful especially if generated code implements a precompiled interface, since tests will be heavily based on reflection api. --- .../java/io/toolisticon/cute/CompileTest.java | 27 ++++++ .../java/io/toolisticon/cute/Constants.java | 2 + .../java/io/toolisticon/cute/CuteApi.java | 37 ++++++- .../io/toolisticon/cute/CuteClassLoader.java | 7 ++ .../toolisticon/cute/CuteClassLoaderImpl.java | 86 ++++++++++++++++ .../cute/GeneratedClassesTest.java | 7 ++ .../GeneratedClassesTestForSpecificClass.java | 7 ++ .../java/io/toolisticon/cute/CuteTest.java | 97 +++++++++++++++++++ .../cute/testcases/SimpleTestInterface.java | 5 + .../TestClassWithImplementedInterface.java | 16 +++ .../resources/TestClassWithInnerClasses.java | 25 +++++ 11 files changed, 313 insertions(+), 3 deletions(-) create mode 100644 cute/src/main/java/io/toolisticon/cute/CuteClassLoader.java create mode 100644 cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java create mode 100644 cute/src/main/java/io/toolisticon/cute/GeneratedClassesTest.java create mode 100644 cute/src/main/java/io/toolisticon/cute/GeneratedClassesTestForSpecificClass.java create mode 100644 cute/src/test/java/io/toolisticon/cute/testcases/SimpleTestInterface.java create mode 100644 cute/src/test/resources/TestClassWithImplementedInterface.java create mode 100644 cute/src/test/resources/TestClassWithInnerClasses.java diff --git a/cute/src/main/java/io/toolisticon/cute/CompileTest.java b/cute/src/main/java/io/toolisticon/cute/CompileTest.java index 8044c88..7806ab1 100644 --- a/cute/src/main/java/io/toolisticon/cute/CompileTest.java +++ b/cute/src/main/java/io/toolisticon/cute/CompileTest.java @@ -81,7 +81,20 @@ public void executeTest() { // Check messages checkMessages(compilationResult.getDiagnostics()); + // Check compiled classes + for (GeneratedClassesTest generatedClassesTest : this.compileTestConfiguration.getGeneratedClassesTest()) { + CuteClassLoader cuteClassLoader = new CuteClassLoaderImpl(compilationResult.getCompileTestFileManager()); + + try { + generatedClassesTest.doTests(cuteClassLoader); + } catch (AssertionError e) { + throw e; + } catch (Exception e) { + throw new FailingAssertionException(Constants.Messages.MESSAGE_GOT_UNEXPECTED_EXCEPTION_DURING_CLASS_TEST_ERROR.produceMessage(generatedClassesTest, e.getMessage())); + } + } + // Check generated JavaFileObjects for (CuteApi.GeneratedJavaFileObjectCheckBB generatedJavaFileObjectCheck : this.compileTestConfiguration.javaFileObjectChecks()) { if (CuteApi.FileObjectCheckType.EXISTS.equals(generatedJavaFileObjectCheck.getCheckType())) { if (!compilationResult.getCompileTestFileManager().existsExpectedJavaFileObject(generatedJavaFileObjectCheck.getLocation(), generatedJavaFileObjectCheck.getClassName(), generatedJavaFileObjectCheck.getKind())) { @@ -109,6 +122,20 @@ public void executeTest() { } + // Check with test + if (generatedJavaFileObjectCheck.getGeneratedClassesTest() != null) { + CuteClassLoader cuteClassLoader = new CuteClassLoaderImpl(compilationResult.getCompileTestFileManager()); + + try { + generatedJavaFileObjectCheck.getGeneratedClassesTest().doTests(cuteClassLoader.getClass(generatedJavaFileObjectCheck.getClassName()), cuteClassLoader); + } catch (AssertionError e) { + throw e; + } catch (Exception e) { + throw new FailingAssertionException(Constants.Messages.MESSAGE_GOT_UNEXPECTED_EXCEPTION_DURING_CLASS_TEST_ERROR.produceMessage(getJavaFileObjectInfoString(generatedJavaFileObjectCheck), e.getMessage())); + } + } + + } catch (IOException e) { // ignore } diff --git a/cute/src/main/java/io/toolisticon/cute/Constants.java b/cute/src/main/java/io/toolisticon/cute/Constants.java index adbaddd..92630ce 100644 --- a/cute/src/main/java/io/toolisticon/cute/Constants.java +++ b/cute/src/main/java/io/toolisticon/cute/Constants.java @@ -69,6 +69,8 @@ public String getMessagePattern(){ public final static Message MESSAGE_TECHNICAL_ERROR = new Message("TECHNICAL ERROR : %s"); + public final static Message MESSAGE_GOT_UNEXPECTED_EXCEPTION_DURING_CLASS_TEST_ERROR = new Message("Unexpected Exception happened during test of generated class %s : %s"); + // IllegalArgumentException Messages public final static Message IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL = new Message("Passed %s must not be null"); diff --git a/cute/src/main/java/io/toolisticon/cute/CuteApi.java b/cute/src/main/java/io/toolisticon/cute/CuteApi.java index f02bb3a..930185e 100644 --- a/cute/src/main/java/io/toolisticon/cute/CuteApi.java +++ b/cute/src/main/java/io/toolisticon/cute/CuteApi.java @@ -73,6 +73,9 @@ public interface CompilerTestBB { @FluentApiBackingBeanField("fileObjectChecks") List fileObjectChecks(); + @FluentApiBackingBeanField("generatedClassesTest") + List getGeneratedClassesTest(); + default long countErrorMessageChecks() { long count = 0; @@ -195,6 +198,9 @@ public interface GeneratedJavaFileObjectCheckBB { @FluentApiBackingBeanField("generatedFileObjectMatcher") GeneratedFileObjectMatcher getGeneratedFileObjectMatcher(); + + @FluentApiBackingBeanField("generatedClassesTest") + GeneratedClassesTestForSpecificClass getGeneratedClassesTest(); } @FluentApiBackingBean @@ -819,11 +825,10 @@ public interface BlackBoxTestOutcomeInterface { CompilerTestExpectAndThatInterface compilationFails(); - } @FluentApiInterface(CompilerTestBB.class) - public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface{ + public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface { /** * Expect an Exception to be thrown @@ -837,7 +842,6 @@ public interface UnitTestOutcomeInterface extends BlackBoxTestOutcomeInterface{ } - @FluentApiInterface(CompilerTestBB.class) public interface CompilerTestExpectAndThatInterface { @@ -859,6 +863,18 @@ public interface CompilerTestExpectAndThatInterface { @FluentApiInterface(CompilerTestBB.class) 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. + * 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. + * @param generatedClassesTest the test to execute + * @return the next interface + */ + CompilerTestExpectAndThatInterface compiledClassesTestsSucceeds(@FluentApiBackingBeanMapping(value = "generatedClassesTest", action = MappingAction.ADD) GeneratedClassesTest generatedClassesTest); + + /** * Adds check that generated class exists or doesn't exist. * @@ -1067,6 +1083,21 @@ default CompilerTestExpectAndThatInterface matches(ExpectedFileObjectMatcherKind @FluentApiParentBackingBeanMapping(value = "javaFileObjectChecks", action = MappingAction.ADD) CompilerTestExpectAndThatInterface matches(@FluentApiBackingBeanMapping(value = "generatedFileObjectMatcher") GeneratedFileObjectMatcher generatedJavaFileObjectCheck); + + /** + * 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. + * 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. + * @param generatedClassesTest the test to execute + * @return the next interface + */ + @FluentApiImplicitValue(id = "checkType", value = "EXISTS") + @FluentApiParentBackingBeanMapping(value = "javaFileObjectChecks", action = MappingAction.ADD) + CompilerTestExpectAndThatInterface testedSuccessfullyBy(@FluentApiBackingBeanMapping(value = "generatedClassesTest") GeneratedClassesTestForSpecificClass generatedClassesTest); + + } @FluentApiInterface(GeneratedFileObjectCheckBB.class) diff --git a/cute/src/main/java/io/toolisticon/cute/CuteClassLoader.java b/cute/src/main/java/io/toolisticon/cute/CuteClassLoader.java new file mode 100644 index 0000000..9c94b04 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/cute/CuteClassLoader.java @@ -0,0 +1,7 @@ +package io.toolisticon.cute; + +public interface CuteClassLoader { + + Class getClass(String binaryClassName) throws ClassNotFoundException; + +} diff --git a/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java b/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java new file mode 100644 index 0000000..3078b74 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java @@ -0,0 +1,86 @@ +package io.toolisticon.cute; + +import javax.tools.JavaFileObject; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +class CuteClassLoaderImpl extends ClassLoader implements CuteClassLoader { + + final CompileTestFileManager compileTestFileManager; + + final Map> classMap = new HashMap<>(); + + public CuteClassLoaderImpl(CompileTestFileManager compileTestFileManager) { + this.compileTestFileManager = compileTestFileManager; + + // get classes + List javaFileObjectList = compileTestFileManager.getGeneratedJavaFileObjects().stream() + .filter(e -> e.getKind() == JavaFileObject.Kind.CLASS) + .collect(Collectors.toList()); + + for (JavaFileObject javaFileObject : javaFileObjectList) { + try { + byte[] byteArray = readAllBytes(javaFileObject.openInputStream()); + String className = convertJavaFileObjectNameToBinaryClassName(javaFileObject); + classMap.put(className, defineClass(className, byteArray, 0, byteArray.length)); + } catch (IOException e) { + // Ignore for the moment + } + } + + } + + private static byte[] readAllBytes(InputStream inputStream) throws IOException { + final int bufLen = 4 * 0x400; // 4KB + byte[] buf = new byte[bufLen]; + int readLen; + IOException exception = null; + + try { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + while ((readLen = inputStream.read(buf, 0, bufLen)) != -1) + outputStream.write(buf, 0, readLen); + + return outputStream.toByteArray(); + } + } catch (IOException e) { + exception = e; + throw e; + } finally { + if (exception == null) inputStream.close(); + else try { + inputStream.close(); + } catch (IOException e) { + exception.addSuppressed(e); + } + } + } + + static String convertJavaFileObjectNameToBinaryClassName(JavaFileObject javaFileObject) { + Pattern pattern = Pattern.compile("^[/](.*)[.]class$"); + Matcher matcher = pattern.matcher(javaFileObject.getName()); + if (matcher.matches()) { + return matcher.group(1).replaceAll("[/]","."); + } + throw new IllegalStateException("Got invalid name : " + javaFileObject.getName()); + } + + @Override + public Class getClass(String binaryClassName) throws ClassNotFoundException { + + + Class clazz = (Class) this.classMap.get(binaryClassName); + + if(clazz == null){ + throw new ClassNotFoundException(binaryClassName); + } + return clazz; + } +} diff --git a/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTest.java b/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTest.java new file mode 100644 index 0000000..a855cd1 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTest.java @@ -0,0 +1,7 @@ +package io.toolisticon.cute; + +public interface GeneratedClassesTest { + + void doTests(CuteClassLoader cuteClassLoader) throws Exception; + +} diff --git a/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTestForSpecificClass.java b/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTestForSpecificClass.java new file mode 100644 index 0000000..4df6682 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/cute/GeneratedClassesTestForSpecificClass.java @@ -0,0 +1,7 @@ +package io.toolisticon.cute; + +public interface GeneratedClassesTestForSpecificClass { + + void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception; + +} diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index df48990..1921be7 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -1,6 +1,7 @@ package io.toolisticon.cute; import io.toolisticon.cute.common.SimpleTestProcessor1; +import io.toolisticon.cute.testcases.SimpleTestInterface; import io.toolisticon.fluapigen.validation.api.ValidatorException; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -969,5 +970,101 @@ public void blackBoxTest_executeTest_WithoutChecks_FailedCompilation() { throw new AssertionError("Should have got Assertion error that compilation was expected to be successful but failed"); } + @Test() + public void blackBoxTest_justCompileCodeAndDoClassTests() { + Cute.blackBoxTest().given().processors() + .andSourceFiles("/TestClass.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.TestClass").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { + @Override + public void doTests(Class clazz,CuteClassLoader cuteClassLoader) throws Exception{ + MatcherAssert.assertThat(clazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClass")); + + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); + } + }) + .executeTest(); + } + + @Test() + public void blackBoxTest_justCompileCodeAndDoClassTests2() { + Cute.blackBoxTest().given().processors() + .andSourceFiles("/TestClassWithInnerClasses.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { + @Override + public void doTests(Classclazz, CuteClassLoader cuteClassLoader) throws Exception{ + MatcherAssert.assertThat(clazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); + + Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); + MatcherAssert.assertThat(innerClazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); + + Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); + MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); + + Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); + MatcherAssert.assertThat(innerInterface.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); + + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); + + } + }) + .executeTest(); + } + + @Test() + public void blackBoxTest_justCompileCodeAndDoClassTest3() { + Cute.blackBoxTest().given().processors() + .andSourceFiles("/TestClassWithInnerClasses.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat().compiledClassesTestsSucceeds(new GeneratedClassesTest() { + @Override + public void doTests(CuteClassLoader cuteClassLoader) throws Exception{ + Class clazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses"); + MatcherAssert.assertThat(clazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); + + Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); + MatcherAssert.assertThat(innerClazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); + + Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); + MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); + + Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); + MatcherAssert.assertThat(innerInterface.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); + + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); + + } + }) + .executeTest(); + } + + @Test() + public void blackBoxTest_justCompileCodeAndDoClassTestWithImplementedInterface() { + Cute.blackBoxTest().given().noProcessors() + .andSourceFiles("/TestClassWithImplementedInterface.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.TestClassWithImplementedInterface").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { + @Override + public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception{ + + SimpleTestInterface unit = (SimpleTestInterface) clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(unit.saySomething(), Matchers.is("WHATS UP?")); + + } + }) + .executeTest(); + } } diff --git a/cute/src/test/java/io/toolisticon/cute/testcases/SimpleTestInterface.java b/cute/src/test/java/io/toolisticon/cute/testcases/SimpleTestInterface.java new file mode 100644 index 0000000..e525852 --- /dev/null +++ b/cute/src/test/java/io/toolisticon/cute/testcases/SimpleTestInterface.java @@ -0,0 +1,5 @@ +package io.toolisticon.cute.testcases; + +public interface SimpleTestInterface { + String saySomething(); +} diff --git a/cute/src/test/resources/TestClassWithImplementedInterface.java b/cute/src/test/resources/TestClassWithImplementedInterface.java new file mode 100644 index 0000000..60f8fdc --- /dev/null +++ b/cute/src/test/resources/TestClassWithImplementedInterface.java @@ -0,0 +1,16 @@ +package io.toolisticon.cute; + +import io.toolisticon.cute.TestAnnotation; +import io.toolisticon.cute.testcases.SimpleTestInterface; + +/** + * Test class for annotation processor tools. + */ +@TestAnnotation +public class TestClassWithImplementedInterface implements SimpleTestInterface { + + @Override + public String saySomething() { + return "WHATS UP?"; + } +} diff --git a/cute/src/test/resources/TestClassWithInnerClasses.java b/cute/src/test/resources/TestClassWithInnerClasses.java new file mode 100644 index 0000000..86004f0 --- /dev/null +++ b/cute/src/test/resources/TestClassWithInnerClasses.java @@ -0,0 +1,25 @@ +package io.toolisticon.cute; + +import io.toolisticon.cute.TestAnnotation; + +/** + * Test class for annotation processor tools. + */ +@TestAnnotation +public class TestClassWithInnerClasses { + + public class InnerClass { + + } + + public static class StaticInnerClass { + + + } + + public interface InnerInterface { + + } + + +} From 167ff355f7a7d06aa0b77fcbfb7caf6deb438186 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 26 Jan 2024 13:59:43 +0100 Subject: [PATCH 3/4] Added unit test --- .../java/io/toolisticon/cute/CuteTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index 1921be7..90d8dea 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -1048,6 +1048,25 @@ public void doTests(CuteClassLoader cuteClassLoader) throws Exception{ .executeTest(); } + @Test() + public void blackBoxTest_justCompileCodeAndDoClassTest4() { + Cute.blackBoxTest().given().processors() + .andSourceFiles("/TestClassWithInnerClasses.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { + @Override + public void doTests( Class innerClazz, CuteClassLoader cuteClassLoader) throws Exception{ + + MatcherAssert.assertThat(innerClazz.getCanonicalName(),Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); + + + } + }) + .executeTest(); + } + @Test() public void blackBoxTest_justCompileCodeAndDoClassTestWithImplementedInterface() { Cute.blackBoxTest().given().noProcessors() From a0146f4ceb4a763aadc963f384715a3a6705e835 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 26 Jan 2024 14:01:25 +0100 Subject: [PATCH 4/4] 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 c361684..7c5b454 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 coverage diff --git a/cute/pom.xml b/cute/pom.xml index 78186e5..e69b409 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 cute diff --git a/extension/api/pom.xml b/extension/api/pom.xml index 6597e79..ebb45d6 100644 --- a/extension/api/pom.xml +++ b/extension/api/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index aed95d0..78c6357 100644 --- a/extension/junit4/pom.xml +++ b/extension/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index 54a499a..1a108e1 100644 --- a/extension/junit5/pom.xml +++ b/extension/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index e5642c4..906eddd 100644 --- a/extension/modulesupport/pom.xml +++ b/extension/modulesupport/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-modulesupport diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index e7c89ed..3c86c4a 100644 --- a/extension/plainjava/pom.xml +++ b/extension/plainjava/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 58cb287..b448306 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index a68bbf5..defcdd2 100644 --- a/extension/testng/pom.xml +++ b/extension/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index c1b55a1..13a8cf7 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.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index e90219a..e619b5a 100644 --- a/integration-test/java9/pom.xml +++ b/integration-test/java9/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index 01741a0..2211513 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.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index badf038..48460b7 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.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index 80c2e71..e50ca87 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.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index debfd18..c4aeeb9 100644 --- a/integration-test/junit4/pom.xml +++ b/integration-test/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index 06fb180..4910147 100644 --- a/integration-test/junit5/pom.xml +++ b/integration-test/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index e036e7e..dec1d12 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 51e1a34..40cfcf4 100644 --- a/integration-test/testng/pom.xml +++ b/integration-test/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute integration-test-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index 51165a5..bebbfeb 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 cute-legacy diff --git a/pom.xml b/pom.xml index accc29c..cd7f7ad 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.0.0_RC2-SNAPSHOT + 1.0.0_RC2 pom cute-parent