Skip to content

Commit 1c6a65c

Browse files
Excavator: Prefer AssertJ (#739)
1 parent 6b9becb commit 1c6a65c

38 files changed

+235
-261
lines changed

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/AggressiveShutdownStrategyIntegrationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
package com.palantir.docker.compose;
1818

19-
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.hamcrest.Matchers.is;
19+
import static org.assertj.core.api.Assertions.assertThat;
2120

2221
import com.palantir.docker.compose.configuration.ShutdownStrategy;
2322
import com.palantir.docker.compose.logging.DoNothingLogCollector;
24-
import org.hamcrest.MatcherAssert;
25-
import org.hamcrest.Matchers;
2623
import org.junit.Test;
2724

2825
public class AggressiveShutdownStrategyIntegrationTest {
@@ -36,12 +33,12 @@ public void shut_down_multiple_containers_immediately() throws Exception {
3633
.shutdownStrategy(ShutdownStrategy.AGGRESSIVE)
3734
.build();
3835

39-
MatcherAssert.assertThat(docker.dockerCompose().ps(), Matchers.is(TestContainerNames.of()));
36+
assertThat(docker.dockerCompose().ps()).isEqualTo(TestContainerNames.of());
4037

4138
docker.before();
42-
assertThat(docker.dockerCompose().ps().size(), is(2));
39+
assertThat(docker.dockerCompose().ps().size()).isEqualTo(2);
4340
docker.after();
4441

45-
assertThat(docker.dockerCompose().ps(), is(TestContainerNames.of()));
42+
assertThat(docker.dockerCompose().ps()).isEqualTo(TestContainerNames.of());
4643
}
4744
}

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/AggressiveShutdownWithNetworkCleanupStrategyIntegrationTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.palantir.docker.compose;
1818

19-
import static org.hamcrest.MatcherAssert.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.hamcrest.Matchers.is;
2121
import static org.hamcrest.Matchers.not;
2222

@@ -25,6 +25,7 @@
2525
import java.util.Arrays;
2626
import java.util.HashSet;
2727
import java.util.Set;
28+
import org.assertj.core.api.HamcrestCondition;
2829
import org.junit.Ignore;
2930
import org.junit.Test;
3031

@@ -39,13 +40,13 @@ public class AggressiveShutdownWithNetworkCleanupStrategyIntegrationTest {
3940

4041
@Test
4142
public void shut_down_multiple_containers_immediately() throws Exception {
42-
assertThat(docker.dockerCompose().ps(), is(TestContainerNames.of()));
43+
assertThat(docker.dockerCompose().ps()).isEqualTo(TestContainerNames.of());
4344

4445
docker.before();
45-
assertThat(docker.dockerCompose().ps().size(), is(2));
46+
assertThat(docker.dockerCompose().ps().size()).isEqualTo(2);
4647
docker.after();
4748

48-
assertThat(docker.dockerCompose().ps(), is(TestContainerNames.of()));
49+
assertThat(docker.dockerCompose().ps()).isEqualTo(TestContainerNames.of());
4950
}
5051

5152
@Test
@@ -56,10 +57,11 @@ public void clean_up_created_networks_when_shutting_down() throws Exception {
5657
parseLinesFromOutputString(docker.docker().listNetworks());
5758

5859
docker.before();
59-
assertThat(parseLinesFromOutputString(docker.docker().listNetworks()), is(not(networksBeforeRun)));
60+
assertThat(parseLinesFromOutputString(docker.docker().listNetworks()))
61+
.is(new HamcrestCondition<>(is(not(networksBeforeRun))));
6062
docker.after();
6163

62-
assertThat(parseLinesFromOutputString(docker.docker().listNetworks()), is(networksBeforeRun));
64+
assertThat(parseLinesFromOutputString(docker.docker().listNetworks())).isEqualTo(networksBeforeRun);
6365
}
6466

6567
private static Set<String> parseLinesFromOutputString(String output) {

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/DockerComposeManagerNativeHealthcheckIntegrationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly;
2020
import static com.palantir.docker.compose.execution.DockerComposeExecArgument.arguments;
2121
import static com.palantir.docker.compose.execution.DockerComposeExecOption.noOptions;
22+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2223
import static org.awaitility.Awaitility.await;
23-
import static org.junit.Assert.fail;
2424

2525
import com.palantir.docker.compose.connection.Container;
2626
import com.palantir.docker.compose.connection.State;
@@ -63,12 +63,9 @@ public void dockerComposeManagerWaitsUntilHealthcheckPasses()
6363
await().until(container::state, Matchers.equalTo(State.UNHEALTHY));
6464

6565
// The "withHealthCheck" container should not initially pass its healthcheck
66-
try {
67-
getUninterruptibly(beforeFuture, 1, TimeUnit.SECONDS);
68-
fail("Expected before() to wait");
69-
} catch (TimeoutException e) {
70-
// Expected
71-
}
66+
assertThatThrownBy(() -> getUninterruptibly(beforeFuture, 1, TimeUnit.SECONDS))
67+
.describedAs("Expected before() to wait")
68+
.isInstanceOf(TimeoutException.class);
7269

7370
// Touching the "healthy" file in the "withHealthCheck" container should make its healthcheck pass
7471
docker.dockerCompose().exec(noOptions(), "withHealthcheck", arguments("touch", "healthy"));

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/DockerComposeManagerUpContainerIntegrationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import static com.palantir.docker.compose.configuration.ShutdownStrategy.AGGRESSIVE;
2020
import static com.palantir.docker.compose.connection.waiting.ClusterHealthCheck.serviceHealthCheck;
2121
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toHaveAllPortsOpen;
22-
import static org.hamcrest.MatcherAssert.assertThat;
23-
import static org.hamcrest.core.Is.is;
22+
import static org.assertj.core.api.Assertions.assertThat;
2423

2524
import com.palantir.docker.compose.connection.Container;
2625
import com.palantir.docker.compose.connection.State;
@@ -51,7 +50,7 @@ public void test_docker_compose_manager_up_container() throws IOException, Inter
5150

5251
container.up();
5352

54-
assertThat(container.state(), is(State.HEALTHY));
53+
assertThat(container.state()).isEqualTo(State.HEALTHY);
5554
}
5655

5756
@Test
@@ -64,6 +63,6 @@ public void test_docker_compose_manager_up_container_with_healthcheck() throws I
6463
new ClusterWait(serviceHealthCheck(SERVICE_NAME, toHaveAllPortsOpen()), Duration.standardSeconds(5))
6564
.waitUntilReady(dockerComposeManager.containers());
6665

67-
assertThat(container.state(), is(State.HEALTHY));
66+
assertThat(container.state()).isEqualTo(State.HEALTHY);
6867
}
6968
}

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/EventsIntegrationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.palantir.docker.compose;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.assertj.core.api.Assertions.fail;
20+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2121
import static org.mockito.Mockito.atLeastOnce;
2222
import static org.mockito.Mockito.mock;
2323
import static org.mockito.Mockito.verify;
@@ -87,12 +87,9 @@ public void produces_events_when_a_container_healthcheck_exceeds_its_timeout() {
8787
.addEventConsumer(eventConsumer)
8888
.build();
8989

90-
try {
91-
runDockerComposeRule(dockerComposeManager);
92-
fail("Was expecting an exception");
93-
} catch (Throwable t) {
94-
// ignore the failure
95-
}
90+
assertThatThrownBy(() -> runDockerComposeRule(dockerComposeManager))
91+
.describedAs("Was expecting an exception")
92+
.isInstanceOf(Throwable.class);
9693

9794
List<Event> events = getEvents();
9895

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/HostNetworkedPortsIntegrationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package com.palantir.docker.compose;
1818

19-
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.hamcrest.core.Is.is;
19+
import static org.assertj.core.api.Assertions.assertThat;
2120
import static org.junit.Assume.assumeTrue;
2221

2322
import com.palantir.docker.compose.connection.DockerPort;
@@ -48,8 +47,8 @@ public void can_access_host_networked_ports() throws Exception {
4847
.build();
4948
try {
5049
docker.before();
51-
assertThat(docker.hostNetworkedPort(5432).getInternalPort(), is(5432));
52-
assertThat(docker.hostNetworkedPort(5432).getExternalPort(), is(5432));
50+
assertThat(docker.hostNetworkedPort(5432).getInternalPort()).isEqualTo(5432);
51+
assertThat(docker.hostNetworkedPort(5432).getExternalPort()).isEqualTo(5432);
5352
} finally {
5453
docker.after();
5554
}

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/connection/ContainerIntegrationTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import static com.palantir.docker.compose.execution.DockerComposeExecArgument.arguments;
2020
import static com.palantir.docker.compose.execution.DockerComposeExecOption.noOptions;
21+
import static org.assertj.core.api.Assertions.assertThat;
2122
import static org.awaitility.Awaitility.await;
2223
import static org.hamcrest.Matchers.equalTo;
23-
import static org.junit.Assert.assertEquals;
2424

2525
import com.palantir.docker.compose.configuration.DockerComposeFiles;
2626
import com.palantir.docker.compose.configuration.ProjectName;
@@ -31,7 +31,6 @@
3131
import java.io.IOException;
3232
import java.time.Duration;
3333
import org.awaitility.core.ConditionFactory;
34-
import org.junit.Assert;
3534
import org.junit.Test;
3635

3736
public class ContainerIntegrationTests {
@@ -49,11 +48,11 @@ public void testStateChanges_withoutHealthCheck() throws IOException, Interrupte
4948

5049
// The noHealthcheck service has no healthcheck specified; it should be immediately healthy
5150
Container container = new Container("noHealthcheck", docker, dockerCompose);
52-
Assert.assertEquals(State.DOWN, container.state());
51+
assertThat(container.state()).isEqualTo(State.DOWN);
5352
container.up();
54-
assertEquals(State.HEALTHY, container.state());
53+
assertThat(container.state()).isEqualTo(State.HEALTHY);
5554
container.kill();
56-
assertEquals(State.DOWN, container.state());
55+
assertThat(container.state()).isEqualTo(State.DOWN);
5756
}
5857

5958
@Test
@@ -65,14 +64,14 @@ public void testStateChanges_withHealthCheck() throws IOException, InterruptedEx
6564

6665
// The withHealthcheck service's healthcheck checks every 100ms whether the file "healthy" exists
6766
Container container = new Container("withHealthcheck", docker, dockerCompose);
68-
assertEquals(State.DOWN, container.state());
67+
assertThat(container.state()).isEqualTo(State.DOWN);
6968
container.up();
70-
assertEquals(State.UNHEALTHY, container.state());
69+
assertThat(container.state()).isEqualTo(State.UNHEALTHY);
7170
dockerCompose.exec(noOptions(), "withHealthcheck", arguments("touch", "healthy"));
7271
wait.until(container::state, equalTo(State.HEALTHY));
7372
dockerCompose.exec(noOptions(), "withHealthcheck", arguments("rm", "healthy"));
7473
wait.until(container::state, equalTo(State.UNHEALTHY));
7574
container.kill();
76-
assertEquals(State.DOWN, container.state());
75+
assertThat(container.state()).isEqualTo(State.DOWN);
7776
}
7877
}

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/execution/EnvironmentVariableIntegrationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toHaveAllPortsOpen;
1919
import static com.palantir.docker.compose.matchers.IoMatchers.fileContainingString;
20-
import static org.hamcrest.MatcherAssert.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.hamcrest.Matchers.is;
2222

2323
import com.palantir.docker.compose.DockerComposeManager;
2424
import com.palantir.docker.compose.connection.DockerMachine;
2525
import java.nio.file.Path;
26+
import org.assertj.core.api.HamcrestCondition;
2627
import org.junit.Rule;
2728
import org.junit.Test;
2829
import org.junit.rules.TemporaryFolder;
@@ -54,6 +55,7 @@ public void docker_compose_gets_environment_variables_from_docker_machine_and_pa
5455

5556
Path logLocation = temporaryFolder.getRoot().toPath().resolve("env-test.log");
5657

57-
assertThat(logLocation.toFile(), is(fileContainingString("SOME_VARIABLE=SOME_VALUE")));
58+
assertThat(logLocation.toFile())
59+
.is(new HamcrestCondition<>(is(fileContainingString("SOME_VARIABLE=SOME_VALUE"))));
5860
}
5961
}

docker-compose-rule-core/src/integrationTest/java/com/palantir/docker/compose/logging/LoggingIntegrationTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toHaveAllPortsOpen;
1919
import static com.palantir.docker.compose.matchers.IoMatchers.fileWithConents;
2020
import static com.palantir.docker.compose.matchers.IoMatchers.matchingPattern;
21-
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.assertj.core.api.Assertions.assertThat;
2222
import static org.hamcrest.core.Is.is;
2323

2424
import com.palantir.docker.compose.DockerComposeManager;
2525
import java.io.File;
2626
import java.io.IOException;
27+
import org.assertj.core.api.HamcrestCondition;
2728
import org.junit.Before;
2829
import org.junit.Rule;
2930
import org.junit.Test;
@@ -53,11 +54,9 @@ public void logs_can_be_saved_to_a_directory() throws IOException, InterruptedEx
5354
} finally {
5455
dockerComposeRule.after();
5556
}
56-
assertThat(
57-
new File(logFolder.getRoot(), "db.log"),
58-
is(fileWithConents(matchingPattern(".*db-1.*server started.*"))));
59-
assertThat(
60-
new File(logFolder.getRoot(), "db2.log"),
61-
is(fileWithConents(matchingPattern(".*db2-1.*server started.*"))));
57+
assertThat(new File(logFolder.getRoot(), "db.log"))
58+
.is(new HamcrestCondition<>(is(fileWithConents(matchingPattern(".*db-1.*server started.*")))));
59+
assertThat(new File(logFolder.getRoot(), "db2.log"))
60+
.is(new HamcrestCondition<>(is(fileWithConents(matchingPattern(".*db2-1.*server started.*")))));
6261
}
6362
}

docker-compose-rule-core/src/test/java/com/palantir/docker/compose/DockerComposeManagerShould.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toHaveAllPortsOpen;
1919
import static com.palantir.docker.compose.matchers.IoMatchers.fileContainingString;
2020
import static com.palantir.docker.compose.matchers.IoMatchers.fileWithName;
21-
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.assertj.core.api.Assertions.assertThat;
2222
import static org.hamcrest.Matchers.arrayContaining;
23-
import static org.hamcrest.Matchers.contains;
2423
import static org.hamcrest.core.Is.is;
2524
import static org.joda.time.Duration.millis;
2625
import static org.mockito.Matchers.any;
@@ -57,6 +56,7 @@
5756
import java.util.concurrent.TimeUnit;
5857
import java.util.concurrent.atomic.AtomicInteger;
5958
import org.apache.commons.io.IOUtils;
59+
import org.assertj.core.api.HamcrestCondition;
6060
import org.joda.time.Duration;
6161
import org.junit.Before;
6262
import org.junit.Rule;
@@ -144,7 +144,7 @@ public void pass_wait_for_service_when_check_is_true() throws IOException, Inter
144144
HealthCheck<Container> checkCalledOnce = _container ->
145145
SuccessOrFailure.fromBoolean(timesCheckCalled.incrementAndGet() == 1, "not called once yet");
146146
defaultBuilder().waitingForService("db", checkCalledOnce).build().before();
147-
assertThat(timesCheckCalled.get(), is(1));
147+
assertThat(timesCheckCalled.get()).isEqualTo(1);
148148
}
149149

150150
@Test
@@ -170,7 +170,7 @@ public void pass_wait_for_service_when_check_is_true_after_being_false() throws
170170
HealthCheck<Container> checkCalledTwice = _container ->
171171
SuccessOrFailure.fromBoolean(timesCheckCalled.incrementAndGet() == 2, "not called twice yet");
172172
defaultBuilder().waitingForService("db", checkCalledTwice).build().before();
173-
assertThat(timesCheckCalled.get(), is(2));
173+
assertThat(timesCheckCalled.get()).isEqualTo(2);
174174
}
175175

176176
@Test
@@ -196,7 +196,7 @@ public void retrieve_port_for_container_by_external_mapping() throws IOException
196196
DockerPort actualPort =
197197
dockerComposeManager.containers().container("db").portMappedExternallyTo(5433);
198198

199-
assertThat(actualPort, is(expectedPort));
199+
assertThat(actualPort).isEqualTo(expectedPort);
200200
}
201201

202202
@Test
@@ -208,7 +208,7 @@ public void retrieve_port_for_container_by_internal_mapping() throws IOException
208208
DockerPort actualPort =
209209
dockerComposeManager.containers().container("db").portMappedInternallyTo(5432);
210210

211-
assertThat(actualPort, is(expectedPort));
211+
assertThat(actualPort).isEqualTo(expectedPort);
212212
}
213213

214214
@Test
@@ -263,9 +263,9 @@ public void be_able_to_save_logs_to_a_directory_while_containers_are_running()
263263
});
264264
loggingComposition.before();
265265
loggingComposition.after();
266-
assertThat(latch.await(1, TimeUnit.SECONDS), is(true));
267-
assertThat(logLocation.listFiles(), arrayContaining(fileWithName("db.log")));
268-
assertThat(new File(logLocation, "db.log"), is(fileContainingString("db log")));
266+
assertThat(latch.await(1, TimeUnit.SECONDS)).isEqualTo(true);
267+
assertThat(logLocation.listFiles()).is(new HamcrestCondition<>(arrayContaining(fileWithName("db.log"))));
268+
assertThat(new File(logLocation, "db.log")).is(new HamcrestCondition<>(is(fileContainingString("db log"))));
269269
}
270270

271271
@Test
@@ -332,7 +332,7 @@ public void union_cluster_waits_from_builder_instead_of_overwriting() {
332332
.clusterWaits(ImmutableList.of(secondWait))
333333
.build();
334334

335-
assertThat(twoAssignments.clusterWaits(), contains(firstWait, secondWait));
335+
assertThat(twoAssignments.clusterWaits()).containsExactly(firstWait, secondWait);
336336
}
337337

338338
@Test

0 commit comments

Comments
 (0)