diff --git a/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateBuilderTests.java b/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateBuilderTests.java index 6b23d2f8e73..001433c2bc9 100644 --- a/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateBuilderTests.java +++ b/spring-ai-model/src/test/java/org/springframework/ai/chat/prompt/PromptTemplateBuilderTests.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatThrownBy; /** @@ -134,14 +135,8 @@ void builderWithMultipleMissingVariablesShouldThrow() { .template("Processing {item} with {type} at {level}") .build(); - try { - promptTemplate.render(); - Assertions.fail("Expected IllegalStateException was not thrown."); - } - catch (IllegalStateException e) { - assertThat(e.getMessage()).contains("Not all variables were replaced in the template"); - assertThat(e.getMessage()).contains("item", "type", "level"); - } + assertThatIllegalStateException().isThrownBy(promptTemplate::render) + .withMessageContainingAll("Not all variables were replaced in the template", "item", "type", "level"); } @Test @@ -155,13 +150,8 @@ void builderWithPartialVariablesShouldThrow() { .variables(variables) .build(); - try { - promptTemplate.render(); - Assertions.fail("Expected IllegalStateException was not thrown."); - } - catch (IllegalStateException e) { - assertThat(e.getMessage()).contains("Missing variable names are: [type]"); - } + assertThatIllegalStateException().isThrownBy(promptTemplate::render) + .withMessageContaining("Missing variable names are: [type]"); } @Test diff --git a/vector-stores/spring-ai-neo4j-store/src/test/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStoreIT.java b/vector-stores/spring-ai-neo4j-store/src/test/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStoreIT.java index 9c73f292c8d..b851269cb59 100644 --- a/vector-stores/spring-ai-neo4j-store/src/test/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStoreIT.java +++ b/vector-stores/spring-ai-neo4j-store/src/test/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStoreIT.java @@ -24,7 +24,6 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; @@ -53,6 +52,7 @@ import org.springframework.context.annotation.Primary; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Gerrit Meier @@ -207,14 +207,10 @@ void searchWithFilters() { assertThat(results).hasSize(1); assertThat(results.get(0).getId()).isEqualTo(bgDocument.getId()); - try { - vectorStore - .similaritySearch(SearchRequest.from(searchRequest).filterExpression("country == NL").build()); - Assert.fail("Invalid filter expression should have been cached!"); - } - catch (FilterExpressionTextParser.FilterExpressionParseException e) { - assertThat(e.getMessage()).contains("Line: 1:17, Error: no viable alternative at input 'NL'"); - } + assertThatExceptionOfType(FilterExpressionTextParser.FilterExpressionParseException.class) + .isThrownBy(() -> vectorStore + .similaritySearch(SearchRequest.from(searchRequest).filterExpression("country == NL").build())) + .withMessageContaining("Line: 1:17, Error: no viable alternative at input 'NL'"); }); }