Showing
3 changed files
with
45 additions
and
0 deletions
... | @@ -84,4 +84,10 @@ public interface PublisherService { | ... | @@ -84,4 +84,10 @@ public interface PublisherService { |
84 | * @return PublisherVersion List | 84 | * @return PublisherVersion List |
85 | */ | 85 | */ |
86 | List<PublisherVersion> convertIndexedPublishersIntoPublisherVersions(List<IndexedPublisher> indexedPublishers); | 86 | List<PublisherVersion> convertIndexedPublishersIntoPublisherVersions(List<IndexedPublisher> indexedPublishers); |
87 | + | ||
88 | + /** | ||
89 | + * | ||
90 | + * @return number of indexed publishers | ||
91 | + */ | ||
92 | + public int reindexAllPublishers(); | ||
87 | } | 93 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -157,4 +157,16 @@ public class PublisherServiceDefault implements PublisherService { | ... | @@ -157,4 +157,16 @@ public class PublisherServiceDefault implements PublisherService { |
157 | return new ArrayList<>(); | 157 | return new ArrayList<>(); |
158 | } | 158 | } |
159 | 159 | ||
160 | + protected List<IndexedPublisher> convertPublishersIntoIndexedPublishers(List<Publisher> publishers) { | ||
161 | + return new ArrayList<>(); | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
165 | + public int reindexAllPublishers() { | ||
166 | + List<Publisher> publishers = publisherRepository.findByValidatedVersionIsNotNull(); | ||
167 | + List<IndexedPublisher> indexedPublishers = convertPublishersIntoIndexedPublishers(new ArrayList<>()); | ||
168 | + publisherSearchRepository.reindex(indexedPublishers); | ||
169 | + return 0; | ||
170 | + } | ||
171 | + | ||
160 | } | 172 | } | ... | ... |
... | @@ -47,6 +47,9 @@ public class PublisherServiceDefaultTest { | ... | @@ -47,6 +47,9 @@ public class PublisherServiceDefaultTest { |
47 | @Captor | 47 | @Captor |
48 | ArgumentCaptor<IndexedPublisher> indexedPublisherArgumentCaptor; | 48 | ArgumentCaptor<IndexedPublisher> indexedPublisherArgumentCaptor; |
49 | 49 | ||
50 | + @Captor | ||
51 | + ArgumentCaptor<List <Publisher>> publishersArgumentCaptor; | ||
52 | + | ||
50 | @BeforeEach | 53 | @BeforeEach |
51 | public void setUp(@Mock PublisherRepository publisherRepository, | 54 | public void setUp(@Mock PublisherRepository publisherRepository, |
52 | @Mock PublisherVersionRepository publisherVersionRepository, | 55 | @Mock PublisherVersionRepository publisherVersionRepository, |
... | @@ -205,4 +208,28 @@ public class PublisherServiceDefaultTest { | ... | @@ -205,4 +208,28 @@ public class PublisherServiceDefaultTest { |
205 | } | 208 | } |
206 | 209 | ||
207 | } | 210 | } |
211 | + | ||
212 | + @Nested | ||
213 | + @DisplayName("reindexAllPublishers method") | ||
214 | + class ReindexAllPublishersTests { | ||
215 | + @DisplayName("When called, should follow the call sequence") | ||
216 | + @Test | ||
217 | + public void testCorrectCalls(@Mock PublisherRepository publisherRepository, @Mock PublisherSearchRepository publisherSearchRepository) { | ||
218 | + publisherServiceDefault.reindexAllPublishers(); | ||
219 | + Mockito.verify(publisherRepository).findByValidatedVersionIsNotNull(); | ||
220 | + verify(publisherServiceDefault, times(1)).convertPublishersIntoIndexedPublishers(Mockito.any()); | ||
221 | + Mockito.verify(publisherSearchRepository).reindex(Mockito.any()); | ||
222 | + } | ||
223 | + | ||
224 | + @DisplayName("When called, should send publishers it gets from findByValidatedVersionIsNotNull to convertPublishersIntoIndexedPublishers") | ||
225 | + @Test | ||
226 | + public void testTransmitsPublishers(@Mock PublisherRepository publisherRepository) { | ||
227 | + List<Publisher> publishers = new ArrayList<>(); | ||
228 | + when(publisherRepository.findByValidatedVersionIsNotNull()).thenReturn(publishers); | ||
229 | + publisherServiceDefault.reindexAllPublishers(); | ||
230 | + verify(publisherServiceDefault, times(1)).convertPublishersIntoIndexedPublishers(publishersArgumentCaptor.capture()); | ||
231 | + // Si reindexAllPublishers fait convertPublishersIntoIndexedPublishers(new ArrayList<>()), je crois que ce test devrait échouer, mais ce n'est pas le cas | ||
232 | + assertThat(publishersArgumentCaptor.getValue()).isEqualTo(publishers); | ||
233 | + } | ||
234 | + } | ||
208 | } | 235 | } | ... | ... |
-
Please register or login to post a comment