Skip to content

Commit 92ec7e9

Browse files
authored
test: Add improving test coverage for MultiQueryExpander, StreamHelper, and Query classes (#4473)
* test: Add missing test coverage for MultiQueryExpander, StreamHelper, and Query classes Co-authored-by: Oleksandr Klymenko <alexanderklmn@gmail.com> Signed-off-by: Oleksandr Klymenko <alexanderklmn@gmail.com>
1 parent 1b923c2 commit 92ec7e9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/api/StreamHelperTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,17 @@ void testMultipleErrorEventsHandling() {
5959
assertThat(response2).isNotNull();
6060
}
6161

62+
@Test
63+
void testPingEventHandling() {
64+
StreamHelper streamHelper = new StreamHelper();
65+
AtomicReference<ChatCompletionResponseBuilder> contentBlockReference = new AtomicReference<>();
66+
67+
AnthropicApi.PingEvent pingEvent = new AnthropicApi.PingEvent(AnthropicApi.EventType.PING);
68+
69+
AnthropicApi.ChatCompletionResponse response = streamHelper.eventToChatCompletionResponse(pingEvent,
70+
contentBlockReference);
71+
72+
assertThat(response).isNotNull();
73+
}
74+
6275
}

spring-ai-rag/src/test/java/org/springframework/ai/rag/QueryTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,22 @@ void whenCompareQueryToNullThenNotEqual() {
7878
assertThat(query).isNotEqualTo(null);
7979
}
8080

81+
@Test
82+
void whenCompareQueryToDifferentTypeThenNotEqual() {
83+
Query query = new Query("Test query");
84+
String notAQuery = "Test query";
85+
86+
assertThat(query).isNotEqualTo(notAQuery);
87+
}
88+
89+
@Test
90+
void toStringReturnsExpectedFormat() {
91+
Query query = new Query("Test query text");
92+
String toString = query.toString();
93+
94+
assertThat(toString).contains("Query");
95+
assertThat(toString).contains("text");
96+
assertThat(toString).contains("Test query text");
97+
}
98+
8199
}

spring-ai-rag/src/test/java/org/springframework/ai/rag/preretrieval/query/expansion/MultiQueryExpanderTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.ai.chat.prompt.PromptTemplate;
2323

2424
import static org.assertj.core.api.Assertions.assertThatThrownBy;
25+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
2526
import static org.mockito.Mockito.mock;
2627

2728
/**
@@ -69,4 +70,19 @@ void whenPromptHasMissingQueryPlaceholderThenThrow() {
6970
.hasMessageContaining("query");
7071
}
7172

73+
@Test
74+
void whenBuilderIsNullThenThrow() {
75+
assertThatThrownBy(() -> MultiQueryExpander.builder().build()).isInstanceOf(IllegalArgumentException.class)
76+
.hasMessageContaining("chatClientBuilder cannot be null");
77+
}
78+
79+
@Test
80+
void whenPromptTemplateIsNullThenUseDefault() {
81+
MultiQueryExpander queryExpander = MultiQueryExpander.builder()
82+
.chatClientBuilder(mock(ChatClient.Builder.class))
83+
.promptTemplate(null)
84+
.build();
85+
assertThat(queryExpander).isNotNull();
86+
}
87+
7288
}

0 commit comments

Comments
 (0)