Skip to content

Commit 6782d43

Browse files
committed
Moving to Junit5 for the most of the project, since Spring Boot 2.4.x is now based on it. But we have to include vintage-engine also for the TestContainers DockerCompose module, since without the ClassRule (which is bound to Junit 4) the test is not running, because containers aren't spun up correctly...
1 parent 18a3b75 commit 6782d43

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

client-bob/src/test/java/de/jonashackt/BobTest.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package de.jonashackt;
22

3-
import org.junit.Ignore;
4-
import org.junit.Test;
5-
import org.junit.runner.RunWith;
6-
import org.springframework.beans.factory.annotation.Autowired;
3+
import org.junit.jupiter.api.Disabled;
4+
import org.junit.jupiter.api.Test;
75
import org.springframework.boot.test.context.SpringBootTest;
86
import org.springframework.boot.web.server.LocalServerPort;
9-
import org.springframework.test.context.junit4.SpringRunner;
107
import org.springframework.web.client.RestTemplate;
118

9+
import static org.hamcrest.MatcherAssert.assertThat;
1210
import static org.hamcrest.Matchers.containsString;
13-
import static org.junit.Assert.assertThat;
1411

15-
@RunWith(SpringRunner.class)
1612
@SpringBootTest(
1713
classes = BobApplication.class,
1814
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
@@ -22,10 +18,9 @@ public class BobTest {
2218
@LocalServerPort
2319
private int port;
2420

25-
@Autowired
26-
private RestTemplate restTemplate;
21+
private RestTemplate restTemplate = new RestTemplate();
2722

28-
@Ignore("no localhost support, because without Docker we would need to bind the same Port 8443 of server-alice and server-tom two times, which isn´t possible")
23+
@Disabled("no localhost support, because without Docker we would need to bind the same Port 8443 of server-alice and server-tom two times, which isn´t possible")
2924
@Test
3025
public void is_hello_resource_callable_with_client_cert() {
3126
String response = restTemplate.getForObject("https://localhost:" + port + "/secretservers", String.class);

docker-network-client/pom.xml

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
<scope>test</scope>
4848
</dependency>
4949

50+
<!-- Needed to run TestContainers in using the DockerCompose module https://www.testcontainers.org/modules/docker_compose/
51+
but together with a Spring Boot 2.4.x based project, which uses JUnit 5 - but Testcontainers ClassRule for Docker Compose
52+
is bound to Junit4 currently -->
53+
<dependency>
54+
<groupId>org.junit.vintage</groupId>
55+
<artifactId>junit-vintage-engine</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
5059
</dependencies>
5160

5261
</project>

docker-network-client/src/test/resources/testcontainers.properties

-1
This file was deleted.

server-alice/src/test/java/de/jonashackt/RestClientCertTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package de.jonashackt;
22

33
import de.jonashackt.controller.ServerAliceController;
4-
import org.junit.Test;
5-
import org.junit.runner.RunWith;
4+
import org.junit.jupiter.api.Test;
65
import org.springframework.beans.factory.annotation.Autowired;
76
import org.springframework.boot.test.context.SpringBootTest;
87
import org.springframework.boot.web.server.LocalServerPort;
98
import org.springframework.test.context.junit4.SpringRunner;
109
import org.springframework.web.client.RestTemplate;
1110

12-
import static org.junit.Assert.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
1313

14-
@RunWith(SpringRunner.class)
1514
@SpringBootTest(
1615
classes = ServerAliceApplication.class,
1716
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT

server-tom/src/test/java/de/jonashackt/RestClientCertTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package de.jonashackt;
22

33
import de.jonashackt.controller.ServerTomController;
4-
import org.junit.Test;
5-
import org.junit.runner.RunWith;
4+
5+
import org.junit.jupiter.api.Test;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.boot.test.context.SpringBootTest;
88
import org.springframework.boot.web.server.LocalServerPort;
99
import org.springframework.test.context.junit4.SpringRunner;
1010
import org.springframework.web.client.RestTemplate;
1111

12-
import static org.junit.Assert.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
1314

14-
@RunWith(SpringRunner.class)
1515
@SpringBootTest(
1616
classes = ServerTomApplication.class,
1717
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT

0 commit comments

Comments
 (0)