test: use junit assertions for pdf viewer compatibility

Agent-Logs-Url: https://github.com/kekingcn/kkFileView/sessions/287f0212-d368-4b59-ae70-0374fb3fe76f

Co-authored-by: klboke <18591662+klboke@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-09 02:48:24 +00:00
committed by GitHub
parent 5499150395
commit 530304b832

View File

@@ -6,26 +6,29 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PdfViewerCompatibilityTests { public class PdfViewerCompatibilityTests {
@Test @Test
void shouldLoadCompatibilityModuleBeforePdfJs() throws IOException { void shouldLoadCompatibilityModuleBeforePdfJs() throws IOException {
String viewerHtml = readResource("/static/pdfjs/web/viewer.html"); String viewerHtml = readResource("/static/pdfjs/web/viewer.html");
assert viewerHtml.contains("<script src=\"compatibility.mjs\" type=\"module\"></script>"); assertTrue(viewerHtml.contains("<script src=\"compatibility.mjs\" type=\"module\"></script>"));
assert viewerHtml.indexOf("compatibility.mjs") < viewerHtml.indexOf("../build/pdf.mjs"); assertTrue(viewerHtml.indexOf("compatibility.mjs") < viewerHtml.indexOf("../build/pdf.mjs"));
} }
@Test @Test
void shouldLoadCompatibilityModuleInPdfWorker() throws IOException { void shouldLoadCompatibilityModuleInPdfWorker() throws IOException {
String workerScript = readResource("/static/pdfjs/build/pdf.worker.mjs"); String workerScript = readResource("/static/pdfjs/build/pdf.worker.mjs");
assert workerScript.contains("import \"../web/compatibility.mjs\";"); assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";"));
} }
private String readResource(String resourcePath) throws IOException { private String readResource(String resourcePath) throws IOException {
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) { try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
assert inputStream != null; assertNotNull(inputStream);
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
} }
} }