1919
2020import io .github .ascopes .jct .compilers .JctCompiler ;
2121import io .github .ascopes .jct .junit .JavacCompilerTest ;
22+ import io .github .ascopes .jct .tests .integration .AbstractIntegrationTest ;
2223import io .github .ascopes .jct .workspaces .PathStrategy ;
2324import io .github .ascopes .jct .workspaces .Workspaces ;
2425import org .junit .jupiter .api .DisplayName ;
2930 * @author Ashley Scopes
3031 */
3132@ DisplayName ("Basic multi-module compilation integration tests" )
32- class BasicMultiModuleCompilationIntegrationTest {
33+ class BasicMultiModuleCompilationIntegrationTest extends AbstractIntegrationTest {
3334
3435 @ DisplayName ("I can compile a single module using multi-module layout using a RAM disk" )
3536 @ JavacCompilerTest (minVersion = 9 )
3637 void singleModuleInMultiModuleLayoutRamDisk (JctCompiler <?, ?> compiler ) {
3738 try (var workspace = Workspaces .newWorkspace (PathStrategy .RAM_DIRECTORIES )) {
3839 // Given
3940 workspace
40- .createSourcePathModule ("hello.world" )
41- .createFile ("com" , "example" , "HelloWorld.java" ).withContents (
42- "package com.example;" ,
43- "public class HelloWorld {" ,
44- " public static void main(String[] args) {" ,
45- " System.out.println(\" Hello, World\" );" ,
46- " }" ,
47- "}"
48- )
49- .and ().createFile ("module-info.java" ).withContents (
50- "module hello.world {" ,
51- " exports com.example;" ,
52- "}"
53- );
41+ .createSourcePathModule ("hello.world.singlemodule" )
42+ .copyContentsFrom (resourcesDirectory ().resolve ("hello.world.singlemodule" ));
5443
5544 // When
5645 var compilation = compiler .compile (workspace );
@@ -61,12 +50,12 @@ void singleModuleInMultiModuleLayoutRamDisk(JctCompiler<?, ?> compiler) {
6150
6251 assertThatCompilation (compilation )
6352 .classOutput ().modules ()
64- .moduleExists ("hello.world" )
53+ .moduleExists ("hello.world.singlemodule " )
6554 .fileExists ("com" , "example" , "HelloWorld.class" ).isNotEmptyFile ();
6655
6756 assertThatCompilation (compilation )
6857 .classOutput ().modules ()
69- .moduleExists ("hello.world" )
58+ .moduleExists ("hello.world.singlemodule " )
7059 .fileExists ("module-info.class" ).isNotEmptyFile ();
7160 }
7261 }
@@ -77,20 +66,8 @@ void singleModuleInMultiModuleLayoutTempDirectory(JctCompiler<?, ?> compiler) {
7766 try (var workspace = Workspaces .newWorkspace (PathStrategy .TEMP_DIRECTORIES )) {
7867 // Given
7968 workspace
80- .createSourcePathModule ("hello.world" )
81- .createFile ("com" , "example" , "HelloWorld.java" ).withContents (
82- "package com.example;" ,
83- "public class HelloWorld {" ,
84- " public static void main(String[] args) {" ,
85- " System.out.println(\" Hello, World\" );" ,
86- " }" ,
87- "}"
88- )
89- .and ().createFile ("module-info.java" ).withContents (
90- "module hello.world {" ,
91- " exports com.example;" ,
92- "}"
93- );
69+ .createSourcePathModule ("hello.world.singlemodule" )
70+ .copyContentsFrom (resourcesDirectory ().resolve ("hello.world.singlemodule" ));
9471
9572 // When
9673 var compilation = compiler .compile (workspace );
@@ -101,12 +78,12 @@ void singleModuleInMultiModuleLayoutTempDirectory(JctCompiler<?, ?> compiler) {
10178
10279 assertThatCompilation (compilation )
10380 .classOutput ().modules ()
104- .moduleExists ("hello.world" )
81+ .moduleExists ("hello.world.singlemodule " )
10582 .fileExists ("com" , "example" , "HelloWorld.class" ).isNotEmptyFile ();
10683
10784 assertThatCompilation (compilation )
10885 .classOutput ().modules ()
109- .moduleExists ("hello.world" )
86+ .moduleExists ("hello.world.singlemodule " )
11087 .fileExists ("module-info.class" ).isNotEmptyFile ();
11188 }
11289 }
@@ -117,38 +94,12 @@ void multipleModulesInMultiModuleLayoutRamDisk(JctCompiler<?, ?> compiler) {
11794 try (var workspace = Workspaces .newWorkspace (PathStrategy .RAM_DIRECTORIES )) {
11895 // Given
11996 workspace
120- .createSourcePathModule ("hello.world" )
121- .createFile ("com" , "example" , "HelloWorld.java" ).withContents (
122- "package com.example;" ,
123- "import com.example.greeter.Greeter;" ,
124- "public class HelloWorld {" ,
125- " public static void main(String[] args) {" ,
126- " System.out.println(Greeter.greet(\" World\" ));" ,
127- " }" ,
128- "}"
129- )
130- .and ().createFile ("module-info.java" ).withContents (
131- "module hello.world {" ,
132- " requires greeter;" ,
133- " exports com.example;" ,
134- "}"
135- );
97+ .createSourcePathModule ("hello.world.crossmodule" )
98+ .copyContentsFrom (resourcesDirectory ().resolve ("hello.world.crossmodule" ));
13699
137100 workspace
138101 .createSourcePathModule ("greeter" )
139- .createFile ("com" , "example" , "greeter" , "Greeter.java" ).withContents (
140- "package com.example.greeter;" ,
141- "public class Greeter {" ,
142- " public static String greet(String name) {" ,
143- " return \" Hello, \" + name + \" !\" ;" ,
144- " }" ,
145- "}"
146- )
147- .and ().createFile ("module-info.java" ).withContents (
148- "module greeter {" ,
149- " exports com.example.greeter;" ,
150- "}"
151- );
102+ .copyContentsFrom (resourcesDirectory ().resolve ("greeter" ));
152103
153104 // When
154105 var compilation = compiler .compile (workspace );
@@ -159,12 +110,12 @@ void multipleModulesInMultiModuleLayoutRamDisk(JctCompiler<?, ?> compiler) {
159110
160111 assertThatCompilation (compilation )
161112 .classOutput ().modules ()
162- .moduleExists ("hello.world" )
113+ .moduleExists ("hello.world.crossmodule " )
163114 .fileExists ("com" , "example" , "HelloWorld.class" ).isNotEmptyFile ();
164115
165116 assertThatCompilation (compilation )
166117 .classOutput ().modules ()
167- .moduleExists ("hello.world" )
118+ .moduleExists ("hello.world.crossmodule " )
168119 .fileExists ("module-info.class" ).isNotEmptyFile ();
169120
170121 assertThatCompilation (compilation )
@@ -185,38 +136,12 @@ void multipleModulesInMultiModuleLayoutTempDirectory(JctCompiler<?, ?> compiler)
185136 try (var workspace = Workspaces .newWorkspace (PathStrategy .TEMP_DIRECTORIES )) {
186137 // Given
187138 workspace
188- .createSourcePathModule ("hello.world" )
189- .createFile ("com" , "example" , "HelloWorld.java" ).withContents (
190- "package com.example;" ,
191- "import com.example.greeter.Greeter;" ,
192- "public class HelloWorld {" ,
193- " public static void main(String[] args) {" ,
194- " System.out.println(Greeter.greet(\" World\" ));" ,
195- " }" ,
196- "}"
197- )
198- .and ().createFile ("module-info.java" ).withContents (
199- "module hello.world {" ,
200- " requires greeter;" ,
201- " exports com.example;" ,
202- "}"
203- );
139+ .createSourcePathModule ("hello.world.crossmodule" )
140+ .copyContentsFrom (resourcesDirectory ().resolve ("hello.world.crossmodule" ));
204141
205142 workspace
206143 .createSourcePathModule ("greeter" )
207- .createFile ("com" , "example" , "greeter" , "Greeter.java" ).withContents (
208- "package com.example.greeter;" ,
209- "public class Greeter {" ,
210- " public static String greet(String name) {" ,
211- " return \" Hello, \" + name + \" !\" ;" ,
212- " }" ,
213- "}"
214- )
215- .and ().createFile ("module-info.java" ).withContents (
216- "module greeter {" ,
217- " exports com.example.greeter;" ,
218- "}"
219- );
144+ .copyContentsFrom (resourcesDirectory ().resolve ("greeter" ));
220145
221146 // When
222147 var compilation = compiler .compile (workspace );
@@ -226,12 +151,12 @@ void multipleModulesInMultiModuleLayoutTempDirectory(JctCompiler<?, ?> compiler)
226151
227152 assertThatCompilation (compilation )
228153 .classOutput ().modules ()
229- .moduleExists ("hello.world" )
154+ .moduleExists ("hello.world.crossmodule " )
230155 .fileExists ("com" , "example" , "HelloWorld.class" ).isNotEmptyFile ();
231156
232157 assertThatCompilation (compilation )
233158 .classOutput ().modules ()
234- .moduleExists ("hello.world" )
159+ .moduleExists ("hello.world.crossmodule " )
235160 .fileExists ("module-info.class" ).isNotEmptyFile ();
236161
237162 assertThatCompilation (compilation )
0 commit comments