39 lines
1.3 KiB
Java
39 lines
1.3 KiB
Java
package ru.lionarius.isdojplab;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import ru.lionarius.isdojplab.controller.HomeController;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
@WebMvcTest(HomeController.class)
|
|
public class HomeControllerTest {
|
|
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
|
|
@Test
|
|
public void testHomePageReturnsOkStatus() throws Exception {
|
|
mockMvc.perform(get("/"))
|
|
.andExpect(status().isOk());
|
|
}
|
|
|
|
@Test
|
|
public void testHomePageReturnsCorrectView() throws Exception {
|
|
mockMvc.perform(get("/"))
|
|
.andExpect(status().isOk())
|
|
.andExpect(view().name("home"));
|
|
}
|
|
|
|
@Test
|
|
public void testHomePageRendersCorrectHtml() throws Exception {
|
|
mockMvc.perform(get("/"))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentType("text/html;charset=UTF-8"))
|
|
.andExpect(model().attribute("message", "Добро пожаловать в магазин электротоваров!"));
|
|
}
|
|
}
|