Update ConvertPDFToMarkdownTest.java

This commit is contained in:
Ludy87 2025-08-10 12:30:09 +02:00
parent 789a3bd2a7
commit 0f0247f006
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -7,6 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.MockedConstruction; import org.mockito.MockedConstruction;
@ -39,7 +40,7 @@ class ConvertPDFToMarkdownTest {
} }
@Test @Test
void pdf_to_markdown_returns_markdown_bytes() throws Exception { void pdfToMarkdownReturnsMarkdownBytes() throws Exception {
byte[] md = "# heading\n\ncontent\n".getBytes(StandardCharsets.UTF_8); byte[] md = "# heading\n\ncontent\n".getBytes(StandardCharsets.UTF_8);
try (MockedConstruction<PDFToFile> construction = try (MockedConstruction<PDFToFile> construction =
@ -58,7 +59,7 @@ class ConvertPDFToMarkdownTest {
MockMultipartFile file = MockMultipartFile file =
new MockMultipartFile( new MockMultipartFile(
"fileInput", // muss zum Feldnamen in PDFFile passen "fileInput", // must match the field name in PDFFile
"input.pdf", "input.pdf",
"application/pdf", "application/pdf",
new byte[] {1, 2, 3}); new byte[] {1, 2, 3});
@ -68,24 +69,23 @@ class ConvertPDFToMarkdownTest {
.andExpect(header().string("Content-Type", "text/markdown")) .andExpect(header().string("Content-Type", "text/markdown"))
.andExpect(content().bytes(md)); .andExpect(content().bytes(md));
// Verifizieren, dass genau eine Instanz erzeugt wurde // Verify that exactly one instance was created
assert construction.constructed().size() == 1; assert construction.constructed().size() == 1;
// und dass das hochgeladene File an processPdfToMarkdown() durchgereicht wurde // And that the uploaded file was passed to processPdfToMarkdown()
PDFToFile created = construction.constructed().get(0); PDFToFile created = construction.constructed().get(0);
ArgumentCaptor<MultipartFile> captor = ArgumentCaptor.forClass(MultipartFile.class); ArgumentCaptor<MultipartFile> captor = ArgumentCaptor.forClass(MultipartFile.class);
verify(created, times(1)).processPdfToMarkdown(captor.capture()); verify(created, times(1)).processPdfToMarkdown(captor.capture());
MultipartFile passed = captor.getValue(); MultipartFile passed = captor.getValue();
// minimal plausi
org.junit.jupiter.api.Assertions.assertEquals( // Minimal plausibility checks
"input.pdf", passed.getOriginalFilename()); Assertions.assertEquals("input.pdf", passed.getOriginalFilename());
org.junit.jupiter.api.Assertions.assertEquals( Assertions.assertEquals("application/pdf", passed.getContentType());
"application/pdf", passed.getContentType());
} }
} }
@Test @Test
void pdf_to_markdown_when_service_throws_returns_500() throws Exception { void pdfToMarkdownWhenServiceThrowsReturns500() throws Exception {
try (MockedConstruction<PDFToFile> ignored = try (MockedConstruction<PDFToFile> ignored =
Mockito.mockConstruction( Mockito.mockConstruction(
PDFToFile.class, PDFToFile.class,