2 Incheckningar

Upphovsman SHA1 Meddelande Datum
  mpierse 7e0d7f8884 mokito testing 5 år sedan
  mpierse 0886b84c45 overloaded person constructor 5 år sedan

+ 5
- 1
src/main/java/io/zipcoder/crudapp/Person.java Visa fil

6
 import javax.persistence.GeneratedValue;
6
 import javax.persistence.GeneratedValue;
7
 import javax.persistence.GenerationType;
7
 import javax.persistence.GenerationType;
8
 import javax.persistence.Id;
8
 import javax.persistence.Id;
9
-import java.io.Serializable;
10
 
9
 
11
 @Entity
10
 @Entity
12
 public class Person {
11
 public class Person {
20
     public Person() {
19
     public Person() {
21
     }
20
     }
22
 
21
 
22
+    public Person(String firstName, String lastName) {
23
+        this.firstName = firstName;
24
+        this.lastName = lastName;
25
+    }
26
+
23
     public Long getId() {
27
     public Long getId() {
24
         return id;
28
         return id;
25
     }
29
     }

+ 0
- 2
src/main/java/io/zipcoder/crudapp/PersonRepository.java Visa fil

4
 
4
 
5
 public interface PersonRepository extends CrudRepository<Person, Long> {
5
 public interface PersonRepository extends CrudRepository<Person, Long> {
6
 
6
 
7
-
8
-
9
 }
7
 }

+ 0
- 5
src/main/java/io/zipcoder/crudapp/PersonService.java Visa fil

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

+ 68
- 0
src/test/java/io/zipcoder/crudapp/PersonControllerTest.java Visa fil

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