Skip to content

Commit 348085a

Browse files
alxkmilayaperumalg
authored andcommitted
test: Add comprehensive test coverage for AnthropicApi.Builder
Co-authored-by: Oleksandr Klymenko <[email protected]> Signed-off-by: Oleksandr Klymenko <[email protected]>
1 parent ad691e5 commit 348085a

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
/**
5151
* @author Filip Hrisafov
52+
* @author Oleksandr Klymenko
5253
*/
5354
public class AnthropicApiBuilderTests {
5455

@@ -132,6 +133,80 @@ void testInvalidResponseErrorHandler() {
132133
.hasMessageContaining("responseErrorHandler cannot be null");
133134
}
134135

136+
@Test
137+
void testApiKeyStringOverload() {
138+
AnthropicApi api = AnthropicApi.builder().apiKey("test-string-key").build();
139+
140+
assertThat(api).isNotNull();
141+
}
142+
143+
@Test
144+
void testInvalidAnthropicVersion() {
145+
assertThatThrownBy(() -> AnthropicApi.builder().apiKey(TEST_API_KEY).anthropicVersion(null).build())
146+
.isInstanceOf(IllegalArgumentException.class)
147+
.hasMessageContaining("anthropicVersion cannot be null");
148+
}
149+
150+
@Test
151+
void testInvalidAnthropicBetaFeatures() {
152+
assertThatThrownBy(() -> AnthropicApi.builder().apiKey(TEST_API_KEY).anthropicBetaFeatures(null).build())
153+
.isInstanceOf(IllegalArgumentException.class)
154+
.hasMessageContaining("anthropicBetaFeatures cannot be null");
155+
}
156+
157+
@Test
158+
void testDefaultValues() {
159+
AnthropicApi api = AnthropicApi.builder().apiKey(TEST_API_KEY).build();
160+
161+
assertThat(api).isNotNull();
162+
}
163+
164+
@Test
165+
void testBuilderIndependence() {
166+
AnthropicApi.Builder builder1 = AnthropicApi.builder().apiKey("key1").baseUrl("https://api1.example.com");
167+
168+
AnthropicApi.Builder builder2 = AnthropicApi.builder().apiKey("key2").baseUrl("https://api2.example.com");
169+
170+
AnthropicApi api1 = builder1.build();
171+
AnthropicApi api2 = builder2.build();
172+
173+
assertThat(api1).isNotNull();
174+
assertThat(api2).isNotNull();
175+
}
176+
177+
@Test
178+
void testCustomAnthropicVersionAndBetaFeatures() {
179+
AnthropicApi api = AnthropicApi.builder()
180+
.apiKey(TEST_API_KEY)
181+
.anthropicVersion("version")
182+
.anthropicBetaFeatures("custom-beta-feature")
183+
.build();
184+
185+
assertThat(api).isNotNull();
186+
}
187+
188+
@Test
189+
void testApiKeyStringNullValidation() {
190+
assertThatThrownBy(() -> AnthropicApi.builder().apiKey((String) null).build())
191+
.isInstanceOf(IllegalArgumentException.class)
192+
.hasMessageContaining("simpleApiKey cannot be null");
193+
}
194+
195+
@Test
196+
void testChainedBuilderMethods() {
197+
AnthropicApi api = AnthropicApi.builder()
198+
.baseUrl(TEST_BASE_URL)
199+
.completionsPath(TEST_COMPLETIONS_PATH)
200+
.apiKey(TEST_API_KEY)
201+
.anthropicBetaFeatures("feature1,feature2")
202+
.restClientBuilder(RestClient.builder())
203+
.webClientBuilder(WebClient.builder())
204+
.responseErrorHandler(mock(ResponseErrorHandler.class))
205+
.build();
206+
207+
assertThat(api).isNotNull();
208+
}
209+
135210
@Nested
136211
class MockRequests {
137212

0 commit comments

Comments
 (0)