Skip to content

Commit cea6bed

Browse files
committed
Moves Junit 4 support from core to separate module
Module is named testcontainers-junit4 instead of junit4 because it fails when building examples with "> Module version 'org.testcontainers:junit4' is not unique in composite: can be provided by [project :testcontainers-java:docs:examples:junit4, project " Seems related to gradle/gradle#12872
1 parent e8844eb commit cea6bed

File tree

161 files changed

+1423
-518
lines changed

Some content is hidden

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

161 files changed

+1423
-518
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ updates:
261261
schedule:
262262
interval: "monthly"
263263
open-pull-requests-limit: 10
264+
- package-ecosystem: "gradle"
265+
directory: "/modules/testcontainers-junit4"
266+
schedule:
267+
interval: "monthly"
268+
open-pull-requests-limit: 10
264269
- package-ecosystem: "gradle"
265270
directory: "/modules/tidb"
266271
schedule:

.github/labeler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
- modules/jdbc/**/*
3838
"modules/jupiter":
3939
- modules/junit-jupiter/**/*
40+
"modules/junit4":
41+
- modules/testcontainers-junit4/**/*
4042
"modules/k3s":
4143
- modules/k3s/**/*
4244
"modules/kafka":

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Revved up by Gradle Enterprise](https://img.shields.io/badge/Revved%20up%20by-Gradle%20Enterprise-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.testcontainers.org/scans)
66

7-
> Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
7+
> Testcontainers is a Java library that supports JUnit and Spock tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
88
99
![Testcontainers logo](docs/logo.png)
1010

config/checkstyle/checkstyle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
org.assertj.core.api.Assumptions.*,
3232
org.awaitility.Awaitility.*,
3333
org.junit.Assume.*,
34+
org.junit.jupiter.api.Assumptions.*,
3435
org.mockito.Mockito.*,
3536
org.mockito.ArgumentMatchers.*,
3637
org.mockserver.model.HttpRequest.*,

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ configurations.all {
6767
}
6868

6969
dependencies {
70-
api 'junit:junit:4.13.2'
7170
api 'org.slf4j:slf4j-api:1.7.36'
7271
compileOnly 'org.jetbrains:annotations:24.0.0'
7372
testCompileOnly 'org.jetbrains:annotations:24.0.0'
@@ -106,6 +105,7 @@ dependencies {
106105
testImplementation 'redis.clients:jedis:4.3.1'
107106
testImplementation 'com.rabbitmq:amqp-client:5.16.0'
108107
testImplementation 'org.mongodb:mongo-java-driver:3.12.12'
108+
testImplementation "junit:junit:4.13.2"
109109

110110
testImplementation ('org.mockito:mockito-core:4.11.0') {
111111
exclude(module: 'hamcrest-core')

core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import lombok.extern.slf4j.Slf4j;
1717
import org.apache.commons.lang3.StringUtils;
1818
import org.apache.commons.lang3.SystemUtils;
19-
import org.junit.runner.Description;
20-
import org.junit.runners.model.Statement;
2119
import org.slf4j.Logger;
2220
import org.testcontainers.DockerClientFactory;
2321
import org.testcontainers.containers.output.OutputFrame;
@@ -66,9 +64,7 @@
6664
* Container which launches Docker Compose, for the purposes of launching a defined set of containers.
6765
*/
6866
@Slf4j
69-
public class DockerComposeContainer<SELF extends DockerComposeContainer<SELF>>
70-
extends FailureDetectingExternalResource
71-
implements Startable {
67+
public class DockerComposeContainer<SELF extends DockerComposeContainer<SELF>> implements Startable {
7268

7369
/**
7470
* Random identifier which will become part of spawned containers names, so we can shut them down
@@ -149,32 +145,6 @@ public DockerComposeContainer(String identifier, List<File> composeFiles) {
149145
this.dockerClient = DockerClientFactory.lazyClient();
150146
}
151147

152-
@Override
153-
@Deprecated
154-
public Statement apply(Statement base, Description description) {
155-
return super.apply(base, description);
156-
}
157-
158-
@Override
159-
@Deprecated
160-
public void starting(Description description) {
161-
start();
162-
}
163-
164-
@Override
165-
@Deprecated
166-
protected void succeeded(Description description) {}
167-
168-
@Override
169-
@Deprecated
170-
protected void failed(Throwable e, Description description) {}
171-
172-
@Override
173-
@Deprecated
174-
public void finished(Description description) {
175-
stop();
176-
}
177-
178148
@Override
179149
public void start() {
180150
synchronized (MUTEX) {

core/src/main/java/org/testcontainers/containers/FailureDetectingExternalResource.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.apache.commons.lang3.SystemUtils;
3333
import org.jetbrains.annotations.NotNull;
3434
import org.jetbrains.annotations.Nullable;
35-
import org.junit.runner.Description;
36-
import org.junit.runners.model.Statement;
3735
import org.rnorth.ducttape.ratelimits.RateLimiter;
3836
import org.rnorth.ducttape.ratelimits.RateLimiterBuilder;
3937
import org.rnorth.ducttape.unreliables.Unreliables;
@@ -53,8 +51,6 @@
5351
import org.testcontainers.images.builder.Transferable;
5452
import org.testcontainers.lifecycle.Startable;
5553
import org.testcontainers.lifecycle.Startables;
56-
import org.testcontainers.lifecycle.TestDescription;
57-
import org.testcontainers.lifecycle.TestLifecycleAware;
5854
import org.testcontainers.utility.Base58;
5955
import org.testcontainers.utility.CommandLine;
6056
import org.testcontainers.utility.DockerImageName;
@@ -107,7 +103,6 @@
107103
*/
108104
@Data
109105
public class GenericContainer<SELF extends GenericContainer<SELF>>
110-
extends FailureDetectingExternalResource
111106
implements Container<SELF>, AutoCloseable, WaitStrategyTarget, Startable {
112107

113108
private static final Charset UTF8 = Charset.forName("UTF-8");
@@ -1102,57 +1097,6 @@ public void addExposedPorts(int... ports) {
11021097
}
11031098
}
11041099

1105-
private TestDescription toDescription(Description description) {
1106-
return new TestDescription() {
1107-
@Override
1108-
public String getTestId() {
1109-
return description.getDisplayName();
1110-
}
1111-
1112-
@Override
1113-
public String getFilesystemFriendlyName() {
1114-
return description.getClassName() + "-" + description.getMethodName();
1115-
}
1116-
};
1117-
}
1118-
1119-
@Override
1120-
@Deprecated
1121-
public Statement apply(Statement base, Description description) {
1122-
return super.apply(base, description);
1123-
}
1124-
1125-
@Override
1126-
@Deprecated
1127-
protected void starting(Description description) {
1128-
if (this instanceof TestLifecycleAware) {
1129-
((TestLifecycleAware) this).beforeTest(toDescription(description));
1130-
}
1131-
this.start();
1132-
}
1133-
1134-
@Override
1135-
@Deprecated
1136-
protected void succeeded(Description description) {
1137-
if (this instanceof TestLifecycleAware) {
1138-
((TestLifecycleAware) this).afterTest(toDescription(description), Optional.empty());
1139-
}
1140-
}
1141-
1142-
@Override
1143-
@Deprecated
1144-
protected void failed(Throwable e, Description description) {
1145-
if (this instanceof TestLifecycleAware) {
1146-
((TestLifecycleAware) this).afterTest(toDescription(description), Optional.of(e));
1147-
}
1148-
}
1149-
1150-
@Override
1151-
@Deprecated
1152-
protected void finished(Description description) {
1153-
this.stop();
1154-
}
1155-
11561100
/**
11571101
* {@inheritDoc}
11581102
*/

core/src/main/java/org/testcontainers/containers/Network.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import lombok.Builder;
55
import lombok.Getter;
66
import lombok.Singular;
7-
import org.junit.rules.ExternalResource;
8-
import org.junit.rules.TestRule;
97
import org.testcontainers.DockerClientFactory;
108
import org.testcontainers.utility.ResourceReaper;
119

@@ -17,7 +15,7 @@
1715
import java.util.concurrent.atomic.AtomicBoolean;
1816
import java.util.function.Consumer;
1917

20-
public interface Network extends AutoCloseable, TestRule {
18+
public interface Network extends AutoCloseable {
2119
Network SHARED = new NetworkImpl(false, null, Collections.emptySet(), null) {
2220
@Override
2321
public void close() {
@@ -40,7 +38,7 @@ static NetworkImpl.NetworkImplBuilder builder() {
4038

4139
@Builder
4240
@Getter
43-
class NetworkImpl extends ExternalResource implements Network {
41+
class NetworkImpl implements Network {
4442

4543
private final String name = UUID.randomUUID().toString();
4644

@@ -100,11 +98,6 @@ private String create() {
10098
return createNetworkCmd.exec().getId();
10199
}
102100

103-
@Override
104-
protected void after() {
105-
close();
106-
}
107-
108101
@Override
109102
public synchronized void close() {
110103
if (initialized.getAndSet(false)) {

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)