Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Stamann committed Jan 26, 2024
2 parents d79ceaa + 85914ca commit 990985c
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 23 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,37 @@ public void yourUnitTestWithPassedInElementAndProcessor() {

}
```


### Testing generated and compiled classes
Testing of the generated code can either be done by providing an integration test project or by using Cute as part of the compilation test.
Unfortunately, testing generated code with Cute heavily relies on the Javas reflection api, since generated classes aren't available in your unit test code.
But it's working flawlessly if your generated classes are implementing precompiled interfaces:

````java
@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();
}
````

Consider to prefer integration tests over Cute if no precompiled interface is implemented by the generated classes.

# Projects using this toolkit library

- [Annotation processor toolkit](https://github.com/toolisticon/annotation-processor-toolkit) : Toolkit that allows you to build annotation processors in a more comfortable way
Expand Down
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>coverage</name>
Expand Down
2 changes: 1 addition & 1 deletion cute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>cute</name>
Expand Down
2 changes: 1 addition & 1 deletion cute/src/main/java/io/toolisticon/cute/CuteApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public interface CompilerTestExpectThatInterface {
* @param generatedClassesTest the test to execute
* @return the next interface
*/
CompilerTestExpectAndThatInterface compiledClassesTestsSucceeds(@FluentApiBackingBeanMapping(value = "generatedClassesTest", action = MappingAction.ADD) GeneratedClassesTest generatedClassesTest);
CompilerTestExpectAndThatInterface generatedClassesTestedSuccessfullyBy(@FluentApiBackingBeanMapping(value = "generatedClassesTest", action = MappingAction.ADD) GeneratedClassesTest generatedClassesTest);


/**
Expand Down
21 changes: 20 additions & 1 deletion cute/src/test/java/io/toolisticon/cute/CuteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public void blackBoxTest_justCompileCodeAndDoClassTest3() {
.whenCompiled()
.thenExpectThat()
.compilationSucceeds()
.andThat().compiledClassesTestsSucceeds(new GeneratedClassesTest() {
.andThat().generatedClassesTestedSuccessfullyBy(new GeneratedClassesTest() {
@Override
public void doTests(CuteClassLoader cuteClassLoader) throws Exception{
Class<?> clazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses");
Expand Down Expand Up @@ -1086,4 +1086,23 @@ public void doTests(Class<?> clazz, CuteClassLoader cuteClassLoader) throws Exce
.executeTest();
}


@Test()
public void blackBoxTest_justCompileCodeAndDoClassTestWithImplementedInterfaceAndRelationsBetweenClasses() {
Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/compiletests/withmultiplerelatedsourcefiles/JustOutput.java", "/compiletests/withmultiplerelatedsourcefiles/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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.toolisticon.cute;

public class JustOutput {

public static String getString() {
return "WHATS UP???";
}
}
Original file line number Diff line number Diff line change
@@ -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 JustOutput.getString();
}
}
2 changes: 1 addition & 1 deletion extension/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-api</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-junit4</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-junit5</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/modulesupport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-modulesupport</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/plainjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-plainjava</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion extension/testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>extension-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>extension-testng</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/java9/namedAutomaticModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-java9-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-java9-namedAutomaticModule</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/java9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-java9-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/java9/regularTestModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-java9-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-java9-regularModule</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/java9/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-java9-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-java9-test</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/java9/unnamedAutomaticModule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-java9-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-java9-unnamedAutomaticModule</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-junit4</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-junit5</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion integration-test/testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>integration-test-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>integration-test-testng</name>
Expand Down
2 changes: 1 addition & 1 deletion legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
</parent>

<name>cute-legacy</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.0.0_RC2</version>
<version>1.0.0</version>
<packaging>pom</packaging>

<name>cute-parent</name>
Expand Down

0 comments on commit 990985c

Please sign in to comment.