Bladeren bron

mokito testing

mpierse 5 jaren geleden
bovenliggende
commit
7e0d7f8884

+ 0
- 1
src/main/java/io/zipcoder/crudapp/Person.java Bestand weergeven

@@ -6,7 +6,6 @@ import javax.persistence.Entity;
6 6
 import javax.persistence.GeneratedValue;
7 7
 import javax.persistence.GenerationType;
8 8
 import javax.persistence.Id;
9
-import java.io.Serializable;
10 9
 
11 10
 @Entity
12 11
 public class Person {

+ 0
- 5
src/main/java/io/zipcoder/crudapp/PersonService.java Bestand weergeven

@@ -1,5 +0,0 @@
1
-package io.zipcoder.crudapp;
2
-
3
-public class PersonService {
4
-
5
-}

+ 68
- 0
src/test/java/io/zipcoder/crudapp/PersonControllerTest.java Bestand weergeven

@@ -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
+}