From 900c325070c77dd3100010b0df49d5dd593d1bd6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 19 Jun 2019 16:12:43 +0200 Subject: [PATCH] Polish "Add JUnit 4 and the Vintage Engine sample" See gh-17100 --- .../spring-boot-sample-junit-vintage/pom.xml | 22 ------------------- .../main/java/sample/MessageController.java | 2 +- .../SampleJunitVintageApplicationTests.java | 17 +++++++------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml b/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml index 0b5b2f1ddc..d245eb7bfa 100644 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml +++ b/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml @@ -23,28 +23,6 @@ org.springframework.boot spring-boot-starter-test test - - - org.junit.jupiter - junit-jupiter - - - org.mockito - mockito-junit-jupiter - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java b/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java index e9afd39306..f46482e8e4 100644 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java +++ b/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java @@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController -public class MessageController { +class MessageController { @GetMapping("/hi") public String hello() { diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJunitVintageApplicationTests.java b/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJunitVintageApplicationTests.java index 3bba75a8a4..3f23fc5185 100644 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJunitVintageApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJunitVintageApplicationTests.java @@ -20,24 +20,23 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; -import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@WebMvcTest public class SampleJunitVintageApplicationTests { @Autowired - private TestRestTemplate restTemplate; + private MockMvc mockMvc; @Test - public void testMessage() { - String message = this.restTemplate.getForObject("/hi", String.class); - assertThat(message).isEqualTo("Hello World"); + public void testMessage() throws Exception { + this.mockMvc.perform(get("/hi")).andExpect(content().string("Hello World")); } }