This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit bddd90c5f1b61a3ef545bc2269157ab9c9942e98 Author: Gary Gregory <[email protected]> AuthorDate: Tue Jul 4 10:32:35 2023 -0400 Sort members --- .../commons/imaging/bytesource/ByteSource.java | 8 ++--- .../imaging/bytesource/ByteSourceDataTest.java | 36 +++++++++++----------- .../imaging/formats/png/PngImageParserTest.java | 24 +++++++-------- .../imaging/formats/png/PngWriteReadTest.java | 14 ++++----- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java b/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java index 4aeee8c8..6f479541 100644 --- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java +++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java @@ -43,14 +43,14 @@ public class ByteSource { return new ByteSource(new FileOrigin(file), file.getName()); } - public static ByteSource path(final Path file) { - return new ByteSource(new PathOrigin(file), Objects.toString(file.getFileName(), null)); - } - public static ByteSource inputStream(final InputStream is, final String name) { return new InputStreamByteSource(is, name); } + public static ByteSource path(final Path file) { + return new ByteSource(new PathOrigin(file), Objects.toString(file.getFileName(), null)); + } + private final String fileName; private final AbstractOrigin<?, ?> origin; diff --git a/src/test/java/org/apache/commons/imaging/bytesource/ByteSourceDataTest.java b/src/test/java/org/apache/commons/imaging/bytesource/ByteSourceDataTest.java index e6153a76..61cbe5ca 100644 --- a/src/test/java/org/apache/commons/imaging/bytesource/ByteSourceDataTest.java +++ b/src/test/java/org/apache/commons/imaging/bytesource/ByteSourceDataTest.java @@ -53,18 +53,6 @@ public class ByteSourceDataTest extends ByteSourceTest { } } - private class ByteSourcePathFactory implements ByteSourceFactory { - @Override - public ByteSource getByteSource(final byte[] src) throws IOException { - final Path file = createTempFile(src).toPath(); - - // test that all bytes written to file. - assertEquals(src.length, Files.size(file)); - - return ByteSource.path(file); - } - } - private class ByteSourceInputStreamFileFactory implements ByteSourceFactory { @Override public ByteSource getByteSource(final byte[] src) throws IOException { @@ -86,6 +74,18 @@ public class ByteSourceDataTest extends ByteSourceTest { } + private class ByteSourcePathFactory implements ByteSourceFactory { + @Override + public ByteSource getByteSource(final byte[] src) throws IOException { + final Path file = createTempFile(src).toPath(); + + // test that all bytes written to file. + assertEquals(src.length, Files.size(file)); + + return ByteSource.path(file); + } + } + public static Stream<byte[]> data() { return Arrays.asList(getTestByteArrays()).stream(); } @@ -96,12 +96,6 @@ public class ByteSourceDataTest extends ByteSourceTest { writeAndReadBytes(new ByteSourceFileFactory(), testByteArray); } - @ParameterizedTest - @MethodSource("data") - public void testByteSourcePathFactory(final byte[] testByteArray) throws Exception { - writeAndReadBytes(new ByteSourcePathFactory(), testByteArray); - } - @ParameterizedTest @MethodSource("data") public void testByteSourceInputStreamFileFactory(final byte[] testByteArray) throws Exception { @@ -114,6 +108,12 @@ public class ByteSourceDataTest extends ByteSourceTest { writeAndReadBytes(new ByteSourceInputStreamRawFactory(), testByteArray); } + @ParameterizedTest + @MethodSource("data") + public void testByteSourcePathFactory(final byte[] testByteArray) throws Exception { + writeAndReadBytes(new ByteSourcePathFactory(), testByteArray); + } + protected void writeAndReadBytes(final ByteSourceFactory byteSourceFactory, final byte[] src) throws IOException { final ByteSource byteSource = byteSourceFactory.getByteSource(src); diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngImageParserTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngImageParserTest.java index 41e41ec9..018e6bab 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngImageParserTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngImageParserTest.java @@ -31,6 +31,13 @@ import org.junit.jupiter.api.Test; public class PngImageParserTest extends PngBaseTest { + private static byte[] getPngImageBytes(final BufferedImage image, final PngImagingParameters params) throws IOException { + try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { + new PngWriter().writeImage(image, os, params, null); + return os.toByteArray(); + } + } + @Test public void testGetImageSize() { final byte[] bytes = { @@ -45,32 +52,25 @@ public class PngImageParserTest extends PngBaseTest { } @Test - public void testPalette() throws IOException { + public void testNoPalette() throws IOException { final BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); image.setRGB(1, 1, 0x00FFffFF); final PngImagingParameters params = new PngImagingParameters(); - params.setForceIndexedColor(true); final byte[] bytes = getPngImageBytes(image, params); final ImageInfo imageInfo = new PngImageParser().getImageInfo(bytes, null); - assertTrue(imageInfo.usesPalette()); + assertFalse(imageInfo.usesPalette()); } @Test - public void testNoPalette() throws IOException { + public void testPalette() throws IOException { final BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); image.setRGB(1, 1, 0x00FFffFF); final PngImagingParameters params = new PngImagingParameters(); + params.setForceIndexedColor(true); final byte[] bytes = getPngImageBytes(image, params); final ImageInfo imageInfo = new PngImageParser().getImageInfo(bytes, null); - assertFalse(imageInfo.usesPalette()); - } - - private static byte[] getPngImageBytes(final BufferedImage image, final PngImagingParameters params) throws IOException { - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { - new PngWriter().writeImage(image, os, params, null); - return os.toByteArray(); - } + assertTrue(imageInfo.usesPalette()); } } diff --git a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java index 292f4152..0d1c31ac 100644 --- a/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java +++ b/src/test/java/org/apache/commons/imaging/formats/png/PngWriteReadTest.java @@ -102,6 +102,13 @@ public class PngWriteReadTest extends ImagingTest { return result; } + @Test + public void tesMultipletEXt() throws Exception { + final int[][] smallBlackPixels = getSimpleRawData(256, 256, 0); + + writeAndReadMultipleEXt(smallBlackPixels); + } + @Test public void test() throws Exception { final int[][] smallBlackPixels = getSimpleRawData(256, 256, 0); @@ -120,13 +127,6 @@ public class PngWriteReadTest extends ImagingTest { } } - @Test - public void tesMultipletEXt() throws Exception { - final int[][] smallBlackPixels = getSimpleRawData(256, 256, 0); - - writeAndReadMultipleEXt(smallBlackPixels); - } - @Test public void testPhysicalScaleMeters() throws Exception { final PngImageParser pngImageParser = new PngImageParser();
