Skip to content

Commit e8d7375

Browse files
authored
Move to assertj (#5679)
1 parent cae1272 commit e8d7375

File tree

147 files changed

+1265
-1544
lines changed

Some content is hidden

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

147 files changed

+1265
-1544
lines changed

config/checkstyle/checkstyle.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
org.mockserver.model.HttpRequest.*,
4040
org.mockserver.model.HttpResponse.*,
4141
org.rnorth.ducttape.unreliables.Unreliables.*,
42-
org.rnorth.visibleassertions.VisibleAssertions.*,
4342
"
4443
/>
4544
</module>

core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ dependencies {
9797
// Synthetic JAR used for MountableFileTest and DirectoryTarResourceTest
9898
testImplementation files('testlib/repo/fakejar/fakejar/0/fakejar-0.jar')
9999

100-
testImplementation 'org.rnorth.visible-assertions:visible-assertions:2.1.2'
101100
testImplementation 'org.assertj:assertj-core:3.23.1'
102101
testImplementation project(':test-support')
103102

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

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

33
import org.junit.Test;
4-
import org.rnorth.visibleassertions.VisibleAssertions;
54
import org.testcontainers.containers.GenericContainer;
65

76
import java.io.File;
87
import java.util.HashSet;
98
import java.util.Set;
109
import java.util.stream.Collectors;
1110

12-
import static org.junit.Assert.assertEquals;
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
import static org.assertj.core.api.Assertions.fail;
1313

1414
/**
1515
* This test forks a new JVM, otherwise it's not possible to reliably diff the threads
@@ -30,17 +30,13 @@ public static void main(String[] args) {
3030

3131
Set<Thread> nonDaemonThreads = threads.stream().filter(it -> !it.isDaemon()).collect(Collectors.toSet());
3232

33-
if (nonDaemonThreads.isEmpty()) {
34-
VisibleAssertions.pass("All threads marked as daemon");
35-
} else {
33+
if (!nonDaemonThreads.isEmpty()) {
3634
String nonDaemonThreadNames = nonDaemonThreads
3735
.stream()
3836
.map(Thread::getName)
3937
.collect(Collectors.joining("\n", "\n", ""));
4038

41-
VisibleAssertions.fail(
42-
"Expected all threads to be daemons but the following are not:\n" + nonDaemonThreadNames
43-
);
39+
fail("Expected all threads to be daemons but the following are not:\n" + nonDaemonThreadNames);
4440
}
4541
} finally {
4642
if (genericContainer != null) {
@@ -59,6 +55,6 @@ public void testThatAllThreadsAreDaemons() throws Exception {
5955
DaemonTest.class.getCanonicalName()
6056
);
6157

62-
assertEquals(0, processBuilder.inheritIO().start().waitFor());
58+
assertThat(processBuilder.inheritIO().start().waitFor()).isZero();
6359
}
6460
}

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

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

3-
import org.assertj.core.api.Assertions;
43
import org.junit.Test;
54
import org.junit.runner.RunWith;
65
import org.junit.runners.Parameterized;
76

87
import java.util.Collections;
98
import java.util.List;
109

10+
import static org.assertj.core.api.Assertions.assertThat;
1111
import static org.mockito.Mockito.doCallRealMethod;
1212
import static org.mockito.Mockito.mock;
1313
import static org.mockito.Mockito.when;
@@ -44,6 +44,6 @@ public void test() {
4444
when(containerState.getPortBindings()).thenReturn(Collections.singletonList(testSet));
4545

4646
List<Integer> result = containerState.getBoundPortNumbers();
47-
Assertions.assertThat(result).hasSameElementsAs(expectedResult);
47+
assertThat(result).hasSameElementsAs(expectedResult);
4848
}
4949
}

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

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

33
import org.junit.Test;
4+
import org.rnorth.ducttape.TimeoutException;
45
import org.testcontainers.containers.wait.strategy.Wait;
56

67
import java.io.File;
@@ -9,8 +10,8 @@
910
import java.util.stream.Collectors;
1011
import java.util.stream.Stream;
1112

12-
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
13-
import static org.rnorth.visibleassertions.VisibleAssertions.assertThrows;
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
import static org.assertj.core.api.Assertions.catchThrowable;
1415

1516
public class DockerComposeContainerWithServicesTest {
1617

@@ -92,10 +93,8 @@ public void testScaleInComposeFileIsRespected() {
9293

9394
@Test
9495
public void testStartupTimeoutSetsTheHighestTimeout() {
95-
assertThrows(
96-
"We expect a timeout from the startup timeout",
97-
org.rnorth.ducttape.TimeoutException.class,
98-
() -> {
96+
assertThat(
97+
catchThrowable(() -> {
9998
try (
10099
DockerComposeContainer<?> compose = new DockerComposeContainer<>(SIMPLE_COMPOSE_FILE)
101100
.withServices("redis")
@@ -108,8 +107,10 @@ public void testStartupTimeoutSetsTheHighestTimeout() {
108107
) {
109108
compose.start();
110109
}
111-
}
112-
);
110+
})
111+
)
112+
.as("We expect a timeout from the startup timeout")
113+
.isInstanceOf(TimeoutException.class);
113114
}
114115

115116
private void verifyStartedContainers(final DockerComposeContainer<?> compose, final String... names) {
@@ -119,16 +120,16 @@ private void verifyStartedContainers(final DockerComposeContainer<?> compose, fi
119120
.flatMap(container -> Stream.of(container.getNames()))
120121
.collect(Collectors.toList());
121122

122-
assertEquals(
123-
"number of running services of docker-compose is the same as length of listOfServices",
124-
names.length,
125-
containerNames.size()
126-
);
123+
assertThat(containerNames)
124+
.as("number of running services of docker-compose is the same as length of listOfServices")
125+
.hasSize(names.length);
127126

128127
for (final String expectedName : names) {
129128
final long matches = containerNames.stream().filter(foundName -> foundName.endsWith(expectedName)).count();
130129

131-
assertEquals("container with name starting '" + expectedName + "' should be running", 1L, matches);
130+
assertThat(matches)
131+
.as("container with name starting '" + expectedName + "' should be running")
132+
.isEqualTo(1L);
132133
}
133134
}
134135
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package org.testcontainers.containers;
22

33
import com.google.common.collect.Lists;
4-
import org.assertj.core.api.Assertions;
54
import org.junit.Test;
65

76
import java.io.File;
87

8+
import static org.assertj.core.api.Assertions.assertThat;
9+
910
public class DockerComposeFilesTest {
1011

1112
@Test
1213
public void shouldGetDependencyImages() {
1314
DockerComposeFiles dockerComposeFiles = new DockerComposeFiles(
1415
Lists.newArrayList(new File("src/test/resources/docker-compose-imagename-parsing-v2.yml"))
1516
);
16-
Assertions
17-
.assertThat(dockerComposeFiles.getDependencyImages())
17+
assertThat(dockerComposeFiles.getDependencyImages())
1818
.containsExactlyInAnyOrder("postgres:latest", "redis:latest", "mysql:latest");
1919
}
2020

@@ -26,8 +26,7 @@ public void shouldGetDependencyImagesWhenOverriding() {
2626
new File("src/test/resources/docker-compose-imagename-overriding-b.yml")
2727
)
2828
);
29-
Assertions
30-
.assertThat(dockerComposeFiles.getDependencyImages())
29+
assertThat(dockerComposeFiles.getDependencyImages())
3130
.containsExactlyInAnyOrder("alpine:3.16", "redis:b", "mysql:b", "aservice:latest");
3231
}
3332
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
import java.util.Arrays;
1717
import java.util.concurrent.TimeUnit;
1818

19-
import static org.rnorth.visibleassertions.VisibleAssertions.info;
20-
import static org.rnorth.visibleassertions.VisibleAssertions.pass;
21-
2219
@RunWith(Parameterized.class)
2320
public class DockerComposeOverridesTest {
2421

@@ -100,11 +97,9 @@ public void test() {
10097
while (br.ready()) {
10198
String line = br.readLine();
10299
if (line.contains(expectedEnvVar)) {
103-
pass("Mapped environment variable was found");
104100
return true;
105101
}
106102
}
107-
info("Mapped environment variable was not found yet - process probably not ready");
108103
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
109104
return false;
110105
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.io.OutputStream;
1414
import java.net.InetSocketAddress;
1515

16-
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
16+
import static org.assertj.core.api.Assertions.assertThat;
1717

1818
public class ExposedHostTest {
1919

@@ -95,7 +95,7 @@ protected void assertResponse(GenericContainer<?> container, int port) {
9595
.execInContainer("wget", "-O", "-", "http://host.testcontainers.internal:" + port)
9696
.getStdout();
9797

98-
assertEquals("received response", "Hello World!", response);
98+
assertThat(response).as("received response").isEqualTo("Hello World!");
9999
} finally {
100100
container.stop();
101101
}

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.github.dockerjava.api.model.ExposedPort;
77
import com.github.dockerjava.api.model.Info;
88
import com.github.dockerjava.api.model.Ports;
9-
import com.google.common.primitives.Ints;
109
import lombok.RequiredArgsConstructor;
1110
import lombok.SneakyThrows;
1211
import lombok.experimental.FieldDefaults;
@@ -30,10 +29,9 @@
3029
import java.util.function.Predicate;
3130
import java.util.stream.Collectors;
3231

32+
import static org.assertj.core.api.Assertions.assertThat;
3333
import static org.assertj.core.api.Assertions.assertThatThrownBy;
34-
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
35-
import static org.rnorth.visibleassertions.VisibleAssertions.assertThrows;
36-
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
34+
import static org.assertj.core.api.Assertions.catchThrowable;
3735

3836
public class GenericContainerTest {
3937

@@ -119,28 +117,20 @@ public void shouldOnlyPublishExposedPorts() {
119117
.map(ExposedPort::getPort)
120118
.collect(Collectors.toList());
121119

122-
assertEquals(
123-
"the exposed ports are all of those EXPOSEd by the image",
124-
Ints.asList(8080, 8081),
125-
exposedPorts
126-
);
120+
assertThat(exposedPorts).as("the exposed ports are all of those EXPOSEd by the image").contains(8080, 8081);
127121

128122
Map<ExposedPort, Ports.Binding[]> hostBindings = inspectedContainer
129123
.getHostConfig()
130124
.getPortBindings()
131125
.getBindings();
132-
assertEquals("only 1 port is bound on the host (published)", 1, hostBindings.size());
126+
assertThat(hostBindings).as("only 1 port is bound on the host (published)").hasSize(1);
133127

134128
Integer mappedPort = container.getMappedPort(8080);
135-
assertTrue("port 8080 is bound to a different port on the host", mappedPort != 8080);
129+
assertThat(mappedPort != 8080).as("port 8080 is bound to a different port on the host").isTrue();
136130

137-
assertThrows(
138-
"trying to get a non-bound port mapping fails",
139-
IllegalArgumentException.class,
140-
() -> {
141-
container.getMappedPort(8081);
142-
}
143-
);
131+
assertThat(catchThrowable(() -> container.getMappedPort(8081)))
132+
.as("trying to get a non-bound port mapping fails")
133+
.isInstanceOf(IllegalArgumentException.class);
144134
}
145135
}
146136

@@ -161,8 +151,8 @@ public void shouldWaitUntilExposedPortIsMapped() {
161151
) {
162152
container.start();
163153

164-
assertEquals("Only withExposedPort should be exposed", 1, container.getExposedPorts().size());
165-
assertTrue("withExposedPort should be exposed", container.getExposedPorts().contains(8080));
154+
assertThat(container.getExposedPorts()).as("Only withExposedPort should be exposed").hasSize(1);
155+
assertThat(container.getExposedPorts()).as("withExposedPort should be exposed").contains(8080);
166156
}
167157
}
168158

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import org.testcontainers.DockerClientFactory;
88
import org.testcontainers.TestImages;
99

10-
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
11-
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotEquals;
12-
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotNull;
10+
import static org.assertj.core.api.Assertions.assertThat;
1311

1412
@RunWith(Enclosed.class)
1513
public class NetworkTest {
@@ -33,7 +31,7 @@ public static class WithRules {
3331
@Test
3432
public void testNetworkSupport() throws Exception {
3533
String response = bar.execInContainer("wget", "-O", "-", "http://foo:8080").getStdout();
36-
assertEquals("received response", "yay", response);
34+
assertThat(response).as("received response").isEqualTo("yay");
3735
}
3836
}
3937

@@ -60,7 +58,7 @@ public void testNetworkSupport() throws Exception {
6058
bar.start();
6159

6260
String response = bar.execInContainer("wget", "-O", "-", "http://foo:8080").getStdout();
63-
assertEquals("received response", "yay", response);
61+
assertThat(response).as("received response").isEqualTo("yay");
6462
}
6563
// }
6664
}
@@ -69,11 +67,11 @@ public void testNetworkSupport() throws Exception {
6967
public void testBuilder() {
7068
try (Network network = Network.builder().driver("macvlan").build()) {
7169
String id = network.getId();
72-
assertEquals(
73-
"Flag is set",
74-
"macvlan",
70+
assertThat(
7571
DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(id).exec().getDriver()
76-
);
72+
)
73+
.as("Flag is set")
74+
.isEqualTo("macvlan");
7775
}
7876
}
7977

@@ -83,36 +81,35 @@ public void testModifiers() {
8381
Network network = Network.builder().createNetworkCmdModifier(cmd -> cmd.withDriver("macvlan")).build()
8482
) {
8583
String id = network.getId();
86-
assertEquals(
87-
"Flag is set",
88-
"macvlan",
84+
assertThat(
8985
DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(id).exec().getDriver()
90-
);
86+
)
87+
.as("Flag is set")
88+
.isEqualTo("macvlan");
9189
}
9290
}
9391

9492
@Test
9593
public void testReusability() {
9694
try (Network network = Network.newNetwork()) {
9795
String firstId = network.getId();
98-
assertNotNull(
99-
"Network exists",
100-
DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(firstId).exec()
101-
);
96+
assertThat(DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(firstId).exec())
97+
.as("Network exists")
98+
.isNotNull();
10299

103100
network.close();
104101

105-
assertNotEquals(
106-
"New network created",
107-
firstId,
102+
assertThat(
108103
DockerClientFactory
109104
.instance()
110105
.client()
111106
.inspectNetworkCmd()
112107
.withNetworkId(network.getId())
113108
.exec()
114109
.getId()
115-
);
110+
)
111+
.as("New network created")
112+
.isNotEqualTo(firstId);
116113
}
117114
}
118115
}

0 commit comments

Comments
 (0)