Commit 900c3250 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add JUnit 4 and the Vintage Engine sample"

See gh-17100
parent 9fafcda9
...@@ -23,28 +23,6 @@ ...@@ -23,28 +23,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</exclusion>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
...@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class MessageController { class MessageController {
@GetMapping("/hi") @GetMapping("/hi")
public String hello() { public String hello() {
......
...@@ -20,24 +20,23 @@ import org.junit.Test; ...@@ -20,24 +20,23 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner; 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) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @WebMvcTest
public class SampleJunitVintageApplicationTests { public class SampleJunitVintageApplicationTests {
@Autowired @Autowired
private TestRestTemplate restTemplate; private MockMvc mockMvc;
@Test @Test
public void testMessage() { public void testMessage() throws Exception {
String message = this.restTemplate.getForObject("/hi", String.class); this.mockMvc.perform(get("/hi")).andExpect(content().string("Hello World"));
assertThat(message).isEqualTo("Hello World");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment