Jean-Francois Leveque

Nouveaux tests, attention à celui qui est commenté dans PublisherSearchRepositorySolrjTest.

1 +package org.legrog.entities;
2 +
3 +import org.apache.solr.client.solrj.SolrClient;
4 +import org.apache.solr.client.solrj.SolrServerException;
5 +import org.junit.jupiter.api.BeforeEach;
6 +import org.junit.jupiter.api.DisplayName;
7 +import org.junit.jupiter.api.Nested;
8 +import org.junit.jupiter.api.Test;
9 +import org.junit.jupiter.api.extension.ExtendWith;
10 +import org.junit.platform.runner.JUnitPlatform;
11 +import org.junit.runner.RunWith;
12 +import org.legrog.test.MockitoExtension;
13 +import org.mockito.Mock;
14 +import org.mockito.Mockito;
15 +
16 +import java.io.IOException;
17 +
18 +import static org.mockito.Mockito.doThrow;
19 +import static org.mockito.Mockito.verify;
20 +import static org.mockito.Mockito.when;
21 +
22 +/*
23 + Classe testant PublisherSearchRepositorySolrj
24 + */
25 +@RunWith(JUnitPlatform.class)
26 +@ExtendWith(MockitoExtension.class)
27 +@DisplayName("Indexes and searches with SearchRepository")
28 +public class PublisherSearchRepositorySolrjTest {
29 +
30 + private PublisherSearchRepository publisherSearchRepository;
31 + private SolrClient solrClient;
32 +
33 + @BeforeEach
34 + public void setup(@Mock SolrClient solrClient) {
35 + publisherSearchRepository = new PublisherSearchRepositorySolrj(solrClient);
36 + this.solrClient = solrClient;
37 + }
38 +
39 + @Nested
40 + @DisplayName("save method")
41 + class saveTests{
42 +
43 + @Test
44 + @DisplayName("when called should addBean IndexedPublisher with commitWithinMs of 1 to repository")
45 + public void addBeanTest(@Mock IndexedPublisher indexedPublisher) throws IndexingException, SolrServerException, IOException {
46 + publisherSearchRepository.save(indexedPublisher);
47 + verify(solrClient).addBean(indexedPublisher, 1);
48 + }
49 +/*
50 + @Test
51 + @DisplayName("When call gets an IOException, should throw an IndexingException cobtaining it")
52 + public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher, @Mock IOException ioException) throws SolrServerException {
53 + IndexingException indexingException = null;
54 + try {
55 + when(solrClient.addBean(indexedPublisher, 1)).thenThrow(ioException);
56 + } catch (IOException e) {
57 + e.printStackTrace();
58 + }
59 + try {
60 + publisherSearchRepository.save(indexedPublisher);
61 + } catch (IndexingException e) {
62 + indexingException = e;
63 + }
64 + verify(ioException).equals(indexingException.getRootCause());
65 + }
66 +*/
67 + }
68 +
69 +}
...@@ -71,7 +71,7 @@ public class ListPublisherActionsViewTest { ...@@ -71,7 +71,7 @@ public class ListPublisherActionsViewTest {
71 71
72 @Test 72 @Test
73 @DisplayName("when publisher is set, should show only its actions") 73 @DisplayName("when publisher is set, should show only its actions")
74 - public void testFilter(@Mock PublisherService publisherServiceMock) { 74 + public void testFilter() {
75 List<PublisherAction> publisherActions = new ArrayList<PublisherAction>(); 75 List<PublisherAction> publisherActions = new ArrayList<PublisherAction>();
76 76
77 Publisher publisher = new Publisher(); 77 Publisher publisher = new Publisher();
......