forked from ityouknow/spring-boot-examples
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathHelloWorldControlerTest.java
More file actions
27 lines (21 loc) · 958 Bytes
/
HelloWorldControlerTest.java
File metadata and controls
27 lines (21 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.example.helloworld.controller;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
class HelloWorldControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void shouldReturnExpectedMessage() throws Exception {
mockMvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string("Hello, World!"));
}
}