mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 03:20:46 +02:00
# Description of Changes Introduced a new `common` module for shared libs and commonly used classes. See the screenshot below for the file structure and classes that have been moved. --- <img width="452" alt="Screenshot 2025-05-22 at 11 46 56" src="https://github.com/user-attachments/assets/c9badabc-48f9-4079-b83e-7cfde0fb840f" /> <img width="470" alt="Screenshot 2025-05-22 at 11 47 30" src="https://github.com/user-attachments/assets/e8315b09-2e78-4c50-b9de-4dd9b9b0ecb1" /> ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
97 lines
3.3 KiB
Java
97 lines
3.3 KiB
Java
package stirling.software.SPDF.controller.api;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.CsvSource;
|
|
import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
|
|
|
class RearrangePagesPDFControllerTest {
|
|
|
|
@Mock private CustomPDFDocumentFactory mockPdfDocumentFactory;
|
|
|
|
private RearrangePagesPDFController sut;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
MockitoAnnotations.openMocks(this);
|
|
sut = new RearrangePagesPDFController(mockPdfDocumentFactory);
|
|
}
|
|
|
|
/** Tests the behavior of the oddEvenMerge method when there are no pages in the document. */
|
|
@Test
|
|
void oddEvenMerge_noPages() {
|
|
int totalNumberOfPages = 0;
|
|
|
|
List<Integer> newPageOrder = sut.oddEvenMerge(totalNumberOfPages);
|
|
|
|
assertNotNull(newPageOrder, "Returning null instead of page order list");
|
|
assertEquals(List.of(), newPageOrder, "Page order doesn't match");
|
|
}
|
|
|
|
/**
|
|
* Tests the behavior of the oddEvenMerge method when there are odd total pages in the document.
|
|
*/
|
|
@Test
|
|
void oddEvenMerge_oddTotalPageNumber() {
|
|
int totalNumberOfPages = 5;
|
|
|
|
List<Integer> newPageOrder = sut.oddEvenMerge(totalNumberOfPages);
|
|
|
|
assertNotNull(newPageOrder, "Returning null instead of page order list");
|
|
assertEquals(Arrays.asList(0, 3, 1, 4, 2), newPageOrder, "Page order doesn't match");
|
|
}
|
|
|
|
/**
|
|
* Tests the behavior of the oddEvenMerge method when there are even total pages in the
|
|
* document.
|
|
*/
|
|
@Test
|
|
void oddEvenMerge_evenTotalPageNumber() {
|
|
int totalNumberOfPages = 6;
|
|
|
|
List<Integer> newPageOrder = sut.oddEvenMerge(totalNumberOfPages);
|
|
|
|
assertNotNull(newPageOrder, "Returning null instead of page order list");
|
|
assertEquals(Arrays.asList(0, 3, 1, 4, 2, 5), newPageOrder, "Page order doesn't match");
|
|
}
|
|
|
|
/**
|
|
* Tests the behavior of the oddEvenMerge method with multiple test cases of multiple pages.
|
|
*
|
|
* @param totalNumberOfPages The total number of pages in the document.
|
|
* @param expectedPageOrder The expected order of the pages after rearranging.
|
|
*/
|
|
@ParameterizedTest
|
|
@CsvSource({
|
|
"1, '0'",
|
|
"2, '0,1'",
|
|
"3, '0,2,1'",
|
|
"4, '0,2,1,3'",
|
|
"5, '0,3,1,4,2'",
|
|
"6, '0,3,1,4,2,5'",
|
|
"10, '0,5,1,6,2,7,3,8,4,9'",
|
|
"50, '0,25,1,26,2,27,3,28,4,29,5,30,6,31,7,32,8,33,9,34,10,35,"
|
|
+ "11,36,12,37,13,38,14,39,15,40,16,41,17,42,18,43,19,44,20,45,21,46,"
|
|
+ "22,47,23,48,24,49'"
|
|
})
|
|
void oddEvenMerge_multi_test(int totalNumberOfPages, String expectedPageOrder) {
|
|
List<Integer> newPageOrder = sut.oddEvenMerge(totalNumberOfPages);
|
|
|
|
assertNotNull(newPageOrder, "Returning null instead of page order list");
|
|
assertEquals(
|
|
Arrays.stream(expectedPageOrder.split(",")).map(Integer::parseInt).toList(),
|
|
newPageOrder,
|
|
"Page order doesn't match");
|
|
}
|
|
}
|