|
4 | 4 | import static org.mockito.Mockito.*; |
5 | 5 |
|
6 | 6 | import java.util.Date; |
7 | | -import java.util.HashMap; |
8 | 7 | import java.util.List; |
9 | 8 | import java.util.Map; |
10 | 9 |
|
11 | | -import org.typesense.model.*; |
12 | | -import org.typesense.api.Documents; |
13 | | -import org.typesense.api.Collection; |
14 | | - |
15 | 10 | import dev.findfirst.core.model.jdbc.TypesenseInitRecord; |
16 | 11 | import dev.findfirst.core.repository.jdbc.TypsenseInitializationRepository; |
17 | 12 |
|
|
22 | 17 | import org.mockito.Mock; |
23 | 18 | import org.mockito.junit.jupiter.MockitoExtension; |
24 | 19 | import org.typesense.api.Client; |
| 20 | +import org.typesense.api.Collection; |
25 | 21 | import org.typesense.api.Collections; |
| 22 | +import org.typesense.api.Documents; |
| 23 | +import org.typesense.model.*; |
26 | 24 |
|
27 | 25 | /** |
28 | 26 | * Tests for typsense operations such as intitilization, queries/imports. |
@@ -83,41 +81,41 @@ void initializationWasNotFinished() throws Exception { |
83 | 81 | @Disabled("Implement test to save storeScrapedText") |
84 | 82 | void storeScrapedText() throws Exception {} |
85 | 83 |
|
86 | | - @Test |
87 | | - void returnSearchHighlighted() throws Exception { |
| 84 | + @Test |
| 85 | + void returnSearchHighlighted() throws Exception { |
88 | 86 |
|
89 | | - String query = "example"; |
90 | | - Long expectedId = 123L; |
91 | | - String expectedSnippet = "<mark>example</mark> text around"; |
| 87 | + String query = "example"; |
| 88 | + Long expectedId = 123L; |
| 89 | + String expectedSnippet = "<mark>example</mark> text around"; |
92 | 90 |
|
93 | | - // Mock highlight |
94 | | - SearchHighlight highlight = mock(SearchHighlight.class); |
95 | | - when(highlight.getField()).thenReturn("text"); |
96 | | - when(highlight.getSnippet()).thenReturn(expectedSnippet); |
| 91 | + // Mock highlight |
| 92 | + SearchHighlight highlight = mock(SearchHighlight.class); |
| 93 | + when(highlight.getField()).thenReturn("text"); |
| 94 | + when(highlight.getSnippet()).thenReturn(expectedSnippet); |
97 | 95 |
|
98 | | - // Simula un hit como Map |
99 | | - SearchResultHit hit = mock(SearchResultHit.class); |
100 | | - when(hit.getDocument()).thenReturn(Map.of("id", expectedId.toString())); |
101 | | - when(hit.getHighlights()).thenReturn(List.of(highlight)); |
| 96 | + // Simula un hit como Map |
| 97 | + SearchResultHit hit = mock(SearchResultHit.class); |
| 98 | + when(hit.getDocument()).thenReturn(Map.of("id", expectedId.toString())); |
| 99 | + when(hit.getHighlights()).thenReturn(List.of(highlight)); |
102 | 100 |
|
103 | | - // Mock search result |
104 | | - SearchResult searchResult = new SearchResult(); |
105 | | - searchResult.setHits(List.of(hit)); |
| 101 | + // Mock search result |
| 102 | + SearchResult searchResult = new SearchResult(); |
| 103 | + searchResult.setHits(List.of(hit)); |
106 | 104 |
|
107 | 105 |
|
108 | | - // Mock client behavior |
109 | | - var documents = mock(Documents.class); |
110 | | - var collection = mock(Collection.class); |
111 | | - when(client.collections("bookmark")).thenReturn(collection); |
112 | | - when(collection.documents()).thenReturn(documents); |
113 | | - when(documents.search(any(SearchParameters.class))).thenReturn(searchResult); |
| 106 | + // Mock client behavior |
| 107 | + var documents = mock(Documents.class); |
| 108 | + var collection = mock(Collection.class); |
| 109 | + when(client.collections("bookmark")).thenReturn(collection); |
| 110 | + when(collection.documents()).thenReturn(documents); |
| 111 | + when(documents.search(any(SearchParameters.class))).thenReturn(searchResult); |
114 | 112 |
|
115 | | - // Act |
116 | | - var results = typesense.search(query); |
| 113 | + // Act |
| 114 | + var results = typesense.search(query); |
117 | 115 |
|
118 | | - // Assert |
119 | | - assertEquals(1, results.size()); |
120 | | - assertEquals(expectedId, results.get(0).id()); |
121 | | - assertEquals(expectedSnippet, results.get(0).highlight()); |
122 | | - } |
| 116 | + // Assert |
| 117 | + assertEquals(1, results.size()); |
| 118 | + assertEquals(expectedId, results.get(0).id()); |
| 119 | + assertEquals(expectedSnippet, results.get(0).highlight()); |
| 120 | + } |
123 | 121 | } |
0 commit comments