Skip to content

Commit a82533d

Browse files
committed
Melhorando alguns Testes de Controlador #52
1 parent e30db4e commit a82533d

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package br.ufrn.dct.apf.controller;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
5+
import org.springframework.boot.test.mock.mockito.MockBean;
6+
import org.springframework.test.web.servlet.MockMvc;
7+
import org.testng.annotations.AfterMethod;
8+
import org.testng.annotations.BeforeMethod;
9+
import org.testng.annotations.Test;
10+
import org.testng.asserts.SoftAssert;
11+
12+
import br.ufrn.dct.apf.service.ProjectService;
13+
import br.ufrn.dct.apf.service.UserService;
14+
15+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
16+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
19+
import static org.hamcrest.Matchers.containsString;
20+
21+
@WebMvcTest(LoginController.class)
22+
public class LoginControllerTest extends AbstractControllerTest {
23+
24+
private SoftAssert softAssert;
25+
26+
@BeforeMethod
27+
public void startTest() {
28+
softAssert = new SoftAssert();
29+
}
30+
31+
@AfterMethod
32+
public void endTest() {
33+
softAssert = null;
34+
}
35+
36+
@Autowired
37+
private MockMvc mockMvc;
38+
39+
@MockBean
40+
private UserService userService;
41+
42+
@MockBean
43+
private ProjectService projectService;
44+
45+
@Test
46+
public void getRootURL() throws Exception {
47+
softAssert.assertNotNull(mockMvc);
48+
mockMvc.perform(get("/"))
49+
.andDo(print())
50+
.andExpect(status().isOk())
51+
.andExpect(content().string(containsString("action=\"/login\"")));
52+
}
53+
54+
@Test
55+
public void getRegistrationURL() throws Exception {
56+
softAssert.assertNotNull(mockMvc);
57+
mockMvc.perform(get("/registration"))
58+
.andDo(print())
59+
.andExpect(status().isOk());
60+
}
61+
}

src/test/java/br/ufrn/dct/apf/controller/UserStoryControllerTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,19 @@ public class UserStoryControllerTest extends AbstractControllerTest {
2525
@Autowired
2626
private MockMvc mockMvc;
2727

28-
@Autowired
28+
@MockBean
2929
private UserStoryService userStoryService;
3030

3131
@MockBean
32-
private UserStoryService service;
32+
private ProjectService projectService;
3333

3434
@MockBean
3535
private UserService userService;
36-
37-
@MockBean
38-
private ProjectService projectService;
39-
40-
//@Test
36+
37+
@Test
4138
public void listFromService() throws Exception {
42-
List<UserStory> value = new ArrayList<>();
43-
System.err.println(userStoryService);
44-
when(userStoryService.findAll()).thenReturn(value);
39+
//List<UserStory> value = new ArrayList<>();
40+
//when(userStoryService.findAll()).thenReturn(value);
4541

4642
mockMvc.perform(get("/us/list"))
4743
.andDo(print())

0 commit comments

Comments
 (0)