Skip to content

Commit

Permalink
[#91] Automaticylly add cute module for unittests including a module-…
Browse files Browse the repository at this point in the history
…info.java
  • Loading branch information
Tobias Stamann committed Apr 10, 2024
1 parent 689d27f commit 545629f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cute/src/main/java/io/toolisticon/cute/CompileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -261,7 +262,13 @@ public static CompilationResult compile(CuteApi.CompilerTestBB compileTestConfig
if (!Java9SupportCheck.UNSUPPORTED_JAVA_VERSION) {
ModuleSupportSpi moduleService = ModuleSupportSpiServiceLocator.locate();
if (moduleService != null) {
moduleService.applyModulePath(stdJavaFileManager, compilationTask, compileTestConfiguration.modules());

Set<String> modulePath = new HashSet<>(compileTestConfiguration.modules());
if (compileTestConfiguration.testType() == CuteApi.TestType.UNIT && hasModuleInfoSourceFile(compileTestConfiguration)) {
modulePath.add("cute");
}

moduleService.applyModulePath(stdJavaFileManager, compilationTask, modulePath);
}
}

Expand All @@ -271,6 +278,10 @@ public static CompilationResult compile(CuteApi.CompilerTestBB compileTestConfig

}

private static boolean hasModuleInfoSourceFile(CuteApi.CompilerTestBB compileTestConfiguration){
return compileTestConfiguration.sourceFiles().stream().filter(sourceFile -> sourceFile.getName().endsWith("/module-info.java")).count() > 0;
}

/**
* Allows checking if annotation processor has been applied during the compilation test.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import io.toolisticon.cute.integrationtest.javanine.namednonmodule.NamedAutomaticModuleTestClass;
import org.junit.Test;

import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;

/**
* Java 9+ related integration tests.
* Addresses mainly the jigsaw module system.
Expand Down Expand Up @@ -80,5 +83,18 @@ public void testBindUnnamedAutomaticJavaModule() {

}

@Test
public void testUnitTestWithModules() {
Cute.unitTest().given().useSourceFilesFromFolders("/testcases/unitTest")
.when()
.passInElement().<TypeElement>fromGivenSourceFiles()
.intoUnitTest( ((processingEnvironment, element) -> {
processingEnvironment.getMessager().printMessage(Diagnostic.Kind.NOTE,"IT WORKED!!!");
}))
.thenExpectThat().compilationSucceeds()
.andThat().compilerMessage().ofKindNote().equals("IT WORKED!!!" )
.executeTest();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.toolisticon.cute.integrationtest.javanine;

import io.toolisticon.cute.PassIn;

@PassIn
public class Test {

public static void testCall() {

}

public static void secondTestCall(String testClass) {

}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module io.toolisticon.cute.integrationtest.javanine {
exports io.toolisticon.cute.integrationtest.javanine;
requires cute;
}

0 comments on commit 545629f

Please sign in to comment.