diff --git a/src/main/java/ch/sbb/polarion/extension/pdf_exporter/rest/model/conversion/ExportParams.java b/src/main/java/ch/sbb/polarion/extension/pdf_exporter/rest/model/conversion/ExportParams.java index 13cb0ba..a7ad8c0 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf_exporter/rest/model/conversion/ExportParams.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf_exporter/rest/model/conversion/ExportParams.java @@ -12,7 +12,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Data @Builder diff --git a/src/main/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProvider.java b/src/main/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProvider.java index 6d3cf9d..321e2bf 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProvider.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProvider.java @@ -109,16 +109,17 @@ boolean isMediaTypeMismatch(String resource, byte[] content) { } @VisibleForTesting + @SuppressWarnings("java:S1075") byte[] getDefaultContent(String resource) throws IOException { - String defaultImagePath; + String pathToDefaultImage; if (WorkItemAttachmentUrlResolver.isSvg(resource)) { - defaultImagePath = "/webapp/ria/images/image_not_accessible_svg.png"; + pathToDefaultImage = "/webapp/ria/images/image_not_accessible_svg.png"; } else if (!StringUtils.isEmpty(MediaUtils.getImageFormat(resource))) { - defaultImagePath = "/webapp/ria/images/image_not_accessible.png"; + pathToDefaultImage = "/webapp/ria/images/image_not_accessible.png"; } else { return new byte[0]; } - File defaultImage = new File(BundleHelper.getPath("com.polarion.alm.ui", defaultImagePath)); + File defaultImage = new File(BundleHelper.getPath("com.polarion.alm.ui", pathToDefaultImage)); return StreamUtils.suckStreamThenClose(new FileInputStream(defaultImage)); } diff --git a/src/test/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProviderTest.java b/src/test/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProviderTest.java index 17e8f97..ba20782 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProviderTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf_exporter/util/PdfExporterFileResourceProviderTest.java @@ -34,9 +34,6 @@ PlatformContextMockExtension.class }) class PdfExporterFileResourceProviderTest { - @Mock - PdfExporterFileResourceProvider resourceProviderMock; - @Mock private IUrlResolver resolverMock; @@ -64,6 +61,7 @@ void replaceImagesAsBase64EncodedTest() { imgBytes = is != null ? is.readAllBytes() : new byte[0]; } + PdfExporterFileResourceProvider resourceProviderMock = mock(PdfExporterFileResourceProvider.class); when(resourceProviderMock.getResourceAsBytes("http://localhost/some-path/img.png", null)).thenReturn(imgBytes); when(resourceProviderMock.getResourceAsBase64String(any(), eq(null))).thenCallRealMethod(); String result = resourceProviderMock.getResourceAsBase64String("http://localhost/some-path/img.png", null); @@ -128,8 +126,8 @@ void getWorkItemIdFromAttachmentUrlValidUrl() { @Test void getWorkItemIdFromAttachmentUrlInvalidUrl() { - String url = "http://example.com/invalid/url"; - String result = resourceProviderMock.getWorkItemIdFromAttachmentUrl(url); + String url = "/http://example.com/invalid/url"; + String result = resourceProvider.getWorkItemIdFromAttachmentUrl(url); assertNull(result); } @@ -144,7 +142,7 @@ void isMediaTypeMismatchMatchingMimeTypes() { mockedMediaUtils.when(() -> MediaUtils.getMimeTypeUsingTikaByResourceName(resource, null)) .thenReturn("image/png"); - boolean result = resourceProviderMock.isMediaTypeMismatch(resource, content); + boolean result = resourceProvider.isMediaTypeMismatch(resource, content); assertFalse(result); } } @@ -157,8 +155,8 @@ void getDefaultContentEmptyForNonImage() { mockedMediaUtils.when(() -> MediaUtils.getImageFormat(resource)) .thenReturn(""); - byte[] content = resourceProviderMock.getDefaultContent(resource); - assertNull(content); + byte[] content = resourceProvider.getDefaultContent(resource); + assertArrayEquals(new byte[0], content); } }