|
36 | 36 | import java.util.HashMap; |
37 | 37 | import java.util.List; |
38 | 38 | import java.util.Map; |
| 39 | +import java.util.Optional; |
39 | 40 | import java.util.Set; |
40 | 41 |
|
41 | 42 | import static java.util.Arrays.asList; |
42 | 43 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
43 | 44 | import static org.junit.jupiter.api.Assertions.assertTrue; |
44 | 45 | import static org.mockito.ArgumentMatchers.any; |
45 | 46 | import static org.mockito.ArgumentMatchers.anyString; |
| 47 | +import static org.mockito.ArgumentMatchers.eq; |
46 | 48 | import static org.mockito.Mockito.verify; |
47 | 49 | import static org.mockito.Mockito.when; |
48 | 50 |
|
@@ -98,6 +100,36 @@ public void shouldFindByAgeAndInteger() { |
98 | 100 | assertTrue(people.stream().allMatch(Person.class::isInstance)); |
99 | 101 | } |
100 | 102 |
|
| 103 | + @Test |
| 104 | + public void shouldSaveUsingInsert() { |
| 105 | + Person person = Person.of("Ada", 10); |
| 106 | + personRepository.save(person); |
| 107 | + verify(template).insert(eq(person)); |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + @Test |
| 112 | + public void shouldSaveUsingUpdate() { |
| 113 | + Person person = Person.of("Ada-2", 10); |
| 114 | + when(template.find(Person.class, "Ada-2")).thenReturn(Optional.of(person)); |
| 115 | + personRepository.save(person); |
| 116 | + verify(template).update(eq(person)); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void shouldDelete(){ |
| 121 | + personRepository.deleteById("id"); |
| 122 | + verify(template).delete(Person.class, "id"); |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + @Test |
| 127 | + public void shouldDeleteEntity(){ |
| 128 | + Person person = Person.of("Ada", 10); |
| 129 | + personRepository.delete(person); |
| 130 | + verify(template).delete(Person.class, person.getName()); |
| 131 | + } |
| 132 | + |
101 | 133 |
|
102 | 134 | interface PersonRepository extends HazelcastRepository<Person, String> { |
103 | 135 |
|
|
0 commit comments