Skip to content

Commit 900c325

Browse files
committed
Polish "Add JUnit 4 and the Vintage Engine sample"
See gh-17100
1 parent 9fafcda commit 900c325

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,6 @@
2323
<groupId>org.springframework.boot</groupId>
2424
<artifactId>spring-boot-starter-test</artifactId>
2525
<scope>test</scope>
26-
<exclusions>
27-
<exclusion>
28-
<groupId>org.junit.jupiter</groupId>
29-
<artifactId>junit-jupiter</artifactId>
30-
</exclusion>
31-
<exclusion>
32-
<groupId>org.mockito</groupId>
33-
<artifactId>mockito-junit-jupiter</artifactId>
34-
</exclusion>
35-
</exclusions>
3626
</dependency>
3727
</dependencies>
38-
<build>
39-
<plugins>
40-
<plugin>
41-
<groupId>org.springframework.boot</groupId>
42-
<artifactId>spring-boot-maven-plugin</artifactId>
43-
</plugin>
44-
<plugin>
45-
<groupId>org.apache.maven.plugins</groupId>
46-
<artifactId>maven-surefire-plugin</artifactId>
47-
</plugin>
48-
</plugins>
49-
</build>
5028
</project>

spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.springframework.web.bind.annotation.RestController;
2121

2222
@RestController
23-
public class MessageController {
23+
class MessageController {
2424

2525
@GetMapping("/hi")
2626
public String hello() {

spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJunitVintageApplicationTests.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@
2020
import org.junit.runner.RunWith;
2121

2222
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.test.context.SpringBootTest;
24-
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25-
import org.springframework.boot.test.web.client.TestRestTemplate;
23+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
2624
import org.springframework.test.context.junit4.SpringRunner;
25+
import org.springframework.test.web.servlet.MockMvc;
2726

28-
import static org.assertj.core.api.Assertions.assertThat;
27+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
28+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
2929

3030
@RunWith(SpringRunner.class)
31-
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
31+
@WebMvcTest
3232
public class SampleJunitVintageApplicationTests {
3333

3434
@Autowired
35-
private TestRestTemplate restTemplate;
35+
private MockMvc mockMvc;
3636

3737
@Test
38-
public void testMessage() {
39-
String message = this.restTemplate.getForObject("/hi", String.class);
40-
assertThat(message).isEqualTo("Hello World");
38+
public void testMessage() throws Exception {
39+
this.mockMvc.perform(get("/hi")).andExpect(content().string("Hello World"));
4140
}
4241

4342
}

0 commit comments

Comments
 (0)