adding testcase for WebUtils and ServletRequestUtils (#1193)
* rest with spark java * 4 * Update Application.java * indentation changes * spring @requestmapping shortcuts * removing spring requestmapping and pushing spring-mvc-java * Joining/Splitting Strings with Java and Stream API * adding more join/split functionality * changing package name * testcase change * adding webutils * adding testcase for WebUtils and ServletRequestUtils * adding testcase
This commit is contained in:
parent
2bf21cbff3
commit
51756367ce
|
@ -0,0 +1,41 @@
|
||||||
|
package com.baeldung.utils;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baeldung.utils.controller.UtilsController;
|
||||||
|
|
||||||
|
public class UtilsControllerTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private UtilsController utilsController;
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception {
|
||||||
|
String param = "testparam";
|
||||||
|
this.mockMvc.perform(
|
||||||
|
post("/setParam")
|
||||||
|
.param("param", param)
|
||||||
|
.sessionAttr("parameter", param))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue