Skip to content

Commit 3c4eded

Browse files
committed
Move Testcontainers tests to JUnit Jupiter
1 parent c5e48b9 commit 3c4eded

File tree

124 files changed

+1364
-1481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1364
-1481
lines changed

core/build.gradle

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ shadowJar {
3030
}
3131

3232
task jarFileTest(type: Test) {
33+
useJUnitPlatform()
3334
testClassesDirs = sourceSets.jarFileTest.output.classesDirs
3435
classpath = sourceSets.jarFileTest.runtimeClasspath
3536

@@ -105,6 +106,9 @@ dependencies {
105106

106107
shaded 'org.zeroturnaround:zt-exec:1.12'
107108

109+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
110+
111+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
108112
testImplementation('com.google.cloud.tools:jib-core:0.27.3') {
109113
exclude group: 'com.google.guava', module: 'guava'
110114
}
@@ -124,8 +128,9 @@ dependencies {
124128

125129
jarFileTestCompileOnly "org.projectlombok:lombok:${lombok.version}"
126130
jarFileTestAnnotationProcessor "org.projectlombok:lombok:${lombok.version}"
127-
jarFileTestImplementation 'junit:junit:4.13.2'
128-
jarFileTestImplementation 'org.assertj:assertj-core:3.27.6'
131+
jarFileTestRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
132+
jarFileTestImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
133+
jarFileTestImplementation 'org.assertj:assertj-core:3.27.4'
129134
jarFileTestImplementation 'org.ow2.asm:asm-debug-all:5.2'
130135
}
131136

@@ -135,3 +140,14 @@ tasks.generatePomFileForMavenJavaPublication.finalizedBy(
135140
]
136141
}
137142
)
143+
144+
compileTestJava {
145+
javaCompiler = javaToolchains.compilerFor {
146+
languageVersion = JavaLanguageVersion.of(17)
147+
}
148+
options.release.set(17)
149+
}
150+
151+
test {
152+
useJUnitPlatform()
153+
}

core/src/jarFileTest/java/org/testcontainers/JarFileShadingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package org.testcontainers;
22

33
import org.assertj.core.api.ListAssert;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55

66
import java.io.IOException;
77
import java.nio.file.Files;
88
import java.nio.file.Path;
99

1010
import static org.assertj.core.api.Assertions.assertThat;
1111

12-
public class JarFileShadingTest extends AbstractJarFileTest {
12+
class JarFileShadingTest extends AbstractJarFileTest {
1313

1414
@Test
15-
public void testPackages() throws Exception {
15+
void testPackages() throws Exception {
1616
assertThatFileList(root).containsOnly("org", "META-INF");
1717

1818
assertThatFileList(root.resolve("org")).containsOnly("testcontainers");
1919
}
2020

2121
@Test
22-
public void testMetaInf() throws Exception {
22+
void testMetaInf() throws Exception {
2323
assertThatFileList(root.resolve("META-INF"))
2424
.containsOnly(
2525
"MANIFEST.MF",
@@ -33,7 +33,7 @@ public void testMetaInf() throws Exception {
3333
}
3434

3535
@Test
36-
public void testMetaInfServices() throws Exception {
36+
void testMetaInfServices() throws Exception {
3737
assertThatFileList(root.resolve("META-INF").resolve("services"))
3838
.allMatch(it -> it.startsWith("org.testcontainers."));
3939
}

core/src/jarFileTest/java/org/testcontainers/PublicBinaryAPITest.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import lombok.RequiredArgsConstructor;
44
import org.assertj.core.api.Assertions;
5-
import org.junit.Assume;
6-
import org.junit.Before;
7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
9-
import org.junit.runners.Parameterized;
10-
import org.junit.runners.Parameterized.Parameters;
5+
import org.junit.jupiter.api.Assumptions;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.params.Parameter;
9+
import org.junit.jupiter.params.ParameterizedClass;
10+
import org.junit.jupiter.params.provider.MethodSource;
1111
import org.objectweb.asm.ClassReader;
1212
import org.objectweb.asm.Opcodes;
1313
import org.objectweb.asm.Type;
@@ -30,23 +30,22 @@
3030

3131
/**
3232
* This test checks that we don't expose any shaded class in our public API.
33-
* We use {@link Parameterized} runner here to create a test per public class in Testcontainers' JAR file.
3433
*/
35-
@RunWith(Parameterized.class)
34+
@ParameterizedClass
35+
@MethodSource("data")
3636
@RequiredArgsConstructor
3737
public class PublicBinaryAPITest extends AbstractJarFileTest {
3838

39-
private static String SHADED_PACKAGE = "org.testcontainers.shaded.";
39+
private static final String SHADED_PACKAGE = "org.testcontainers.shaded.";
4040

41-
private static String SHADED_PACKAGE_PATH = SHADED_PACKAGE.replaceAll("\\.", "/");
41+
private static final String SHADED_PACKAGE_PATH = SHADED_PACKAGE.replaceAll("\\.", "/");
4242

4343
static {
4444
Assertions.registerFormatterForType(ClassNode.class, it -> it.name);
4545
Assertions.registerFormatterForType(FieldNode.class, it -> it.name);
4646
Assertions.registerFormatterForType(MethodNode.class, it -> it.name + it.desc);
4747
}
4848

49-
@Parameters(name = "{0}")
5049
public static List<Object[]> data() throws Exception {
5150
List<Object[]> result = new ArrayList<>();
5251

@@ -85,41 +84,43 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO
8584
return result;
8685
}
8786

88-
private final String fileName;
87+
@Parameter(0)
88+
private String fileName;
8989

90-
private final ClassNode classNode;
90+
@Parameter(1)
91+
private ClassNode classNode;
9192

92-
@Before
93+
@BeforeEach
9394
public void setUp() {
9495
switch (classNode.name) {
9596
// Necessary evil
9697
case "org/testcontainers/dockerclient/UnixSocketClientProviderStrategy":
9798
case "org/testcontainers/dockerclient/DockerClientProviderStrategy":
9899
case "org/testcontainers/dockerclient/WindowsClientProviderStrategy":
99100
case "org/testcontainers/utility/DynamicPollInterval":
100-
Assume.assumeTrue(false);
101+
Assumptions.assumeTrue(false);
101102
}
102103
}
103104

104105
@Test
105-
public void testSuperClass() {
106+
void testSuperClass() {
106107
assertThat(classNode.superName).doesNotStartWith(SHADED_PACKAGE_PATH);
107108
}
108109

109110
@Test
110-
public void testInterfaces() {
111+
void testInterfaces() {
111112
assertThat(classNode.interfaces).allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE_PATH));
112113
}
113114

114115
@Test
115-
public void testMethodReturnTypes() {
116+
void testMethodReturnTypes() {
116117
assertThat(classNode.methods)
117118
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
118119
.allSatisfy(it -> assertThat(Type.getReturnType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
119120
}
120121

121122
@Test
122-
public void testMethodArguments() {
123+
void testMethodArguments() {
123124
assertThat(classNode.methods)
124125
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
125126
.allSatisfy(method -> {
@@ -130,7 +131,7 @@ public void testMethodArguments() {
130131
}
131132

132133
@Test
133-
public void testFields() {
134+
void testFields() {
134135
assertThat(classNode.fields)
135136
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
136137
.allSatisfy(it -> assertThat(Type.getType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));

core/src/test/java/alt/testcontainers/images/OutOfPackageImagePullPolicyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package alt.testcontainers.images;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.testcontainers.TestImages;
55
import org.testcontainers.containers.GenericContainer;
66
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
77
import org.testcontainers.images.AbstractImagePullPolicy;
88
import org.testcontainers.images.ImageData;
99
import org.testcontainers.utility.DockerImageName;
1010

11-
public class OutOfPackageImagePullPolicyTest {
11+
class OutOfPackageImagePullPolicyTest {
1212

1313
@Test
14-
public void shouldSupportCustomPoliciesOutOfTestcontainersPackage() {
14+
void shouldSupportCustomPoliciesOutOfTestcontainersPackage() {
1515
try (
1616
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
1717
.withImagePullPolicy(

core/src/test/java/org/testcontainers/DaemonTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.testcontainers;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.testcontainers.containers.GenericContainer;
55

66
import java.io.File;
@@ -14,7 +14,7 @@
1414
/**
1515
* This test forks a new JVM, otherwise it's not possible to reliably diff the threads
1616
*/
17-
public class DaemonTest {
17+
class DaemonTest {
1818

1919
public static void main(String[] args) {
2020
Thread mainThread = Thread.currentThread();
@@ -46,7 +46,7 @@ public static void main(String[] args) {
4646
}
4747

4848
@Test
49-
public void testThatAllThreadsAreDaemons() throws Exception {
49+
void testThatAllThreadsAreDaemons() throws Exception {
5050
ProcessBuilder processBuilder = new ProcessBuilder(
5151
new File(System.getProperty("java.home")).toPath().resolve("bin").resolve("java").toString(),
5252
"-ea",

core/src/test/java/org/testcontainers/DockerClientFactoryTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
package org.testcontainers;
22

3-
import org.junit.Rule;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
55
import org.testcontainers.dockerclient.LogToStringContainerCallback;
66
import org.testcontainers.utility.DockerImageName;
7-
import org.testcontainers.utility.MockTestcontainersConfigurationRule;
7+
import org.testcontainers.utility.MockTestcontainersConfigurationExtension;
88

99
import static org.assertj.core.api.Assertions.assertThat;
1010
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1111

1212
/**
1313
* Test for {@link DockerClientFactory}.
1414
*/
15-
public class DockerClientFactoryTest {
16-
17-
@Rule
18-
public MockTestcontainersConfigurationRule configurationMock = new MockTestcontainersConfigurationRule();
15+
@ExtendWith(MockTestcontainersConfigurationExtension.class)
16+
class DockerClientFactoryTest {
1917

2018
@Test
21-
public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
19+
void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
2220
try (DockerRegistryContainer registryContainer = new DockerRegistryContainer()) {
2321
registryContainer.start();
2422
DockerImageName imageName = registryContainer.createImage();
@@ -40,14 +38,14 @@ public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
4038
}
4139

4240
@Test
43-
public void dockerHostIpAddress() {
41+
void dockerHostIpAddress() {
4442
DockerClientFactory instance = new DockerClientFactory();
4543
instance.strategy = null;
4644
assertThat(instance.dockerHostIpAddress()).isNotNull();
4745
}
4846

4947
@Test
50-
public void failedChecksFailFast() {
48+
void failedChecksFailFast() {
5149
DockerClientFactory instance = DockerClientFactory.instance();
5250
assertThat(instance.client()).isNotNull();
5351
assertThat(instance.cachedClientFailure).isNull();

core/src/test/java/org/testcontainers/containers/ComposeContainerWithServicesTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.testcontainers.containers;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44
import org.rnorth.ducttape.TimeoutException;
55
import org.testcontainers.containers.wait.strategy.Wait;
66

@@ -13,7 +13,7 @@
1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.assertj.core.api.Assertions.catchThrowable;
1515

16-
public class ComposeContainerWithServicesTest {
16+
class ComposeContainerWithServicesTest {
1717

1818
public static final File SIMPLE_COMPOSE_FILE = new File(
1919
"src/test/resources/compose-scaling-multiple-containers.yml"
@@ -28,7 +28,7 @@ public class ComposeContainerWithServicesTest {
2828
);
2929

3030
@Test
31-
public void testDesiredSubsetOfServicesAreStarted() {
31+
void testDesiredSubsetOfServicesAreStarted() {
3232
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE).withServices("redis")) {
3333
compose.start();
3434

@@ -37,7 +37,7 @@ public void testDesiredSubsetOfServicesAreStarted() {
3737
}
3838

3939
@Test
40-
public void testDesiredSubsetOfScaledServicesAreStarted() {
40+
void testDesiredSubsetOfScaledServicesAreStarted() {
4141
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE).withScaledService("redis", 2)) {
4242
compose.start();
4343

@@ -46,7 +46,7 @@ public void testDesiredSubsetOfScaledServicesAreStarted() {
4646
}
4747

4848
@Test
49-
public void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
49+
void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
5050
try (
5151
ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)
5252
.withServices("redis")
@@ -59,7 +59,7 @@ public void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
5959
}
6060

6161
@Test
62-
public void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
62+
void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
6363
try (
6464
ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)
6565
.withServices("other")
@@ -72,7 +72,7 @@ public void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
7272
}
7373

7474
@Test
75-
public void testAllServicesAreStartedIfNotSpecified() {
75+
void testAllServicesAreStartedIfNotSpecified() {
7676
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)) {
7777
compose.start();
7878

@@ -81,7 +81,7 @@ public void testAllServicesAreStartedIfNotSpecified() {
8181
}
8282

8383
@Test
84-
public void testScaleInComposeFileIsRespected() {
84+
void testScaleInComposeFileIsRespected() {
8585
try (ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_INLINE_SCALE)) {
8686
compose.start();
8787

@@ -91,7 +91,7 @@ public void testScaleInComposeFileIsRespected() {
9191
}
9292

9393
@Test
94-
public void testStartupTimeoutSetsTheHighestTimeout() {
94+
void testStartupTimeoutSetsTheHighestTimeout() {
9595
assertThat(
9696
catchThrowable(() -> {
9797
try (
@@ -113,7 +113,7 @@ public void testStartupTimeoutSetsTheHighestTimeout() {
113113
}
114114

115115
@Test
116-
public void testWaitingForHealthcheck() {
116+
void testWaitingForHealthcheck() {
117117
try (
118118
ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_HEALTHCHECK)
119119
.waitingFor("redis", Wait.forHealthcheck().withStartupTimeout(Duration.ofMinutes(2)))
@@ -125,7 +125,7 @@ public void testWaitingForHealthcheck() {
125125
}
126126

127127
@Test
128-
public void testWaitingForHealthcheckWithRestartDoesNotCrash() {
128+
void testWaitingForHealthcheckWithRestartDoesNotCrash() {
129129
try (
130130
ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_HEALTHCHECK)
131131
.waitingFor("redis", Wait.forHealthcheck().withStartupTimeout(Duration.ofMinutes(1)))

0 commit comments

Comments
 (0)