Files
java-design-patterns/page-controller/src/test/java/com/iluwatar/page/controller/UserControllerTest.java
T
marikattt 4709922f11 feature: add Page Controller pattern (#2202)
* feat: create page controller

* add test

* add documentation

* fix: delete img file

* fix: modify App, SignupMode, UserController, pom.xml, and Readme

* fix: modify MVC files on page controller

* fix: modify readme file
2023-01-01 10:57:30 +02:00

37 lines
1.3 KiB
Java

package com.iluwatar.page.controller;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.context.junit.jupiter.SpringExtension;
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.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
public class UserControllerTest {
private UserController userController;
@Autowired
MockMvc mockMvc;
/**
* Verify if view and model are directed properly
*/
@Test
void testGetUserPath () throws Exception {
this.mockMvc.perform(get("/user")
.param("name", "Lily")
.param("email", "Lily@email.com"))
.andExpect(status().isOk())
.andExpect(model().attribute("name", "Lily"))
.andExpect(model().attribute("email", "Lily@email.com"))
.andReturn();
}
}