In addition to the existing test scenario, it would be beneficial to add a new test case that validates the behavior when the Prompt
is null
. This is because when the messageType
is either MessageType.SYSTEM
or MessageType.USER
, the textContent
parameter cannot be null
, and an IllegalArgumentException
should be thrown in such cases.
https://github.com/spring-projects/spring-ai/blob/4c83fe830211756e098e4ce72ed10a5644bb2968/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/AnthropicAutoConfigurationIT.java#L50
//This is just a sample using AssertJ
@Test
void ThrowIllegalArgumentExceptionWhenPromptIsNull() {
contextRunner.run(context -> {
AnthropicChatModel chatModel = context.getBean(AnthropicChatModel.class);
assertThatThrownBy(() -> chatModel.call(null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Content must not be null for SYSTEM or USER messages");
});
}