Skip to content

Commit 4194bdd

Browse files
Excavator: Switch to JUnit 5 to parallelize tests and speed up CI
1 parent 8a90432 commit 4194bdd

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

docker-proxy-rule-core/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ dependencies {
1010
testImplementation group: 'org.assertj', name: 'assertj-core'
1111
testImplementation group: 'org.mockito', name: 'mockito-core'
1212
testRuntimeOnly group: 'org.mockito', name: 'mockito-inline'
13+
testImplementation 'org.junit.jupiter:junit-jupiter'
14+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
15+
because 'allows JUnit 3 and JUnit 4 tests to run'
16+
}
1317
}
1418

1519
moduleJvmArgs {

docker-proxy-rule-core/src/test/java/com/palantir/docker/proxy/DockerContainerInfoUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.nio.charset.StandardCharsets;
3131
import java.util.Optional;
3232
import java.util.concurrent.TimeUnit;
33-
import org.junit.Test;
33+
import org.junit.jupiter.api.Test;
3434

3535
public class DockerContainerInfoUtilsTest {
3636
private static final String CONTAINER_ID = "container-id";

docker-proxy-rule-core/src/test/java/com/palantir/docker/proxy/DockerNameServiceTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import java.net.InetAddress;
2626
import java.net.UnknownHostException;
2727
import java.util.Optional;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Assertions;
29+
import org.junit.jupiter.api.Test;
2930

3031
public class DockerNameServiceTest {
3132
private static final String HOST_NAME = "host";
@@ -63,11 +64,13 @@ public void shouldGetIpOfHostFromSupplierEveryTime() throws UnknownHostException
6364
verify(containerInfo, times(2)).getIpForHost(HOST_NAME);
6465
}
6566

66-
@Test(expected = UnknownHostException.class)
67+
@Test
6768
public void shouldThrowUnknownHostExceptionWhenNoIpForHost() throws UnknownHostException {
68-
when(containerInfo.getIpForHost(HOST_NAME)).thenReturn(Optional.empty());
69+
Assertions.assertThrows(UnknownHostException.class, () -> {
70+
when(containerInfo.getIpForHost(HOST_NAME)).thenReturn(Optional.empty());
6971

70-
dockerNameService.lookupAllHostAddr(HOST_NAME);
72+
dockerNameService.lookupAllHostAddr(HOST_NAME);
73+
});
7174
}
7275

7376
@Test
@@ -98,10 +101,12 @@ public void shouldGetHostOfIpFromSupplierEveryTime() throws UnknownHostException
98101
verify(containerInfo, times(2)).getHostForIp(HOST_IP);
99102
}
100103

101-
@Test(expected = UnknownHostException.class)
104+
@Test
102105
public void shouldThrowUnknownHostExceptionWhenNoHostForIp() throws UnknownHostException {
103-
when(containerInfo.getHostForIp(HOST_IP)).thenReturn(Optional.empty());
106+
Assertions.assertThrows(UnknownHostException.class, () -> {
107+
when(containerInfo.getHostForIp(HOST_IP)).thenReturn(Optional.empty());
104108

105-
dockerNameService.getHostByAddr(HOST_IP_INET.getAddress());
109+
dockerNameService.getHostByAddr(HOST_IP_INET.getAddress());
110+
});
106111
}
107112
}

docker-proxy-rule-core/src/test/java/com/palantir/docker/proxy/DockerProxySelectorTest.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
import java.net.URISyntaxException;
3939
import java.util.List;
4040
import java.util.Optional;
41-
import org.junit.Before;
42-
import org.junit.Test;
41+
import org.junit.jupiter.api.Assertions;
42+
import org.junit.jupiter.api.BeforeEach;
43+
import org.junit.jupiter.api.Test;
4344

4445
public class DockerProxySelectorTest {
4546
private static final String CLUSTER_IP = "172.17.0.1";
@@ -57,7 +58,7 @@ public class DockerProxySelectorTest {
5758
private final ProxySelector dockerProxySelector =
5859
new DockerProxySelector(setupProxyContainer(), containerInfo, originalProxySelector);
5960

60-
@Before
61+
@BeforeEach
6162
public void originalProxySelectorIsNoProxy() {
6263
when(originalProxySelector.select(any())).thenReturn(ImmutableList.of(Proxy.NO_PROXY));
6364
}
@@ -92,19 +93,25 @@ public void dockerIpsShouldGoThroughAProxy() {
9293
assertThat(selectedProxy).containsExactly(new Proxy(Proxy.Type.SOCKS, PROXY_ADDRESS));
9394
}
9495

95-
@Test(expected = IllegalArgumentException.class)
96+
@Test
9697
public void connectionFailedShouldThrowOnNullUri() {
97-
dockerProxySelector.connectFailed(null, PROXY_ADDRESS, new IOException());
98+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
99+
dockerProxySelector.connectFailed(null, PROXY_ADDRESS, new IOException());
100+
});
98101
}
99102

100-
@Test(expected = IllegalArgumentException.class)
103+
@Test
101104
public void connectionFailedShouldThrowOnNullAddress() {
102-
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, null, new IOException());
105+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
106+
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, null, new IOException());
107+
});
103108
}
104109

105-
@Test(expected = IllegalArgumentException.class)
110+
@Test
106111
public void connectionFailedShouldThrowOnNullException() {
107-
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, PROXY_ADDRESS, null);
112+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
113+
dockerProxySelector.connectFailed(TEST_HOSTNAME_URI, PROXY_ADDRESS, null);
114+
});
108115
}
109116

110117
@Test

docker-proxy-rule-junit4/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ dependencies {
1414

1515
testImplementation group: 'org.assertj', name: 'assertj-core'
1616
testImplementation group: 'org.mockito', name: 'mockito-core'
17+
integrationTestImplementation 'org.junit.jupiter:junit-jupiter'
18+
integrationTestRuntimeOnly 'org.junit.vintage:junit-vintage-engine', {
19+
because 'allows JUnit 3 and JUnit 4 tests to run'
20+
}
21+
testImplementation 'org.junit.jupiter:junit-jupiter'
1722
}

docker-proxy-rule-junit4/src/integrationTest/java/com/palantir/docker/proxy/DockerProxyRuleTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import java.net.URL;
2323
import java.net.URLConnection;
2424
import org.junit.ClassRule;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Assertions;
26+
import org.junit.jupiter.api.Test;
2627

2728
public class DockerProxyRuleTest {
2829
@ClassRule
@@ -125,9 +126,11 @@ public void otherHostnamesStillResolve() throws IOException, InterruptedExceptio
125126
}
126127
}
127128

128-
@Test(expected = IllegalStateException.class)
129+
@Test
129130
public void runningProxyRuleBeforeDockerComposeRuleFails() throws IOException, InterruptedException {
130-
DockerProxyRule.fromNetworkName("doesnotexist", DockerProxyRuleTest.class)
131-
.before();
131+
Assertions.assertThrows(IllegalStateException.class, () -> {
132+
DockerProxyRule.fromNetworkName("doesnotexist", DockerProxyRuleTest.class)
133+
.before();
134+
});
132135
}
133136
}

versions.lock

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ javax.ws.rs:javax.ws.rs-api:2.1.1 (1 constraints: f10f7399)
6464

6565
joda-time:joda-time:2.12.7 (2 constraints: 232ce739)
6666

67-
junit:junit:4.13.2 (2 constraints: 841bfe6b)
67+
junit:junit:4.13.2 (3 constraints: 332cd155)
6868

6969
one.util:streamex:0.8.1 (2 constraints: cd1a403c)
7070

7171
org.apache.commons:commons-lang3:3.7 (1 constraints: 661571a7)
7272

73-
org.apiguardian:apiguardian-api:1.1.2 (5 constraints: 105480ac)
73+
org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 896455cc)
7474

7575
org.awaitility:awaitility:4.0.2 (1 constraints: c015bbd2)
7676

@@ -84,9 +84,9 @@ org.hamcrest:hamcrest-core:2.1 (1 constraints: cc05fe3f)
8484

8585
org.junit.jupiter:junit-jupiter-api:5.8.2 (4 constraints: 0547af6b)
8686

87-
org.junit.platform:junit-platform-commons:1.8.2 (2 constraints: dd200b4b)
87+
org.junit.platform:junit-platform-commons:1.11.4 (2 constraints: 0921016c)
8888

89-
org.opentest4j:opentest4j:1.2.0 (2 constraints: cd205b49)
89+
org.opentest4j:opentest4j:1.3.0 (2 constraints: ce205e49)
9090

9191
org.slf4j:slf4j-api:1.7.36 (2 constraints: 042493b3)
9292

@@ -108,7 +108,9 @@ org.junit.jupiter:junit-jupiter-engine:5.8.2 (1 constraints: 0c0edf3b)
108108

109109
org.junit.jupiter:junit-jupiter-params:5.8.2 (1 constraints: 0c0edf3b)
110110

111-
org.junit.platform:junit-platform-engine:1.8.2 (1 constraints: ab1027b4)
111+
org.junit.platform:junit-platform-engine:1.11.4 (2 constraints: 57211695)
112+
113+
org.junit.vintage:junit-vintage-engine:5.11.4 (1 constraints: 3d05483b)
112114

113115
org.mockito:mockito-core:4.4.0 (2 constraints: f11021d5)
114116

versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ junit:junit = 4.13.2
55
one.util:streamex = 0.8.1
66
org.assertj:assertj-core = 3.22.0
77
org.junit.jupiter:* = 5.8.2
8+
org.junit.vintage:* = 5.11.4
89
org.mockito:* = 4.4.0
910
org.hamcrest:* = 2.1
1011
net.bytebuddy:* = 1.14.11

0 commit comments

Comments
 (0)