Skip to content

Commit 5d717f9

Browse files
committed
Tidy up modified integration tests
1 parent b720080 commit 5d717f9

6 files changed

+223
-320
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.ascopes.jct.tests.integration;
17+
18+
import io.github.ascopes.jct.compilers.JctCompiler;
19+
import io.github.ascopes.jct.compilers.JctCompilerConfigurer;
20+
21+
/**
22+
* Default configuration settings for integration tests.
23+
*
24+
* @author Ashley Scopes
25+
*/
26+
public final class IntegrationTestConfigurer implements JctCompilerConfigurer<Exception> {
27+
@Override
28+
public void configure(JctCompiler<?, ?> compiler) {
29+
compiler
30+
.inheritClassPath(false)
31+
.inheritModulePath(false);
32+
}
33+
}

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/integration/compilation/BasicLegacyCompilationIntegrationTest.java

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import io.github.ascopes.jct.junit.EcjCompilerTest;
2222
import io.github.ascopes.jct.junit.JavacCompilerTest;
2323
import io.github.ascopes.jct.tests.integration.AbstractIntegrationTest;
24+
import io.github.ascopes.jct.tests.integration.IntegrationTestConfigurer;
2425
import io.github.ascopes.jct.workspaces.PathStrategy;
26+
import io.github.ascopes.jct.workspaces.Workspace;
2527
import io.github.ascopes.jct.workspaces.Workspaces;
2628
import javax.tools.StandardLocation;
2729
import org.junit.jupiter.api.DisplayName;
@@ -35,64 +37,43 @@
3537
class BasicLegacyCompilationIntegrationTest extends AbstractIntegrationTest {
3638

3739
@DisplayName("I can compile a 'Hello, World!' program using a RAM directory on Javac")
38-
@JavacCompilerTest
40+
@JavacCompilerTest(configurers = IntegrationTestConfigurer.class)
3941
void helloWorldRamDirectoryJavac(JctCompiler<?, ?> compiler) {
4042
try (var workspace = Workspaces.newWorkspace(PathStrategy.RAM_DIRECTORIES)) {
41-
workspace
42-
.createPackage(StandardLocation.SOURCE_PATH)
43-
.createDirectory("com", "example")
44-
.copyContentsFrom(resourcesDirectory());
45-
var compilation = compiler.compile(workspace);
46-
47-
assertThatCompilation(compilation)
48-
.isSuccessfulWithoutWarnings();
49-
50-
assertThatCompilation(compilation)
51-
.classOutput().packages()
52-
.fileExists("com", "example", "HelloWorld.class")
53-
.isNotEmptyFile();
43+
runTest(compiler, workspace);
5444
}
5545
}
5646

5747
@DisplayName("I can compile a 'Hello, World!' program using a temp directory on Javac")
58-
@JavacCompilerTest
48+
@JavacCompilerTest(configurers = IntegrationTestConfigurer.class)
5949
void helloWorldTempDirectoryJavac(JctCompiler<?, ?> compiler) {
6050
try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
61-
workspace
62-
.createPackage(StandardLocation.SOURCE_PATH)
63-
.createDirectory("com", "example")
64-
.copyContentsFrom(resourcesDirectory());
65-
66-
var compilation = compiler.compile(workspace);
67-
68-
assertThatCompilation(compilation)
69-
.isSuccessfulWithoutWarnings();
70-
71-
assertThatCompilation(compilation)
72-
.classOutput().packages()
73-
.fileExists("com", "example", "HelloWorld.class")
74-
.isNotEmptyFile();
51+
runTest(compiler, workspace);
7552
}
7653
}
7754

7855
@DisplayName("I can compile a 'Hello, World!' program using a temp directory on ECJ")
79-
@EcjCompilerTest
56+
@EcjCompilerTest(configurers = IntegrationTestConfigurer.class)
8057
void helloWorldTempDirectoryEcj(JctCompiler<?, ?> compiler) {
8158
try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
82-
workspace
83-
.createPackage(StandardLocation.SOURCE_PATH)
84-
.createDirectory("com", "example")
85-
.copyContentsFrom(resourcesDirectory());
59+
runTest(compiler, workspace);
60+
}
61+
}
8662

87-
var compilation = compiler.compile(workspace);
63+
private void runTest(JctCompiler<?, ?> compiler, Workspace workspace) {
64+
workspace
65+
.createPackage(StandardLocation.SOURCE_PATH)
66+
.createDirectory("com", "example")
67+
.copyContentsFrom(resourcesDirectory());
8868

89-
assertThatCompilation(compilation)
90-
.isSuccessfulWithoutWarnings();
69+
var compilation = compiler.compile(workspace);
9170

92-
assertThatCompilation(compilation)
93-
.classOutput().packages()
94-
.fileExists("com", "example", "HelloWorld.class")
95-
.isNotEmptyFile();
96-
}
71+
assertThatCompilation(compilation)
72+
.isSuccessfulWithoutWarnings();
73+
74+
assertThatCompilation(compilation)
75+
.classOutput().packages()
76+
.fileExists("com", "example", "HelloWorld.class")
77+
.isNotEmptyFile();
9778
}
9879
}

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/integration/compilation/BasicModuleCompilationIntegrationTest.java

Lines changed: 56 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation;
1919
import static io.github.ascopes.jct.assertions.JctAssertions.assertThatContainerGroup;
2020

21+
import io.github.ascopes.jct.compilers.JctCompilation;
2122
import io.github.ascopes.jct.compilers.JctCompiler;
2223
import io.github.ascopes.jct.junit.EcjCompilerTest;
2324
import io.github.ascopes.jct.junit.JavacCompilerTest;
2425
import io.github.ascopes.jct.tests.integration.AbstractIntegrationTest;
26+
import io.github.ascopes.jct.tests.integration.IntegrationTestConfigurer;
2527
import io.github.ascopes.jct.workspaces.PathStrategy;
28+
import io.github.ascopes.jct.workspaces.Workspace;
2629
import io.github.ascopes.jct.workspaces.Workspaces;
2730
import org.junit.jupiter.api.DisplayName;
2831

@@ -35,93 +38,75 @@
3538
class BasicModuleCompilationIntegrationTest extends AbstractIntegrationTest {
3639

3740
@DisplayName("I can compile a 'Hello, World!' module program using a RAM disk on Javac")
38-
@JavacCompilerTest(minVersion = 9)
41+
@JavacCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class)
3942
void helloWorldRamDiskJavac(JctCompiler<?, ?> compiler) {
4043
try (var workspace = Workspaces.newWorkspace(PathStrategy.RAM_DIRECTORIES)) {
41-
// Given
42-
workspace
43-
.createSourcePathPackage()
44-
.copyContentsFrom(resourcesDirectory());
45-
46-
// When
47-
var compilation = compiler.compile(workspace);
48-
49-
// Then
50-
assertThatCompilation(compilation)
51-
.isSuccessfulWithoutWarnings();
52-
53-
assertThatCompilation(compilation)
54-
.classOutput()
55-
.packages()
56-
.fileExists("com", "example", "HelloWorld.class")
57-
.isNotEmptyFile();
58-
59-
assertThatCompilation(compilation)
60-
.classOutput()
61-
.packages()
62-
.fileExists("module-info.class")
63-
.isNotEmptyFile();
44+
runHelloWorldTestExpectingPackages(compiler, workspace);
6445
}
6546
}
6647

6748
@DisplayName("I can compile a 'Hello, World!' module program using a temp directory on Javac")
68-
@JavacCompilerTest(minVersion = 9)
49+
@JavacCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class)
6950
void helloWorldUsingTempDirectoryJavac(JctCompiler<?, ?> compiler) {
7051
try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
71-
// Given
72-
workspace
73-
.createSourcePathPackage()
74-
.copyContentsFrom(resourcesDirectory());
75-
76-
// When
77-
var compilation = compiler.compile(workspace);
78-
79-
// Then
80-
assertThatCompilation(compilation)
81-
.isSuccessfulWithoutWarnings();
82-
83-
assertThatCompilation(compilation)
84-
.classOutput()
85-
.packages()
86-
.fileExists("com", "example", "HelloWorld.class")
87-
.isNotEmptyFile();
88-
89-
assertThatCompilation(compilation)
90-
.classOutput()
91-
.packages()
92-
.fileExists("module-info.class")
93-
.isNotEmptyFile();
52+
runHelloWorldTestExpectingPackages(compiler, workspace);
9453
}
9554
}
9655

9756
@DisplayName("I can compile a 'Hello, World!' module program using a temp directory on ECJ")
98-
@EcjCompilerTest(minVersion = 9)
57+
@EcjCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class)
9958
void helloWorldUsingTempDirectoryEcj(JctCompiler<?, ?> compiler) {
10059
try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
101-
// Given
102-
workspace
103-
.createSourcePathPackage()
104-
.copyContentsFrom(resourcesDirectory());
60+
runHelloWorldTestExpectingModules(compiler, workspace);
61+
}
62+
}
10563

106-
// When
107-
var compilation = compiler.compile(workspace);
64+
private void runHelloWorldTestExpectingPackages(JctCompiler<?, ?> compiler, Workspace workspace) {
65+
var compilation = runHelloWorldTestStart(compiler, workspace);
10866

109-
// Then
110-
assertThatCompilation(compilation)
111-
.isSuccessfulWithoutWarnings();
67+
assertThatCompilation(compilation)
68+
.classOutput()
69+
.packages()
70+
.fileExists("com", "example", "HelloWorld.class")
71+
.isNotEmptyFile();
11272

113-
assertThatCompilation(compilation)
114-
.classOutput()
115-
.modules()
116-
.moduleExists("hello.world")
117-
.satisfies(
118-
module -> assertThatContainerGroup(module)
119-
.fileExists("com", "example", "HelloWorld.class")
120-
.isNotEmptyFile(),
121-
module -> assertThatContainerGroup(module)
122-
.fileExists("module-info.class")
123-
.isNotEmptyFile()
124-
);
125-
}
73+
assertThatCompilation(compilation)
74+
.classOutput()
75+
.packages()
76+
.fileExists("module-info.class")
77+
.isNotEmptyFile();
78+
}
79+
80+
private void runHelloWorldTestExpectingModules(JctCompiler<?, ?> compiler, Workspace workspace) {
81+
var compilation = runHelloWorldTestStart(compiler, workspace);
82+
83+
assertThatCompilation(compilation)
84+
.classOutput()
85+
.modules()
86+
.moduleExists("hello.world")
87+
.satisfies(
88+
module -> assertThatContainerGroup(module)
89+
.fileExists("com", "example", "HelloWorld.class")
90+
.isNotEmptyFile(),
91+
module -> assertThatContainerGroup(module)
92+
.fileExists("module-info.class")
93+
.isNotEmptyFile()
94+
);
95+
}
96+
97+
private JctCompilation runHelloWorldTestStart(JctCompiler<?, ?> compiler, Workspace workspace) {
98+
// Given
99+
workspace
100+
.createSourcePathPackage()
101+
.copyContentsFrom(resourcesDirectory());
102+
103+
// When
104+
var compilation = compiler.compile(workspace);
105+
106+
// Then
107+
assertThatCompilation(compilation)
108+
.isSuccessfulWithoutWarnings();
109+
110+
return compilation;
126111
}
127112
}

0 commit comments

Comments
 (0)