File tree Expand file tree Collapse file tree 3 files changed +9
-32
lines changed
spring-boot-samples/spring-boot-sample-junit-vintage Expand file tree Collapse file tree 3 files changed +9
-32
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 2020import org .springframework .web .bind .annotation .RestController ;
2121
2222@ RestController
23- public class MessageController {
23+ class MessageController {
2424
2525 @ GetMapping ("/hi" )
2626 public String hello () {
Original file line number Diff line number Diff line change 2020import org .junit .runner .RunWith ;
2121
2222import 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 ;
2624import 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
3232public 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}
You can’t perform that action at this time.
0 commit comments