Skip to content

Commit adb4eac

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 7ba6b1c commit adb4eac

File tree

155 files changed

+1410
-512
lines changed

Some content is hidden

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

155 files changed

+1410
-512
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ updates:
238238
schedule:
239239
interval: "monthly"
240240
open-pull-requests-limit: 10
241+
- package-ecosystem: "gradle"
242+
directory: "/modules/testcontainers-junit4"
243+
schedule:
244+
interval: "monthly"
245+
open-pull-requests-limit: 10
241246
- package-ecosystem: "gradle"
242247
directory: "/modules/tidb"
243248
schedule:

.github/labeler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
- modules/jdbc/*
3636
"modules/jupiter":
3737
- modules/junit-jupiter/**/*
38+
"modules/junit4":
39+
- modules/testcontainers-junit4/**/*
3840
"modules/k3s":
3941
- modules/k3s/**/*
4042
"modules/kafka":

README.md

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

33
[![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)
44

5-
> 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.
5+
> 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.
66
77
![Testcontainers logo](docs/logo.png)
88

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
@@ -66,7 +66,6 @@ configurations.all {
6666
}
6767

6868
dependencies {
69-
api 'junit:junit:4.13.2'
7069
api 'org.slf4j:slf4j-api:1.7.36'
7170
compileOnly 'org.jetbrains:annotations:23.0.0'
7271
testCompileOnly 'org.jetbrains:annotations:23.0.0'
@@ -96,6 +95,7 @@ dependencies {
9695
testImplementation 'redis.clients:jedis:4.3.1'
9796
testImplementation 'com.rabbitmq:amqp-client:5.16.0'
9897
testImplementation 'org.mongodb:mongo-java-driver:3.12.11'
98+
testImplementation "junit:junit:4.13.2"
9999

100100
testImplementation ('org.mockito:mockito-core:4.9.0') {
101101
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");
@@ -1065,57 +1060,6 @@ public void addExposedPorts(int... ports) {
10651060
}
10661061
}
10671062

1068-
private TestDescription toDescription(Description description) {
1069-
return new TestDescription() {
1070-
@Override
1071-
public String getTestId() {
1072-
return description.getDisplayName();
1073-
}
1074-
1075-
@Override
1076-
public String getFilesystemFriendlyName() {
1077-
return description.getClassName() + "-" + description.getMethodName();
1078-
}
1079-
};
1080-
}
1081-
1082-
@Override
1083-
@Deprecated
1084-
public Statement apply(Statement base, Description description) {
1085-
return super.apply(base, description);
1086-
}
1087-
1088-
@Override
1089-
@Deprecated
1090-
protected void starting(Description description) {
1091-
if (this instanceof TestLifecycleAware) {
1092-
((TestLifecycleAware) this).beforeTest(toDescription(description));
1093-
}
1094-
this.start();
1095-
}
1096-
1097-
@Override
1098-
@Deprecated
1099-
protected void succeeded(Description description) {
1100-
if (this instanceof TestLifecycleAware) {
1101-
((TestLifecycleAware) this).afterTest(toDescription(description), Optional.empty());
1102-
}
1103-
}
1104-
1105-
@Override
1106-
@Deprecated
1107-
protected void failed(Throwable e, Description description) {
1108-
if (this instanceof TestLifecycleAware) {
1109-
((TestLifecycleAware) this).afterTest(toDescription(description), Optional.of(e));
1110-
}
1111-
}
1112-
1113-
@Override
1114-
@Deprecated
1115-
protected void finished(Description description) {
1116-
this.stop();
1117-
}
1118-
11191063
/**
11201064
* {@inheritDoc}
11211065
*/

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

@@ -93,11 +91,6 @@ private String create() {
9391
return createNetworkCmd.exec().getId();
9492
}
9593

96-
@Override
97-
protected void after() {
98-
close();
99-
}
100-
10194
@Override
10295
public synchronized void close() {
10396
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)