Jean-Francois Leveque

Test avec problème

......@@ -84,4 +84,10 @@ public interface PublisherService {
* @return PublisherVersion List
*/
List<PublisherVersion> convertIndexedPublishersIntoPublisherVersions(List<IndexedPublisher> indexedPublishers);
/**
*
* @return number of indexed publishers
*/
public int reindexAllPublishers();
}
\ No newline at end of file
......
......@@ -157,4 +157,16 @@ public class PublisherServiceDefault implements PublisherService {
return new ArrayList<>();
}
protected List<IndexedPublisher> convertPublishersIntoIndexedPublishers(List<Publisher> publishers) {
return new ArrayList<>();
}
@Override
public int reindexAllPublishers() {
List<Publisher> publishers = publisherRepository.findByValidatedVersionIsNotNull();
List<IndexedPublisher> indexedPublishers = convertPublishersIntoIndexedPublishers(new ArrayList<>());
publisherSearchRepository.reindex(indexedPublishers);
return 0;
}
}
......
......@@ -47,6 +47,9 @@ public class PublisherServiceDefaultTest {
@Captor
ArgumentCaptor<IndexedPublisher> indexedPublisherArgumentCaptor;
@Captor
ArgumentCaptor<List <Publisher>> publishersArgumentCaptor;
@BeforeEach
public void setUp(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository,
......@@ -205,4 +208,28 @@ public class PublisherServiceDefaultTest {
}
}
@Nested
@DisplayName("reindexAllPublishers method")
class ReindexAllPublishersTests {
@DisplayName("When called, should follow the call sequence")
@Test
public void testCorrectCalls(@Mock PublisherRepository publisherRepository, @Mock PublisherSearchRepository publisherSearchRepository) {
publisherServiceDefault.reindexAllPublishers();
Mockito.verify(publisherRepository).findByValidatedVersionIsNotNull();
verify(publisherServiceDefault, times(1)).convertPublishersIntoIndexedPublishers(Mockito.any());
Mockito.verify(publisherSearchRepository).reindex(Mockito.any());
}
@DisplayName("When called, should send publishers it gets from findByValidatedVersionIsNotNull to convertPublishersIntoIndexedPublishers")
@Test
public void testTransmitsPublishers(@Mock PublisherRepository publisherRepository) {
List<Publisher> publishers = new ArrayList<>();
when(publisherRepository.findByValidatedVersionIsNotNull()).thenReturn(publishers);
publisherServiceDefault.reindexAllPublishers();
verify(publisherServiceDefault, times(1)).convertPublishersIntoIndexedPublishers(publishersArgumentCaptor.capture());
// Si reindexAllPublishers fait convertPublishersIntoIndexedPublishers(new ArrayList<>()), je crois que ce test devrait échouer, mais ce n'est pas le cas
assertThat(publishersArgumentCaptor.getValue()).isEqualTo(publishers);
}
}
}
......