|
@@ -6,12 +6,16 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
6
|
6
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
7
|
7
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
8
|
8
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.handler;
|
|
9
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
9
|
10
|
|
|
11
|
+import org.junit.Ignore;
|
10
|
12
|
import org.junit.Test;
|
11
|
13
|
import org.junit.runner.RunWith;
|
12
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
15
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
14
|
16
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
17
|
+import org.springframework.http.HttpHeaders;
|
|
18
|
+import org.springframework.http.HttpStatus;
|
15
|
19
|
import org.springframework.test.context.junit4.SpringRunner;
|
16
|
20
|
import org.springframework.test.web.servlet.MockMvc;
|
17
|
21
|
|
|
@@ -26,7 +30,7 @@ public class NewsControllerTest {
|
26
|
30
|
private NewsService service;
|
27
|
31
|
|
28
|
32
|
@Test
|
29
|
|
- public void news_Should_Use_Method_getAllArticles() throws Exception {
|
|
33
|
+ public void news_ShouldUseMethod_getAllArticles() throws Exception {
|
30
|
34
|
when(service.getNews("test")).thenReturn(new News());
|
31
|
35
|
this.mockMvc.perform(get("/news?query=fb"))
|
32
|
36
|
.andDo(print())
|
|
@@ -34,7 +38,7 @@ public class NewsControllerTest {
|
34
|
38
|
}
|
35
|
39
|
|
36
|
40
|
@Test
|
37
|
|
- public void news_Should_Return_A_Json_Array() throws Exception {
|
|
41
|
+ public void news_ShouldReturnJsonArray() throws Exception {
|
38
|
42
|
when(service.getNews("test")).thenReturn(new News());
|
39
|
43
|
this.mockMvc.perform(get("/news?query=fb"))
|
40
|
44
|
.andDo(print())
|
|
@@ -42,10 +46,10 @@ public class NewsControllerTest {
|
42
|
46
|
}
|
43
|
47
|
|
44
|
48
|
@Test
|
45
|
|
- public void news_When_No_Queries_Throw_Exception() throws Exception {
|
|
49
|
+ public void news_ShouldHaveBadRequest_WhenNoQueries() throws Exception {
|
46
|
50
|
when(service.getNews("test")).thenReturn(new News());
|
47
|
51
|
this.mockMvc.perform(get("/news"))
|
48
|
52
|
.andDo(print())
|
49
|
|
- .andExpect(content().string("[]"));
|
|
53
|
+ .andExpect(status().isBadRequest());
|
50
|
54
|
}
|
51
|
55
|
}
|