Skip to content

Commit 5175636

Browse files
AbhinabKanrarmaibin
authored andcommitted
adding testcase for WebUtils and ServletRequestUtils (eugenp#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
1 parent 2bf21cb commit 5175636

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.utils;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.mockito.InjectMocks;
6+
import org.mockito.MockitoAnnotations;
7+
import org.springframework.test.web.servlet.MockMvc;
8+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
9+
10+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
11+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
12+
13+
14+
import com.baeldung.utils.controller.UtilsController;
15+
16+
public class UtilsControllerTest {
17+
18+
@InjectMocks
19+
private UtilsController utilsController;
20+
21+
private MockMvc mockMvc;
22+
23+
@Before
24+
public void setup() {
25+
MockitoAnnotations.initMocks(this);
26+
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController)
27+
.build();
28+
29+
}
30+
31+
@Test
32+
public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception {
33+
String param = "testparam";
34+
this.mockMvc.perform(
35+
post("/setParam")
36+
.param("param", param)
37+
.sessionAttr("parameter", param))
38+
.andExpect(status().isOk());
39+
}
40+
41+
}

0 commit comments

Comments
 (0)