diff --git a/build.gradle b/build.gradle index f1a8427fb..7914b8d1f 100644 --- a/build.gradle +++ b/build.gradle @@ -256,7 +256,7 @@ launch4j { spotless { java { - target project.fileTree('src/main/java') + target project.fileTree('src').include('**/*.java') googleJavaFormat("1.25.2").aosp().reorderImports(false) diff --git a/src/test/java/stirling/software/SPDF/SPDFApplicationTest.java b/src/test/java/stirling/software/SPDF/SPDFApplicationTest.java index 3b05e8761..c4dae34bf 100644 --- a/src/test/java/stirling/software/SPDF/SPDFApplicationTest.java +++ b/src/test/java/stirling/software/SPDF/SPDFApplicationTest.java @@ -1,11 +1,6 @@ package stirling.software.SPDF; -import static org.junit.jupiter.api.Assertions.*; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,22 +11,15 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; import stirling.software.SPDF.model.ApplicationProperties; -import static java.nio.file.Files.createDirectories; -import static java.nio.file.Files.createFile; -import static java.nio.file.Files.delete; -import static java.nio.file.Files.exists; @ExtendWith(MockitoExtension.class) public class SPDFApplicationTest { - @Mock - private Environment env; + @Mock private Environment env; - @Mock - private ApplicationProperties applicationProperties; + @Mock private ApplicationProperties applicationProperties; - @InjectMocks - private SPDFApplication sPDFApplication; + @InjectMocks private SPDFApplication sPDFApplication; @BeforeEach public void setUp() { @@ -48,5 +36,4 @@ public class SPDFApplicationTest { public void testGetStaticPort() { assertEquals("8080", SPDFApplication.getStaticPort()); } - } diff --git a/src/test/java/stirling/software/SPDF/config/security/CustomLogoutSuccessHandlerTest.java b/src/test/java/stirling/software/SPDF/config/security/CustomLogoutSuccessHandlerTest.java index 37a9f86e6..72dd95418 100644 --- a/src/test/java/stirling/software/SPDF/config/security/CustomLogoutSuccessHandlerTest.java +++ b/src/test/java/stirling/software/SPDF/config/security/CustomLogoutSuccessHandlerTest.java @@ -1,27 +1,29 @@ package stirling.software.SPDF.config.security; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.io.IOException; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import stirling.software.SPDF.model.ApplicationProperties; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class CustomLogoutSuccessHandlerTest { - @Mock - private ApplicationProperties applicationProperties; + @Mock private ApplicationProperties applicationProperties; - @InjectMocks - private CustomLogoutSuccessHandler customLogoutSuccessHandler; + @InjectMocks private CustomLogoutSuccessHandler customLogoutSuccessHandler; @Test void testSuccessfulLogout() throws IOException { @@ -44,7 +46,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken oAuth2AuthenticationToken = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -70,7 +73,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -100,7 +104,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter(error)).thenReturn("true"); @@ -125,7 +130,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -151,7 +157,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -179,7 +186,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -209,7 +217,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); @@ -240,7 +249,8 @@ class CustomLogoutSuccessHandlerTest { HttpServletResponse response = mock(HttpServletResponse.class); OAuth2AuthenticationToken authentication = mock(OAuth2AuthenticationToken.class); ApplicationProperties.Security security = mock(ApplicationProperties.Security.class); - ApplicationProperties.Security.OAUTH2 oauth = mock(ApplicationProperties.Security.OAUTH2.class); + ApplicationProperties.Security.OAUTH2 oauth = + mock(ApplicationProperties.Security.OAUTH2.class); when(response.isCommitted()).thenReturn(false); when(request.getParameter("oAuth2AuthenticationErrorWeb")).thenReturn(null); diff --git a/src/test/java/stirling/software/SPDF/config/security/database/DatabaseConfigTest.java b/src/test/java/stirling/software/SPDF/config/security/database/DatabaseConfigTest.java index 6d933d721..0118e8e32 100644 --- a/src/test/java/stirling/software/SPDF/config/security/database/DatabaseConfigTest.java +++ b/src/test/java/stirling/software/SPDF/config/security/database/DatabaseConfigTest.java @@ -1,6 +1,12 @@ package stirling.software.SPDF.config.security.database; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import javax.sql.DataSource; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -8,18 +14,14 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; + import stirling.software.SPDF.model.ApplicationProperties; import stirling.software.SPDF.model.exception.UnsupportedProviderException; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class DatabaseConfigTest { - @Mock - private ApplicationProperties applicationProperties; + @Mock private ApplicationProperties applicationProperties; private DatabaseConfig databaseConfig; diff --git a/src/test/java/stirling/software/SPDF/controller/api/RearrangePagesPDFControllerTest.java b/src/test/java/stirling/software/SPDF/controller/api/RearrangePagesPDFControllerTest.java index 2270d68f0..d6085b6f2 100644 --- a/src/test/java/stirling/software/SPDF/controller/api/RearrangePagesPDFControllerTest.java +++ b/src/test/java/stirling/software/SPDF/controller/api/RearrangePagesPDFControllerTest.java @@ -1,25 +1,19 @@ package stirling.software.SPDF.controller.api; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; - -import java.util.Arrays; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import stirling.software.SPDF.service.CustomPDFDocumentFactory; - -import java.util.Arrays; -import java.util.List; - 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.SPDF.service.CustomPDFDocumentFactory; class RearrangePagesPDFControllerTest { @@ -33,9 +27,7 @@ class RearrangePagesPDFControllerTest { sut = new RearrangePagesPDFController(mockPdfDocumentFactory); } - /** - * Tests the behavior of the oddEvenMerge method when there are no pages in the document. - */ + /** Tests the behavior of the oddEvenMerge method when there are no pages in the document. */ @Test void oddEvenMerge_noPages() { int totalNumberOfPages = 0; @@ -60,7 +52,8 @@ class RearrangePagesPDFControllerTest { } /** - * Tests the behavior of the oddEvenMerge method when there are even total pages in the document. + * Tests the behavior of the oddEvenMerge method when there are even total pages in the + * document. */ @Test void oddEvenMerge_evenTotalPageNumber() { @@ -76,7 +69,7 @@ class RearrangePagesPDFControllerTest { * 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. + * @param expectedPageOrder The expected order of the pages after rearranging. */ @ParameterizedTest @CsvSource({ diff --git a/src/test/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPdfTest.java b/src/test/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPdfTest.java index 372751e8e..952d765fc 100644 --- a/src/test/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPdfTest.java +++ b/src/test/java/stirling/software/SPDF/controller/api/converters/ConvertWebsiteToPdfTest.java @@ -1,5 +1,8 @@ package stirling.software.SPDF.controller.api.converters; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -9,9 +12,6 @@ import stirling.software.SPDF.config.RuntimePathConfig; import stirling.software.SPDF.model.api.converters.UrlToPdfRequest; import stirling.software.SPDF.service.CustomPDFDocumentFactory; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class ConvertWebsiteToPdfTest { @Mock private CustomPDFDocumentFactory mockPdfDocumentFactory; diff --git a/src/test/java/stirling/software/SPDF/utils/FileInfoTest.java b/src/test/java/stirling/software/SPDF/utils/FileInfoTest.java index e83a062f8..6192d1dea 100644 --- a/src/test/java/stirling/software/SPDF/utils/FileInfoTest.java +++ b/src/test/java/stirling/software/SPDF/utils/FileInfoTest.java @@ -1,31 +1,32 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalDateTime; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; public class FileInfoTest { @ParameterizedTest(name = "{index}: fileSize={0}") @CsvSource({ - "0, '0 Bytes'", - "1023, '1023 Bytes'", - "1024, '1.00 KB'", - "1048575, '1024.00 KB'", // Do we really want this as result? - "1048576, '1.00 MB'", - "1073741823, '1024.00 MB'", // Do we really want this as result? - "1073741824, '1.00 GB'" + "0, '0 Bytes'", + "1023, '1023 Bytes'", + "1024, '1.00 KB'", + "1048575, '1024.00 KB'", // Do we really want this as result? + "1048576, '1.00 MB'", + "1073741823, '1024.00 MB'", // Do we really want this as result? + "1073741824, '1.00 GB'" }) void testGetFormattedFileSize(long fileSize, String expectedFormattedSize) { - FileInfo fileInfo = new FileInfo( - "example.txt", - "/path/to/example.txt", - LocalDateTime.now(), - fileSize, - LocalDateTime.now().minusDays(1)); + FileInfo fileInfo = + new FileInfo( + "example.txt", + "/path/to/example.txt", + LocalDateTime.now(), + fileSize, + LocalDateTime.now().minusDays(1)); assertEquals(expectedFormattedSize, fileInfo.getFormattedFileSize()); } diff --git a/src/test/java/stirling/software/SPDF/utils/FileToPdfTest.java b/src/test/java/stirling/software/SPDF/utils/FileToPdfTest.java index 8edb1b871..38e2ec3b8 100644 --- a/src/test/java/stirling/software/SPDF/utils/FileToPdfTest.java +++ b/src/test/java/stirling/software/SPDF/utils/FileToPdfTest.java @@ -1,17 +1,20 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.Test; -import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +import stirling.software.SPDF.model.api.converters.HTMLToPdfRequest; public class FileToPdfTest { /** - * Test the HTML to PDF conversion. - * This test expects an IOException when an empty HTML input is provided. + * Test the HTML to PDF conversion. This test expects an IOException when an empty HTML input is + * provided. */ @Test public void testConvertHtmlToPdf() { @@ -31,8 +34,8 @@ public class FileToPdfTest { } /** - * Test sanitizeZipFilename with null or empty input. - * It should return an empty string in these cases. + * Test sanitizeZipFilename with null or empty input. It should return an empty string in these + * cases. */ @Test public void testSanitizeZipFilename_NullOrEmpty() { @@ -41,8 +44,8 @@ public class FileToPdfTest { } /** - * Test sanitizeZipFilename to ensure it removes path traversal sequences. - * This includes removing both forward and backward slash sequences. + * Test sanitizeZipFilename to ensure it removes path traversal sequences. This includes + * removing both forward and backward slash sequences. */ @Test public void testSanitizeZipFilename_RemovesTraversalSequences() { @@ -58,9 +61,7 @@ public class FileToPdfTest { assertEquals(expected, FileToPdf.sanitizeZipFilename(input)); } - /** - * Test sanitizeZipFilename to ensure that it removes leading drive letters and slashes. - */ + /** Test sanitizeZipFilename to ensure that it removes leading drive letters and slashes. */ @Test public void testSanitizeZipFilename_RemovesLeadingDriveAndSlashes() { String input = "C:\\folder\\file.txt"; @@ -72,9 +73,7 @@ public class FileToPdfTest { assertEquals(expected, FileToPdf.sanitizeZipFilename(input)); } - /** - * Test sanitizeZipFilename to verify that safe filenames remain unchanged. - */ + /** Test sanitizeZipFilename to verify that safe filenames remain unchanged. */ @Test public void testSanitizeZipFilename_NoChangeForSafeNames() { String input = "folder/subfolder/file.txt"; diff --git a/src/test/java/stirling/software/SPDF/utils/GeneralUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/GeneralUtilsTest.java index 18afcad62..72389130d 100644 --- a/src/test/java/stirling/software/SPDF/utils/GeneralUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/GeneralUtilsTest.java @@ -1,161 +1,157 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.Test; - -import java.util.List; - import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; + +import org.junit.jupiter.api.Test; public class GeneralUtilsTest { - @Test void testParsePageListWithAll() { - List result = GeneralUtils.parsePageList(new String[]{"all"}, 5, false); + List result = GeneralUtils.parsePageList(new String[] {"all"}, 5, false); assertEquals(List.of(0, 1, 2, 3, 4), result, "'All' keyword should return all pages."); } @Test void testParsePageListWithAllOneBased() { - List result = GeneralUtils.parsePageList(new String[]{"all"}, 5, true); + List result = GeneralUtils.parsePageList(new String[] {"all"}, 5, true); assertEquals(List.of(1, 2, 3, 4, 5), result, "'All' keyword should return all pages."); } @Test void nFunc() { - List result = GeneralUtils.parsePageList(new String[]{"n"}, 5, true); + List result = GeneralUtils.parsePageList(new String[] {"n"}, 5, true); assertEquals(List.of(1, 2, 3, 4, 5), result, "'n' keyword should return all pages."); } @Test void nFuncAdvanced() { - List result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, true); - //skip 0 as not valid + List result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, true); + // skip 0 as not valid assertEquals(List.of(4, 8), result, "'All' keyword should return all pages."); } @Test void nFuncAdvancedZero() { - List result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, false); - //skip 0 as not valid + List result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false); + // skip 0 as not valid assertEquals(List.of(3, 7), result, "'All' keyword should return all pages."); } @Test void nFuncAdvanced2() { - List result = GeneralUtils.parsePageList(new String[]{"4n-1"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, true); // skip -1 as not valid assertEquals(List.of(3, 7), result, "4n-1 should do (0-1), (4-1), (8-1)"); } @Test void nFuncAdvanced3() { - List result = GeneralUtils.parsePageList(new String[]{"4n+1"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"4n+1"}, 9, true); assertEquals(List.of(5, 9), result, "'All' keyword should return all pages."); } @Test void nFunc_spaces() { - List result = GeneralUtils.parsePageList(new String[]{"n + 1"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"n + 1"}, 9, true); assertEquals(List.of(2, 3, 4, 5, 6, 7, 8, 9), result); } @Test void nFunc_consecutive_Ns_nnn() { - List result = GeneralUtils.parsePageList(new String[]{"nnn"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"nnn"}, 9, true); assertEquals(List.of(1, 8), result); } @Test void nFunc_consecutive_Ns_nn() { - List result = GeneralUtils.parsePageList(new String[]{"nn"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"nn"}, 9, true); assertEquals(List.of(1, 4, 9), result); } @Test void nFunc_opening_closing_round_brackets() { - List result = GeneralUtils.parsePageList(new String[]{"(n-1)(n-2)"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"(n-1)(n-2)"}, 9, true); assertEquals(List.of(2, 6), result); } @Test void nFunc_opening_round_brackets() { - List result = GeneralUtils.parsePageList(new String[]{"2(n-1)"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"2(n-1)"}, 9, true); assertEquals(List.of(2, 4, 6, 8), result); } @Test void nFunc_opening_round_brackets_n() { - List result = GeneralUtils.parsePageList(new String[]{"n(n-1)"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"n(n-1)"}, 9, true); assertEquals(List.of(2, 6), result); } @Test void nFunc_closing_round_brackets() { - List result = GeneralUtils.parsePageList(new String[]{"(n-1)2"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"(n-1)2"}, 9, true); assertEquals(List.of(2, 4, 6, 8), result); } @Test void nFunc_closing_round_brackets_n() { - List result = GeneralUtils.parsePageList(new String[]{"(n-1)n"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"(n-1)n"}, 9, true); assertEquals(List.of(2, 6), result); } @Test void nFunc_function_surrounded_with_brackets() { - List result = GeneralUtils.parsePageList(new String[]{"(n-1)"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"(n-1)"}, 9, true); assertEquals(List.of(1, 2, 3, 4, 5, 6, 7, 8), result); } - @Test void nFuncAdvanced4() { - List result = GeneralUtils.parsePageList(new String[]{"3+2n"}, 9, true); + List result = GeneralUtils.parsePageList(new String[] {"3+2n"}, 9, true); assertEquals(List.of(5, 7, 9), result, "'All' keyword should return all pages."); } @Test void nFuncAdvancedZerobased() { - List result = GeneralUtils.parsePageList(new String[]{"4n"}, 9, false); + List result = GeneralUtils.parsePageList(new String[] {"4n"}, 9, false); assertEquals(List.of(3, 7), result, "'All' keyword should return all pages."); } @Test void nFuncAdvanced2Zerobased() { - List result = GeneralUtils.parsePageList(new String[]{"4n-1"}, 9, false); + List result = GeneralUtils.parsePageList(new String[] {"4n-1"}, 9, false); assertEquals(List.of(2, 6), result, "'All' keyword should return all pages."); } @Test void testParsePageListWithRangeOneBasedOutput() { - List result = GeneralUtils.parsePageList(new String[]{"1-3"}, 5, true); + List result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, true); assertEquals(List.of(1, 2, 3), result, "Range should be parsed correctly."); } @Test void testParsePageListWithRangeZeroBaseOutput() { - List result = GeneralUtils.parsePageList(new String[]{"1-3"}, 5, false); + List result = GeneralUtils.parsePageList(new String[] {"1-3"}, 5, false); assertEquals(List.of(0, 1, 2), result, "Range should be parsed correctly."); } - @Test void testParsePageListWithRangeOneBasedOutputFull() { - List result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 8, true); + List result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, true); assertEquals(List.of(1, 3, 7, 8), result, "Range should be parsed correctly."); } @Test void testParsePageListWithRangeOneBasedOutputFullOutOfRange() { - List result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 5, true); + List result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 5, true); assertEquals(List.of(1, 3), result, "Range should be parsed correctly."); } @Test void testParsePageListWithRangeZeroBaseOutputFull() { - List result = GeneralUtils.parsePageList(new String[]{"1,3,7-8"}, 8, false); + List result = GeneralUtils.parsePageList(new String[] {"1,3,7-8"}, 8, false); assertEquals(List.of(0, 2, 6, 7), result, "Range should be parsed correctly."); } } diff --git a/src/test/java/stirling/software/SPDF/utils/ImageProcessingUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/ImageProcessingUtilsTest.java index af4bc22fb..dc4a94d7b 100644 --- a/src/test/java/stirling/software/SPDF/utils/ImageProcessingUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/ImageProcessingUtilsTest.java @@ -1,11 +1,13 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.*; import java.awt.image.BufferedImage; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ImageProcessingUtilsTest { @@ -14,7 +16,8 @@ public class ImageProcessingUtilsTest { BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); fillImageWithColor(sourceImage, Color.RED); - BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "greyscale"); + BufferedImage convertedImage = + ImageProcessingUtils.convertColorType(sourceImage, "greyscale"); assertNotNull(convertedImage); assertEquals(BufferedImage.TYPE_BYTE_GRAY, convertedImage.getType()); @@ -32,7 +35,8 @@ public class ImageProcessingUtilsTest { BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); fillImageWithColor(sourceImage, Color.RED); - BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "blackwhite"); + BufferedImage convertedImage = + ImageProcessingUtils.convertColorType(sourceImage, "blackwhite"); assertNotNull(convertedImage); assertEquals(BufferedImage.TYPE_BYTE_BINARY, convertedImage.getType()); @@ -49,7 +53,8 @@ public class ImageProcessingUtilsTest { BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); fillImageWithColor(sourceImage, Color.RED); - BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "fullcolor"); + BufferedImage convertedImage = + ImageProcessingUtils.convertColorType(sourceImage, "fullcolor"); assertNotNull(convertedImage); assertEquals(sourceImage, convertedImage); @@ -60,7 +65,8 @@ public class ImageProcessingUtilsTest { BufferedImage sourceImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); fillImageWithColor(sourceImage, Color.RED); - BufferedImage convertedImage = ImageProcessingUtils.convertColorType(sourceImage, "invalidtype"); + BufferedImage convertedImage = + ImageProcessingUtils.convertColorType(sourceImage, "invalidtype"); assertNotNull(convertedImage); assertEquals(sourceImage, convertedImage); diff --git a/src/test/java/stirling/software/SPDF/utils/PdfUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/PdfUtilsTest.java index e57e92035..a03564ee9 100644 --- a/src/test/java/stirling/software/SPDF/utils/PdfUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/PdfUtilsTest.java @@ -1,5 +1,15 @@ package stirling.software.SPDF.utils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; @@ -8,13 +18,6 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - public class PdfUtilsTest { @Test @@ -46,6 +49,4 @@ public class PdfUtilsTest { assertTrue(PdfUtils.hasImagesOnPage(page)); } - - } diff --git a/src/test/java/stirling/software/SPDF/utils/ProcessExecutorTest.java b/src/test/java/stirling/software/SPDF/utils/ProcessExecutorTest.java index 10910b125..871a1678c 100644 --- a/src/test/java/stirling/software/SPDF/utils/ProcessExecutorTest.java +++ b/src/test/java/stirling/software/SPDF/utils/ProcessExecutorTest.java @@ -1,13 +1,16 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ProcessExecutorTest { @@ -27,7 +30,8 @@ public class ProcessExecutorTest { command.add("-version"); // Execute the command - ProcessExecutor.ProcessExecutorResult result = processExecutor.runCommandWithOutputHandling(command); + ProcessExecutor.ProcessExecutorResult result = + processExecutor.runCommandWithOutputHandling(command); // Check the exit code and output messages assertEquals(0, result.getRc()); @@ -41,15 +45,21 @@ public class ProcessExecutorTest { command.add("nonexistent-command"); // Execute the command and expect an IOException - IOException thrown = assertThrows(IOException.class, () -> { - processExecutor.runCommandWithOutputHandling(command); - }); + IOException thrown = + assertThrows( + IOException.class, + () -> { + processExecutor.runCommandWithOutputHandling(command); + }); // Log the actual error message System.out.println("Caught IOException: " + thrown.getMessage()); // Check the exception message to ensure it indicates the command was not found String errorMessage = thrown.getMessage(); - assertTrue(errorMessage.contains("error=2") || errorMessage.contains("No such file or directory"), "Unexpected error message: " + errorMessage); + assertTrue( + errorMessage.contains("error=2") + || errorMessage.contains("No such file or directory"), + "Unexpected error message: " + errorMessage); } } diff --git a/src/test/java/stirling/software/SPDF/utils/PropertyConfigsTest.java b/src/test/java/stirling/software/SPDF/utils/PropertyConfigsTest.java index 7909f1d9f..be0605735 100644 --- a/src/test/java/stirling/software/SPDF/utils/PropertyConfigsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/PropertyConfigsTest.java @@ -1,11 +1,11 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class PropertyConfigsTest { diff --git a/src/test/java/stirling/software/SPDF/utils/RequestUriUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/RequestUriUtilsTest.java index 7b586f472..f18196030 100644 --- a/src/test/java/stirling/software/SPDF/utils/RequestUriUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/RequestUriUtilsTest.java @@ -1,10 +1,10 @@ package stirling.software.SPDF.utils; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + public class RequestUriUtilsTest { @Test diff --git a/src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java index c17c0e747..c6383accb 100644 --- a/src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java @@ -1,10 +1,11 @@ package stirling.software.SPDF.utils; -import jakarta.servlet.http.HttpServletRequest; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.assertEquals; +import jakarta.servlet.http.HttpServletRequest; public class UrlUtilsTest { diff --git a/src/test/java/stirling/software/SPDF/utils/WebResponseUtilsTest.java b/src/test/java/stirling/software/SPDF/utils/WebResponseUtilsTest.java index 49ecab328..9175e7a1b 100644 --- a/src/test/java/stirling/software/SPDF/utils/WebResponseUtilsTest.java +++ b/src/test/java/stirling/software/SPDF/utils/WebResponseUtilsTest.java @@ -1,5 +1,12 @@ package stirling.software.SPDF.utils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; @@ -8,11 +15,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.mock.web.MockMultipartFile; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.*; - public class WebResponseUtilsTest { @Test @@ -22,7 +24,8 @@ public class WebResponseUtilsTest { baos.write("Sample PDF content".getBytes()); String docName = "sample.pdf"; - ResponseEntity responseEntity = WebResponseUtils.boasToWebResponse(baos, docName); + ResponseEntity responseEntity = + WebResponseUtils.boasToWebResponse(baos, docName); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -32,7 +35,8 @@ public class WebResponseUtilsTest { assertNotNull(headers); assertEquals(MediaType.APPLICATION_PDF, headers.getContentType()); assertNotNull(headers.getContentDisposition()); - //assertEquals("attachment; filename=\"sample.pdf\"", headers.getContentDisposition().toString()); + // assertEquals("attachment; filename=\"sample.pdf\"", + // headers.getContentDisposition().toString()); } catch (IOException e) { fail("Exception thrown: " + e.getMessage()); @@ -43,9 +47,11 @@ public class WebResponseUtilsTest { public void testMultiPartFileToWebResponse() { try { byte[] fileContent = "Sample file content".getBytes(); - MockMultipartFile file = new MockMultipartFile("file", "sample.txt", "text/plain", fileContent); + MockMultipartFile file = + new MockMultipartFile("file", "sample.txt", "text/plain", fileContent); - ResponseEntity responseEntity = WebResponseUtils.multiPartFileToWebResponse(file); + ResponseEntity responseEntity = + WebResponseUtils.multiPartFileToWebResponse(file); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -68,7 +74,8 @@ public class WebResponseUtilsTest { String docName = "sample.txt"; MediaType mediaType = MediaType.TEXT_PLAIN; - ResponseEntity responseEntity = WebResponseUtils.bytesToWebResponse(bytes, docName, mediaType); + ResponseEntity responseEntity = + WebResponseUtils.bytesToWebResponse(bytes, docName, mediaType); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -79,7 +86,6 @@ public class WebResponseUtilsTest { assertEquals(MediaType.TEXT_PLAIN, headers.getContentType()); assertNotNull(headers.getContentDisposition()); - } catch (IOException e) { fail("Exception thrown: " + e.getMessage()); } @@ -92,7 +98,8 @@ public class WebResponseUtilsTest { document.addPage(new org.apache.pdfbox.pdmodel.PDPage()); String docName = "sample.pdf"; - ResponseEntity responseEntity = WebResponseUtils.pdfDocToWebResponse(document, docName); + ResponseEntity responseEntity = + WebResponseUtils.pdfDocToWebResponse(document, docName); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -103,7 +110,6 @@ public class WebResponseUtilsTest { assertEquals(MediaType.APPLICATION_PDF, headers.getContentType()); assertNotNull(headers.getContentDisposition()); - } catch (IOException e) { fail("Exception thrown: " + e.getMessage()); } diff --git a/src/test/java/stirling/software/SPDF/utils/validation/ValidatorTest.java b/src/test/java/stirling/software/SPDF/utils/validation/ValidatorTest.java index 1e2b075ac..1ec8acd91 100644 --- a/src/test/java/stirling/software/SPDF/utils/validation/ValidatorTest.java +++ b/src/test/java/stirling/software/SPDF/utils/validation/ValidatorTest.java @@ -1,24 +1,25 @@ package stirling.software.SPDF.utils.validation; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.stream.Stream; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.junit.jupiter.MockitoExtension; + import stirling.software.SPDF.model.UsernameAttribute; import stirling.software.SPDF.model.provider.GitHubProvider; import stirling.software.SPDF.model.provider.GoogleProvider; -import stirling.software.SPDF.model.provider.KeycloakProvider; import stirling.software.SPDF.model.provider.Provider; -import java.util.List; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - @ExtendWith(MockitoExtension.class) class ValidatorTest { @@ -41,14 +42,10 @@ class ValidatorTest { public static Stream providerParams() { Provider generic = null; - var google = new GoogleProvider(null, "clientSecret", List.of("scope"), UsernameAttribute.EMAIL); + var google = + new GoogleProvider(null, "clientSecret", List.of("scope"), UsernameAttribute.EMAIL); var github = new GitHubProvider("clientId", "", List.of("scope"), UsernameAttribute.LOGIN); - return Stream.of( - Arguments.of(generic), - Arguments.of(google), - Arguments.of(github) - ); + return Stream.of(Arguments.of(generic), Arguments.of(google), Arguments.of(github)); } - }