|
@@ -0,0 +1,68 @@
|
|
1
|
+package io.zipcoder.crudapp;
|
|
2
|
+
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+import org.mockito.Mock;
|
|
7
|
+import org.mockito.MockitoAnnotations;
|
|
8
|
+import org.springframework.http.HttpStatus;
|
|
9
|
+import org.springframework.http.ResponseEntity;
|
|
10
|
+import static org.mockito.Matchers.any;
|
|
11
|
+import static org.mockito.Mockito.when;
|
|
12
|
+
|
|
13
|
+public class PersonControllerTest {
|
|
14
|
+
|
|
15
|
+ @Mock
|
|
16
|
+ private PersonController controller;
|
|
17
|
+
|
|
18
|
+ @Before
|
|
19
|
+ public void setUp() throws Exception {
|
|
20
|
+
|
|
21
|
+ MockitoAnnotations.initMocks(this);
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ @Test
|
|
25
|
+ public void createPersonTest(){
|
|
26
|
+ when(controller.createPerson(any(Person.class))).thenReturn(new ResponseEntity<>( HttpStatus.CREATED));
|
|
27
|
+
|
|
28
|
+ Person p = new Person();
|
|
29
|
+ ResponseEntity<Person> actual = controller.createPerson(p);
|
|
30
|
+ ResponseEntity<Person> expected = new ResponseEntity<>(HttpStatus.CREATED);
|
|
31
|
+
|
|
32
|
+ Assert.assertEquals(expected, actual);
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Test
|
|
36
|
+ public void getPersonTest(){
|
|
37
|
+ when(controller.getPerson(1)).thenReturn(new ResponseEntity<>( HttpStatus.OK));
|
|
38
|
+
|
|
39
|
+ Person p = new Person();
|
|
40
|
+ p.setId(1L);
|
|
41
|
+ ResponseEntity<Person> actual = controller.getPerson(1);
|
|
42
|
+ ResponseEntity<Person> expected = new ResponseEntity<>(HttpStatus.OK);
|
|
43
|
+
|
|
44
|
+ Assert.assertEquals(expected, actual);
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Test
|
|
48
|
+ public void updatePersonTest(){
|
|
49
|
+ when(controller.updatePerson(any(Person.class))).thenReturn(new ResponseEntity<>( HttpStatus.OK));
|
|
50
|
+
|
|
51
|
+ Person p = new Person();
|
|
52
|
+ p.setId(1L);
|
|
53
|
+ ResponseEntity<Person> actual = controller.updatePerson(any(Person.class));
|
|
54
|
+ ResponseEntity<Person> expected = new ResponseEntity<>(HttpStatus.OK);
|
|
55
|
+
|
|
56
|
+ Assert.assertEquals(expected, actual);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ @Test
|
|
60
|
+ public void deletePerson(){
|
|
61
|
+ when(controller.deletePerson(1)).thenReturn(new ResponseEntity<>( HttpStatus.NO_CONTENT));
|
|
62
|
+
|
|
63
|
+ ResponseEntity<Person> actual = controller.deletePerson(1);
|
|
64
|
+ ResponseEntity<Person> expected = new ResponseEntity<>( HttpStatus.NO_CONTENT);
|
|
65
|
+
|
|
66
|
+ Assert.assertEquals(expected, actual);
|
|
67
|
+ }
|
|
68
|
+}
|