refactor(merge,split,json): adopt streaming approach and standardize types, address gradle warnings (#5803)

Co-authored-by: Anthony Stirling <[email protected]>
Co-authored-by: Balázs <[email protected]>
This commit is contained in:
Balázs Szücs
2026-03-02 21:55:07 +00:00
committed by GitHub
co-authored by Anthony Stirling Balázs
parent 0c46f77179
commit fd1b7abc83
66 changed files with 1425 additions and 1430 deletions
@@ -25,6 +25,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.general.SplitPdfBySizeOrCountRequest;
import stirling.software.common.service.CustomPDFDocumentFactory;
@@ -69,16 +70,15 @@ class SplitPdfBySizeControllerTest {
request.setSplitType(1); // Page count
request.setSplitValue("2");
when(pdfDocumentFactory.load(any(byte[].class)))
.thenAnswer(inv -> Loader.loadPDF((byte[]) inv.getArgument(0)));
when(pdfDocumentFactory.load(any(MultipartFile.class)))
.thenAnswer(inv -> Loader.loadPDF(((MultipartFile) inv.getArgument(0)).getBytes()));
when(pdfDocumentFactory.createNewDocumentBasedOnOldDocument(any(PDDocument.class)))
.thenAnswer(inv -> new PDDocument());
ResponseEntity<byte[]> response = controller.autoSplitPdf(request);
ResponseEntity<?> response = controller.autoSplitPdf(request);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotEmpty();
assertThat(response.getHeaders().getContentType())
.isEqualTo(MediaType.APPLICATION_OCTET_STREAM);
}
@@ -104,15 +104,19 @@ class SplitPdfBySizeControllerTest {
request.setSplitType(2); // Document count
request.setSplitValue("3"); // Split into 3 docs (2 pages each)
when(pdfDocumentFactory.load(any(byte[].class)))
.thenAnswer(inv -> Loader.loadPDF((byte[]) inv.getArgument(0)));
when(pdfDocumentFactory.load(any(org.springframework.web.multipart.MultipartFile.class)))
.thenAnswer(
inv ->
Loader.loadPDF(
((org.springframework.web.multipart.MultipartFile)
inv.getArgument(0))
.getBytes()));
when(pdfDocumentFactory.createNewDocumentBasedOnOldDocument(any(PDDocument.class)))
.thenAnswer(inv -> new PDDocument());
ResponseEntity<byte[]> response = controller.autoSplitPdf(request);
ResponseEntity<?> response = controller.autoSplitPdf(request);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotEmpty();
}
}
@@ -13,10 +13,12 @@ import org.springframework.mock.web.MockMultipartFile;
import stirling.software.common.service.CustomPDFDocumentFactory;
import stirling.software.common.util.PdfToCbzUtils;
import stirling.software.common.util.TempFileManager;
public class PdfToCbzUtilsTest {
@Mock private CustomPDFDocumentFactory pdfDocumentFactory;
@Mock private TempFileManager tempFileManager;
@BeforeEach
public void setUp() {
@@ -42,7 +44,9 @@ public class PdfToCbzUtilsTest {
IllegalArgumentException exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() -> PdfToCbzUtils.convertPdfToCbz(null, 300, pdfDocumentFactory));
() ->
PdfToCbzUtils.convertPdfToCbz(
null, 300, pdfDocumentFactory, tempFileManager));
Assertions.assertEquals("File cannot be null or empty", exception.getMessage());
}
@@ -54,7 +58,9 @@ public class PdfToCbzUtilsTest {
IllegalArgumentException exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() -> PdfToCbzUtils.convertPdfToCbz(emptyFile, 300, pdfDocumentFactory));
() ->
PdfToCbzUtils.convertPdfToCbz(
emptyFile, 300, pdfDocumentFactory, tempFileManager));
Assertions.assertEquals("File cannot be null or empty", exception.getMessage());
}
@@ -66,7 +72,9 @@ public class PdfToCbzUtilsTest {
IllegalArgumentException exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() -> PdfToCbzUtils.convertPdfToCbz(nonPdfFile, 300, pdfDocumentFactory));
() ->
PdfToCbzUtils.convertPdfToCbz(
nonPdfFile, 300, pdfDocumentFactory, tempFileManager));
Assertions.assertEquals("File must be in PDF format", exception.getMessage());
}
@@ -84,7 +92,9 @@ public class PdfToCbzUtilsTest {
// structure
Assertions.assertThrows(
Exception.class,
() -> PdfToCbzUtils.convertPdfToCbz(pdfFile, 300, pdfDocumentFactory));
() ->
PdfToCbzUtils.convertPdfToCbz(
pdfFile, 300, pdfDocumentFactory, tempFileManager));
// Verify that load was called
Mockito.verify(pdfDocumentFactory).load(pdfFile);
@@ -27,7 +27,7 @@ import stirling.software.common.service.UserServiceInterface;
class PdfMetadataServiceBasicTest {
private PdfMetadataService pdfMetadataService;
private final String STIRLING_PDF_LABEL = "Stirling PDF";
private static final String STIRLING_PDF_LABEL = "Stirling PDF";
@BeforeEach
void setUp() {
@@ -33,7 +33,7 @@ class PdfMetadataServiceTest {
@Mock private ApplicationProperties applicationProperties;
@Mock private UserServiceInterface userService;
private PdfMetadataService pdfMetadataService;
private final String STIRLING_PDF_LABEL = "Stirling PDF";
private static final String STIRLING_PDF_LABEL = "Stirling PDF";
@BeforeEach
void setUp() {
@@ -28,8 +28,8 @@ class SignatureServiceTest {
private SharedSignatureService signatureService;
private Path personalSignatureFolder;
private Path sharedSignatureFolder;
private final String ALL_USERS_FOLDER = "ALL_USERS";
private final String TEST_USER = "testUser";
private static final String ALL_USERS_FOLDER = "ALL_USERS";
private static final String TEST_USER = "testUser";
@BeforeEach
void setUp() throws IOException {