From 175eaeb128f48fe4ae6d0fe4b2c399fdb8984318 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Jun 2026 15:13:37 +0000 Subject: [PATCH] test: make null-getFileName fallback assertions OS-independent Two tests construct a root path via Paths.get("/") and assert the "file name is null -> fall back to the full path string" branch using a hardcoded POSIX separator. On Windows Paths.get("/").toString() returns "\", so the assertions failed there while passing on Linux/macOS. The production code is correct (it intentionally falls back to the full Path.toString() when getFileName() is null); only the expected values were hardcoded to "/". Derive the expected string from the same Path object instead of hardcoding the separator. Paths.get("/") still yields a null file name on every OS, so the intended fallback branch stays exercised: - AiPromptSupportTest.buildPromptUsesFullPathWhenFileNameNull - MockAiGenerationProviderTest.generateFallsBackToFullPathWhenFileNameNull mvn test: Tests run: 174, Failures: 0, Errors: 0, Skipped: 1. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01FHNW6HtnBwNm3DFRGuHxfZ --- .../llamacpp/aiindex/prompt/AiPromptSupportTest.java | 7 ++++++- .../aiindex/provider/MockAiGenerationProviderTest.java | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/ladenthin/maven/llamacpp/aiindex/prompt/AiPromptSupportTest.java b/src/test/java/net/ladenthin/maven/llamacpp/aiindex/prompt/AiPromptSupportTest.java index 1835955..59c9b47 100644 --- a/src/test/java/net/ladenthin/maven/llamacpp/aiindex/prompt/AiPromptSupportTest.java +++ b/src/test/java/net/ladenthin/maven/llamacpp/aiindex/prompt/AiPromptSupportTest.java @@ -8,6 +8,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -32,7 +33,11 @@ public void buildPromptRendersFileNameAndSource() { @Test public void buildPromptUsesFullPathWhenFileNameNull() { AiPromptSupport support = new AiPromptSupport(Collections.singletonList(def("summary", "[%s] %s"))); - assertThat(support.buildPrompt("summary", Paths.get("/"), "x"), is("[/] x")); + // A root path has a null getFileName() on every OS, so buildPrompt falls back to the full + // path string. Derive the expected separator from the same Path so the assertion holds on + // Windows too (the root renders with the platform separator: "/" on POSIX, "\" on Windows). + Path root = Paths.get("/"); + assertThat(support.buildPrompt("summary", root, "x"), is("[" + root + "] x")); } @Test diff --git a/src/test/java/net/ladenthin/maven/llamacpp/aiindex/provider/MockAiGenerationProviderTest.java b/src/test/java/net/ladenthin/maven/llamacpp/aiindex/provider/MockAiGenerationProviderTest.java index d319aa9..b1f94b9 100644 --- a/src/test/java/net/ladenthin/maven/llamacpp/aiindex/provider/MockAiGenerationProviderTest.java +++ b/src/test/java/net/ladenthin/maven/llamacpp/aiindex/provider/MockAiGenerationProviderTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; +import java.nio.file.Path; import java.nio.file.Paths; import net.ladenthin.maven.llamacpp.aiindex.document.AiGenerationRequest; import net.ladenthin.maven.llamacpp.aiindex.document.AiMdHeader; @@ -30,9 +31,12 @@ public void generateUsesFileNameOnly() throws IOException { @Test public void generateFallsBackToFullPathWhenFileNameNull() throws IOException { - // A root path has a null getFileName(); the provider must use file.toString(). - AiGenerationRequest request = new AiGenerationRequest("summary", Paths.get("/"), "src", HEADER); - assertThat(provider.generate(request), is("Mock summary for /")); + // A root path has a null getFileName(); the provider must use file.toString(). Derive the + // expected separator from the same Path so the assertion holds on Windows too (the root + // renders with the platform separator: "/" on POSIX, "\" on Windows). + Path root = Paths.get("/"); + AiGenerationRequest request = new AiGenerationRequest("summary", root, "src", HEADER); + assertThat(provider.generate(request), is("Mock summary for " + root)); } @Test