JR Utily

fix tests

...@@ -2,20 +2,15 @@ package org.legrog.entities; ...@@ -2,20 +2,15 @@ package org.legrog.entities;
2 2
3 import org.apache.solr.client.solrj.SolrClient; 3 import org.apache.solr.client.solrj.SolrClient;
4 import org.apache.solr.client.solrj.SolrServerException; 4 import org.apache.solr.client.solrj.SolrServerException;
5 -import org.junit.jupiter.api.BeforeEach; 5 +import org.junit.jupiter.api.*;
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; 6 import org.junit.jupiter.api.extension.ExtendWith;
10 import org.junit.platform.runner.JUnitPlatform; 7 import org.junit.platform.runner.JUnitPlatform;
11 import org.junit.runner.RunWith; 8 import org.junit.runner.RunWith;
12 import org.legrog.test.MockitoExtension; 9 import org.legrog.test.MockitoExtension;
13 import org.mockito.Mock; 10 import org.mockito.Mock;
14 -import org.mockito.Mockito;
15 11
16 import java.io.IOException; 12 import java.io.IOException;
17 13
18 -import static org.mockito.Mockito.doThrow;
19 import static org.mockito.Mockito.verify; 14 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.when; 15 import static org.mockito.Mockito.when;
21 16
...@@ -25,6 +20,7 @@ import static org.mockito.Mockito.when; ...@@ -25,6 +20,7 @@ import static org.mockito.Mockito.when;
25 @RunWith(JUnitPlatform.class) 20 @RunWith(JUnitPlatform.class)
26 @ExtendWith(MockitoExtension.class) 21 @ExtendWith(MockitoExtension.class)
27 @DisplayName("Indexes and searches with SearchRepository") 22 @DisplayName("Indexes and searches with SearchRepository")
23 +
28 public class PublisherSearchRepositorySolrjTest { 24 public class PublisherSearchRepositorySolrjTest {
29 25
30 private PublisherSearchRepository publisherSearchRepository; 26 private PublisherSearchRepository publisherSearchRepository;
...@@ -38,7 +34,7 @@ public class PublisherSearchRepositorySolrjTest { ...@@ -38,7 +34,7 @@ public class PublisherSearchRepositorySolrjTest {
38 34
39 @Nested 35 @Nested
40 @DisplayName("save method") 36 @DisplayName("save method")
41 - class saveTests{ 37 + class saveTests {
42 38
43 @Test 39 @Test
44 @DisplayName("when called should addBean IndexedPublisher with commitWithinMs of 1 to repository") 40 @DisplayName("when called should addBean IndexedPublisher with commitWithinMs of 1 to repository")
...@@ -46,24 +42,14 @@ public class PublisherSearchRepositorySolrjTest { ...@@ -46,24 +42,14 @@ public class PublisherSearchRepositorySolrjTest {
46 publisherSearchRepository.save(indexedPublisher); 42 publisherSearchRepository.save(indexedPublisher);
47 verify(solrClient).addBean(indexedPublisher, 1); 43 verify(solrClient).addBean(indexedPublisher, 1);
48 } 44 }
49 -/* 45 +
50 @Test 46 @Test
51 @DisplayName("When call gets an IOException, should throw an IndexingException cobtaining it") 47 @DisplayName("When call gets an IOException, should throw an IndexingException cobtaining it")
52 - public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher, @Mock IOException ioException) throws SolrServerException { 48 + public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException {
53 - IndexingException indexingException = null; 49 + when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new IOException());
54 - try { 50 + Assertions.assertThrows(IndexingException.class, () -> publisherSearchRepository.save(indexedPublisher));
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 } 51 }
66 -*/ 52 +
67 } 53 }
68 54
69 } 55 }
......