Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void streamFunctionCallTest() {
.collect(Collectors.joining());
logger.info("Response: {}", content);

assertThat(content).isNotEmpty().withFailMessage("Content returned from OpenAI model is empty");
assertThat(content).withFailMessage("Content returned from OpenAI model is empty").isNotEmpty();
assertThat(content).contains("30", "10", "15");

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ensureBeansGetsCreated() {
void add_shouldInsertSingleMessage(String content, MessageType messageType) {
this.contextRunner.run(context -> {
var chatMemory = context.getBean(ChatMemoryRepository.class);
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
var sessionId = UUID.randomUUID().toString();
var message = switch (messageType) {
case ASSISTANT -> new AssistantMessage(content);
Expand Down Expand Up @@ -109,7 +109,7 @@ void add_shouldInsertSingleMessage(String content, MessageType messageType) {
void add_shouldInsertMessages() {
this.contextRunner.run(context -> {
var chatMemory = context.getBean(ChatMemoryRepository.class);
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
var sessionId = UUID.randomUUID().toString();
var messages = List.<Message>of(new AssistantMessage("Message from assistant"),
new UserMessage("Message from user"));
Expand Down Expand Up @@ -147,7 +147,7 @@ void add_shouldInsertMessages() {
void get_shouldReturnMessages() {
this.contextRunner.run(context -> {
var chatMemory = context.getBean(ChatMemoryRepository.class);
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
var sessionId = UUID.randomUUID().toString();

var messages = List.<Message>of(new AssistantMessage("Message from assistant 1 - " + sessionId),
Expand All @@ -174,7 +174,7 @@ void get_shouldReturnMessages() {
void get_afterMultipleAdds_shouldReturnMessagesInSameOrder() {
this.contextRunner.run(context -> {
var chatMemory = context.getBean(ChatMemoryRepository.class);
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
var sessionId = UUID.randomUUID().toString();
var userMessage = new UserMessage("Message from user - " + sessionId);
var assistantMessage = new AssistantMessage("Message from assistant - " + sessionId);
Expand All @@ -200,7 +200,7 @@ void get_afterMultipleAdds_shouldReturnMessagesInSameOrder() {
void clear_shouldDeleteMessages() {
this.contextRunner.run(context -> {
var chatMemory = context.getBean(ChatMemoryRepository.class);
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
var sessionId = UUID.randomUUID().toString();

var messages = List.<Message>of(new AssistantMessage("Message from assistant - " + sessionId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void handleToolResponseMessage() {
}

@Test
@SuppressWarnings("DoubleBraceInitialization")
void saveAndFindSystemMessageWithMetadata() {
var conversationId = UUID.randomUUID().toString();
Map<String, Object> customMetadata = Map.of("priority", "high", "source", "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void testCopyDoesNotShareMetadataReference() {
}

@Test
@SuppressWarnings("SelfAssertion")
void testEqualsWithSelf() {
AnthropicChatOptions options = AnthropicChatOptions.builder().model("test").build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,9 @@ void testFourBreakpointLimitEnforcement() throws Exception {
int cacheControlCount = countCacheControlOccurrences(requestBody);

// Verify we don't exceed Anthropic's 4-breakpoint limit
assertThat(cacheControlCount).isLessThanOrEqualTo(4)
.withFailMessage("Cache breakpoints should not exceed 4, but found %d", cacheControlCount);
assertThat(cacheControlCount)
.withFailMessage("Cache breakpoints should not exceed 4, but found %d", cacheControlCount)
.isLessThanOrEqualTo(4);
}

@Test
Expand Down Expand Up @@ -608,8 +609,9 @@ else if (systemNode.isTextual()) {
// Simple text system message should still have cache_control applied at the
// message level
// Check if there's a cache_control field at the system level or in a wrapper
assertThat(requestBody.toString()).contains("cache_control")
.withFailMessage("SYSTEM_ONLY strategy should include cache_control in wire format");
assertThat(requestBody.toString())
.withFailMessage("SYSTEM_ONLY strategy should include cache_control in wire format")
.contains("cache_control");
}
}

Expand Down Expand Up @@ -690,8 +692,9 @@ void testComplexMultiBreakpointScenario() throws Exception {

// Verify proper ordering and cache control placement
int cacheControlCount = countCacheControlOccurrences(requestBody);
assertThat(cacheControlCount).isLessThanOrEqualTo(4)
.withFailMessage("Complex scenario should not exceed 4 cache breakpoints, found %d", cacheControlCount);
assertThat(cacheControlCount)
.withFailMessage("Complex scenario should not exceed 4 cache breakpoints, found %d", cacheControlCount)
.isLessThanOrEqualTo(4);

// Verify cache_control is only on the LAST blocks of each section (system, tools)
// This ensures proper breakpoint placement according to Anthropic's requirements
Expand Down Expand Up @@ -732,9 +735,9 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
if (systemNode.isArray()) {
for (int i = 0; i < systemNode.size() - 1; i++) {
JsonNode systemBlock = systemNode.get(i);
assertThat(systemBlock.has("cache_control")).isFalse()
.withFailMessage("Only the last system block should have cache_control, but block %d has it",
i);
assertThat(systemBlock.has("cache_control"))
.withFailMessage("Only the last system block should have cache_control, but block %d has it", i)
.isFalse();
}
}
}
Expand All @@ -745,8 +748,9 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
if (toolsArray.isArray()) {
for (int i = 0; i < toolsArray.size() - 1; i++) {
JsonNode tool = toolsArray.get(i);
assertThat(tool.has("cache_control")).isFalse()
.withFailMessage("Only the last tool should have cache_control, but tool %d has it", i);
assertThat(tool.has("cache_control"))
.withFailMessage("Only the last tool should have cache_control, but tool %d has it", i)
.isFalse();
}
}
}
Expand All @@ -767,9 +771,10 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
if (i != messagesArray.size() - 2 || j != contentArray.size() - 1) {
// Only the last content block of the second-to-last
// message should have cache_control
assertThat(contentBlock.has("cache_control")).isFalse()
assertThat(contentBlock.has("cache_control"))
.withFailMessage(
"Unexpected cache_control placement in message %d, content block %d", i, j);
"Unexpected cache_control placement in message %d, content block %d", i, j)
.isFalse();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void testStreaming() {
.collect(Collectors.joining());
logger.info("Response: {}", content);

assertThat(counter.get()).isGreaterThan(8).as("More than 8 chuncks because there are 8 planets");
assertThat(counter.get()).withFailMessage("More than 8 chunks because there are 8 planets").isGreaterThan(8);

assertThat(content).contains("Earth", "Mars", "Jupiter");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void streamFunctionCallTest() {
.collect(Collectors.joining());
logger.info("Response: {}", content);

assertThat(counter.get()).isGreaterThan(30).as("The response should be chunked in more than 30 messages");
assertThat(counter.get()).withFailMessage("The response should be chunked in more than 30 messages")
.isGreaterThan(30);

assertThat(content).contains("30", "10", "15");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ public void toolFunctionCallWithUsage() {

ChatResponse chatResponse = this.chatModel.call(prompt);
assertThat(chatResponse).isNotNull();
assertThat(chatResponse.getResult().getOutput());
assertThat(chatResponse.getResult().getOutput()).isNotNull();
assertThat(chatResponse.getResult().getOutput().getText()).contains("San Francisco");
assertThat(chatResponse.getResult().getOutput().getText()).contains("30");
// 这个 total token 是第一次 chat 以及 tool call 之后的两次请求 token 总和

// the total token is first chat and tool call request
assertThat(chatResponse.getMetadata().getUsage().getTotalTokens()).isLessThan(700).isGreaterThan(280);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void prefixCompletionTest() {
.build();
Prompt prompt = new Prompt(List.of(userMessage, assistantMessage));
ChatResponse response = this.chatModel.call(prompt);
assertThat(response.getResult().getOutput().getText().equals(",2,3]}}"));
assertThat(response.getResult().getOutput().getText()).isEqualTo(",2,3]}}");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public boolean equals(Object o) {
if (!(o instanceof GoogleGenAiChatOptions that)) {
return false;
}
return this.googleSearchRetrieval == that.googleSearchRetrieval
return Objects.equals(this.googleSearchRetrieval, that.googleSearchRetrieval)
&& Objects.equals(this.stopSequences, that.stopSequences)
&& Objects.equals(this.temperature, that.temperature) && Objects.equals(this.topP, that.topP)
&& Objects.equals(this.topK, that.topK) && Objects.equals(this.candidateCount, that.candidateCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.mistralai;

import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

Expand Down Expand Up @@ -64,15 +65,8 @@ void moderationAsPositiveTest() {
assertThat(result.isFlagged()).isTrue();

CategoryScores scores = result.getCategoryScores();
assertThat(scores.getSexual()).isNotNull();
assertThat(scores.getHate()).isNotNull();
assertThat(scores.getViolence()).isNotNull();
assertThat(scores.getDangerousAndCriminalContent()).isNotNull();
assertThat(scores.getSelfHarm()).isNotNull();
assertThat(scores.getHealth()).isNotNull();
assertThat(scores.getFinancial()).isNotNull();
assertThat(scores.getLaw()).isNotNull();
assertThat(scores.getPii()).isNotNull();
assertThat(scores.getSexual()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getViolence()).isCloseTo(1.0d, Offset.offset(0.2d));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ollamaThinkingMetadataCaptured() {
chatResponse.getResults().forEach(generation -> {
ChatGenerationMetadata chatGenerationMetadata = generation.getMetadata();
assertThat(chatGenerationMetadata).isNotNull();
assertThat(chatGenerationMetadata.containsKey("thinking"));
assertThat(chatGenerationMetadata.containsKey("thinking")).isTrue();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void testFromOptions_webSearchOptions() {
}

@Test
@SuppressWarnings("SelfAssertion")
void testEqualsAndHashCode() {
OpenAiChatOptions options1 = OpenAiChatOptions.builder()
.model("test-model")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void testBuilderWithExistingOptions() {
}

@Test
@SuppressWarnings("SelfAssertion")
void testEqualsAndHashCode() {
OpenAiImageOptions options1 = OpenAiImageOptions.builder()
.N(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ record Items(@JsonProperty(required = true, value = "explanation") String explan

// Check if the order is correct as specified in the schema. Steps should come
// first before final answer.
assertThat(content.startsWith("{\"steps\":{\"items\":["));
assertThat(content).startsWith("{\"steps\":{\"items\":[");

MathReasoning mathReasoning = outputConverter.convert(content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.openai.moderation;

import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

Expand Down Expand Up @@ -59,7 +60,6 @@ void moderationAsUrlTestPositive() {
assertThat(moderation.getId()).isNotEmpty();
assertThat(moderation.getResults()).isNotNull();
assertThat(moderation.getResults().size()).isNotZero();
System.out.println(moderation.getResults().toString());

assertThat(moderation.getId()).isNotNull();
assertThat(moderation.getModel()).isNotNull();
Expand All @@ -68,30 +68,11 @@ void moderationAsUrlTestPositive() {
assertThat(result.isFlagged()).isTrue();
Categories categories = result.getCategories();
assertThat(categories).isNotNull();
assertThat(categories.isSexual()).isNotNull();
assertThat(categories.isHate()).isNotNull();
assertThat(categories.isHarassment()).isNotNull();
assertThat(categories.isSelfHarm()).isNotNull();
assertThat(categories.isSexualMinors()).isNotNull();
assertThat(categories.isHateThreatening()).isNotNull();
assertThat(categories.isViolenceGraphic()).isNotNull();
assertThat(categories.isSelfHarmIntent()).isNotNull();
assertThat(categories.isSelfHarmInstructions()).isNotNull();
assertThat(categories.isHarassmentThreatening()).isNotNull();
assertThat(categories.isViolence()).isTrue();

CategoryScores scores = result.getCategoryScores();
assertThat(scores.getSexual()).isNotNull();
assertThat(scores.getHate()).isNotNull();
assertThat(scores.getHarassment()).isNotNull();
assertThat(scores.getSelfHarm()).isNotNull();
assertThat(scores.getSexualMinors()).isNotNull();
assertThat(scores.getHateThreatening()).isNotNull();
assertThat(scores.getViolenceGraphic()).isNotNull();
assertThat(scores.getSelfHarmIntent()).isNotNull();
assertThat(scores.getSelfHarmInstructions()).isNotNull();
assertThat(scores.getHarassmentThreatening()).isNotNull();
assertThat(scores.getViolence()).isNotNull();
assertThat(scores.getSexual()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getViolence()).isCloseTo(1.0d, Offset.offset(0.2d));

}

Expand All @@ -113,7 +94,6 @@ void moderationAsUrlTestNegative() {
assertThat(moderation.getId()).isNotEmpty();
assertThat(moderation.getResults()).isNotNull();
assertThat(moderation.getResults().size()).isNotZero();
System.out.println(moderation.getResults().toString());

assertThat(moderation.getId()).isNotNull();
assertThat(moderation.getModel()).isNotNull();
Expand All @@ -134,17 +114,17 @@ void moderationAsUrlTestNegative() {
assertThat(categories.isViolence()).isFalse();

CategoryScores scores = result.getCategoryScores();
assertThat(scores.getSexual()).isNotNull();
assertThat(scores.getHate()).isNotNull();
assertThat(scores.getHarassment()).isNotNull();
assertThat(scores.getSelfHarm()).isNotNull();
assertThat(scores.getSexualMinors()).isNotNull();
assertThat(scores.getHateThreatening()).isNotNull();
assertThat(scores.getViolenceGraphic()).isNotNull();
assertThat(scores.getSelfHarmIntent()).isNotNull();
assertThat(scores.getSelfHarmInstructions()).isNotNull();
assertThat(scores.getHarassmentThreatening()).isNotNull();
assertThat(scores.getViolence()).isNotNull();
assertThat(scores.getSexual()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getHate()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getHarassment()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getSelfHarm()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getSexualMinors()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getHateThreatening()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getViolenceGraphic()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getSelfHarmIntent()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getSelfHarmInstructions()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getHarassmentThreatening()).isCloseTo(0.0d, Offset.offset(0.1d));
assertThat(scores.getViolence()).isCloseTo(0.0d, Offset.offset(0.1d));

}

Expand Down
Loading