Skip to content

Commit ee456fc

Browse files
committed
Fix Checkstyle violations in OpenSearchVectorStoreTest
Resolved 14 Checkstyle errors that blocked the build process: - Corrected import statement ordering - Added 'this.' qualifier to instance variable references - Added missing newline at end of file This ensures compliance with Spring AI coding standards and enables successful compilation after rebasing onto upstream/main. Signed-off-by: sanghun <vitash1215@gmail.com>
1 parent 13de7d8 commit ee456fc

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

vector-stores/spring-ai-opensearch-store/src/test/java/org/springframework/ai/vectorstore/opensearch/OpenSearchVectorStoreTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616

1717
package org.springframework.ai.vectorstore.opensearch;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
21-
import static org.mockito.ArgumentMatchers.any;
22-
import static org.mockito.Mockito.lenient;
23-
import static org.mockito.Mockito.verify;
24-
import static org.mockito.Mockito.when;
25-
2619
import java.io.IOException;
2720
import java.util.List;
2821
import java.util.Map;
@@ -43,6 +36,13 @@
4336
import org.springframework.ai.document.Document;
4437
import org.springframework.ai.embedding.EmbeddingModel;
4538

39+
import static org.assertj.core.api.Assertions.assertThat;
40+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
41+
import static org.mockito.ArgumentMatchers.any;
42+
import static org.mockito.Mockito.lenient;
43+
import static org.mockito.Mockito.verify;
44+
import static org.mockito.Mockito.when;
45+
4646
/**
4747
* Unit tests for OpenSearchVectorStore.doAdd() method.
4848
*
@@ -64,17 +64,17 @@ class OpenSearchVectorStoreTest {
6464
@BeforeEach
6565
void setUp() throws IOException {
6666
// Use lenient to avoid UnnecessaryStubbingException
67-
lenient().when(mockEmbeddingModel.dimensions()).thenReturn(3);
68-
lenient().when(mockOpenSearchClient.bulk(any(BulkRequest.class))).thenReturn(mockBulkResponse);
69-
lenient().when(mockBulkResponse.errors()).thenReturn(false);
67+
lenient().when(this.mockEmbeddingModel.dimensions()).thenReturn(3);
68+
lenient().when(this.mockOpenSearchClient.bulk(any(BulkRequest.class))).thenReturn(this.mockBulkResponse);
69+
lenient().when(this.mockBulkResponse.errors()).thenReturn(false);
7070
}
7171

7272
@ParameterizedTest(name = "manageDocumentIds={0}")
7373
@ValueSource(booleans = { true, false })
7474
@DisplayName("Should handle document ID management setting correctly")
7575
void shouldHandleDocumentIdManagementSetting(boolean manageDocumentIds) throws IOException {
7676
// Given
77-
when(mockEmbeddingModel.embed(any(), any(), any()))
77+
when(this.mockEmbeddingModel.embed(any(), any(), any()))
7878
.thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f }, new float[] { 0.4f, 0.5f, 0.6f }));
7979

8080
OpenSearchVectorStore vectorStore = createVectorStore(manageDocumentIds);
@@ -95,7 +95,7 @@ void shouldHandleDocumentIdManagementSetting(boolean manageDocumentIds) throws I
9595
@DisplayName("Should handle single document correctly")
9696
void shouldHandleSingleDocumentCorrectly() throws IOException {
9797
// Given
98-
when(mockEmbeddingModel.embed(any(), any(), any())).thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f }));
98+
when(this.mockEmbeddingModel.embed(any(), any(), any())).thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f }));
9999

100100
OpenSearchVectorStore vectorStore = createVectorStore(true);
101101
Document document = new Document("test-id", "test content", Map.of("key", "value"));
@@ -116,7 +116,7 @@ void shouldHandleSingleDocumentCorrectly() throws IOException {
116116
@DisplayName("Should handle multiple documents with explicit IDs")
117117
void shouldHandleMultipleDocumentsWithExplicitIds() throws IOException {
118118
// Given
119-
when(mockEmbeddingModel.embed(any(), any(), any())).thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f },
119+
when(this.mockEmbeddingModel.embed(any(), any(), any())).thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f },
120120
new float[] { 0.4f, 0.5f, 0.6f }, new float[] { 0.7f, 0.8f, 0.9f }));
121121

122122
OpenSearchVectorStore vectorStore = createVectorStore(true);
@@ -141,7 +141,7 @@ void shouldHandleMultipleDocumentsWithExplicitIds() throws IOException {
141141
@DisplayName("Should handle multiple documents without explicit IDs")
142142
void shouldHandleMultipleDocumentsWithoutExplicitIds() throws IOException {
143143
// Given
144-
when(mockEmbeddingModel.embed(any(), any(), any()))
144+
when(this.mockEmbeddingModel.embed(any(), any(), any()))
145145
.thenReturn(List.of(new float[] { 0.1f, 0.2f, 0.3f }, new float[] { 0.4f, 0.5f, 0.6f }));
146146

147147
OpenSearchVectorStore vectorStore = createVectorStore(false);
@@ -165,7 +165,7 @@ void shouldHandleMultipleDocumentsWithoutExplicitIds() throws IOException {
165165
@DisplayName("Should handle embedding model error")
166166
void shouldHandleEmbeddingModelError() {
167167
// Given
168-
when(mockEmbeddingModel.embed(any(), any(), any())).thenThrow(new RuntimeException("Embedding failed"));
168+
when(this.mockEmbeddingModel.embed(any(), any(), any())).thenThrow(new RuntimeException("Embedding failed"));
169169

170170
OpenSearchVectorStore vectorStore = createVectorStore(true);
171171
List<Document> documents = List.of(new Document("doc1", "content", Map.of()));
@@ -178,14 +178,14 @@ void shouldHandleEmbeddingModelError() {
178178
// Helper methods
179179

180180
private OpenSearchVectorStore createVectorStore(boolean manageDocumentIds) {
181-
return OpenSearchVectorStore.builder(mockOpenSearchClient, mockEmbeddingModel)
181+
return OpenSearchVectorStore.builder(this.mockOpenSearchClient, this.mockEmbeddingModel)
182182
.manageDocumentIds(manageDocumentIds)
183183
.build();
184184
}
185185

186186
private BulkRequest captureBulkRequest() throws IOException {
187187
ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class);
188-
verify(mockOpenSearchClient).bulk(captor.capture());
188+
verify(this.mockOpenSearchClient).bulk(captor.capture());
189189
return captor.getValue();
190190
}
191191

@@ -203,4 +203,4 @@ private void verifyDocumentIdHandling(BulkRequest request, boolean shouldHaveExp
203203
}
204204
}
205205

206-
}
206+
}

0 commit comments

Comments
 (0)