mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
Upgrade to Junit5 (#1050)
* chore: Update to junit5 for servlet package * chore: Update to junit5 for contrib package * chore: Update to junit5 for common-image package * chore: Update to junit5 for common-lang package * chore: Update to junit5 for entire project files * fix: test case for JPEGImageReaderTest failed for java 8 and 11 assertEquals was using old signature of junit4. * Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update common/common-io/src/test/java/com/twelvemonkeys/io/InputStreamAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-bmp/src/test/java/com/twelvemonkeys/imageio/plugins/bmp/BMPImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageMetadataTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReaderTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageWriterTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/stream/BufferedChannelImageInputStreamTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * refactor: few indentation changes and missed test case - review change related to missing test annotation - unwanted new lines inside test case - duplicate assertions * refactor: moved the lambda expression to method reference * review: testNotNullWithParameterNull catch block was never executed. Added the suggested change * Apply suggestions from code review chore: adjust suggested indentation Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * Update imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageWriterAbstractTest.java Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com> * refactor: using assertTimeout doesnot kill the execution, even if the timeout happens. It is better to use assertTimeoutPreemptively in cases, where we really want to kill the execution after timeout. https://stackoverflow.com/questions/57116801/how-to-fail-a-test-after-a-timeout-is-exceeded-in-junit-5/57116959#57116959 --------- Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a67fdd4b80
commit
543acce8a3
+2
-3
@@ -38,8 +38,7 @@ import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* AbstractThumbnailReaderTest
|
||||
*
|
||||
@@ -57,7 +56,7 @@ public abstract class AbstractThumbnailReaderTest {
|
||||
protected final ImageInputStream createStream(final String name) throws IOException {
|
||||
URL resource = getClass().getResource(name);
|
||||
ImageInputStream stream = ImageIO.createImageInputStream(resource);
|
||||
assertNotNull("Could not create stream for resource " + resource, stream);
|
||||
assertNotNull(stream, "Could not create stream for resource " + resource);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
+25
-27
@@ -41,9 +41,6 @@ import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFEntry;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFReader;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
@@ -56,8 +53,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* EXIFThumbnailReaderTest
|
||||
*
|
||||
@@ -69,7 +67,7 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
|
||||
private final ImageReader thumbnailReader = ImageIO.getImageReadersByFormatName("jpeg").next();
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
thumbnailReader.dispose();
|
||||
}
|
||||
@@ -94,48 +92,48 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
assertNull(EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList())), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromMissingThumbnail() throws IOException {
|
||||
EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(Collections.<Entry>emptyList())), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(Collections.<Entry>emptyList())), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromUnsupportedThumbnailCompression() throws IOException {
|
||||
List<TIFFEntry> entries = Collections.singletonList(new TIFFEntry(TIFF.TAG_COMPRESSION, 42));
|
||||
EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromMissingOffsetUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_WIDTH, 16),
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 9)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromMissingWidthUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
new TIFFEntry(TIFF.TAG_STRIP_OFFSETS, 0),
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 9)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromMissingHeightUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
new TIFFEntry(TIFF.TAG_STRIP_OFFSETS, 0),
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_WIDTH, 16)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromUnsupportedPhotometricUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
@@ -144,10 +142,10 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 9),
|
||||
new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, 42)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromUnsupportedBitsPerSampleUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
@@ -156,10 +154,10 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 9),
|
||||
new TIFFEntry(TIFF.TAG_BITS_PER_SAMPLE, new int[]{5, 6, 5})
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9 * 3]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromUnsupportedSamplesPerPixelUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
@@ -168,10 +166,10 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 90),
|
||||
new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, 1)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[6 + 16 * 9]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncatedUncompressed() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 1),
|
||||
@@ -179,7 +177,7 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_WIDTH, 160),
|
||||
new TIFFEntry(TIFF.TAG_IMAGE_HEIGHT, 90)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,19 +198,19 @@ public class EXIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
assertNotNull(reader.read());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromMissingOffsetJPEG() throws IOException {
|
||||
List<TIFFEntry> entries = Collections.singletonList(new TIFFEntry(TIFF.TAG_COMPRESSION, 6));
|
||||
EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncatedJPEG() throws IOException {
|
||||
List<TIFFEntry> entries = Arrays.asList(
|
||||
new TIFFEntry(TIFF.TAG_COMPRESSION, 6),
|
||||
new TIFFEntry(TIFF.TAG_JPEG_INTERCHANGE_FORMAT, 0)
|
||||
);
|
||||
EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> EXIFThumbnail.from(new EXIF(new byte[42]), new EXIFDirectory(new IFD(Collections.<Entry>emptyList()), new IFD(entries)), thumbnailReader));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-14
@@ -30,16 +30,14 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.jpeg;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* FastCMYKToRGBTest
|
||||
*
|
||||
@@ -63,7 +61,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(3, pixel.length);
|
||||
byte[] expected = {(byte) 255, (byte) 255, (byte) 255};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +75,7 @@ public class FastCMYKToRGBTest {
|
||||
assertEquals(1, pixel.length);
|
||||
int expected = 0xFFFFFF;
|
||||
int rgb = pixel[0] & 0xFFFFFF;
|
||||
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
|
||||
assertEquals(expected, rgb, String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +93,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(3, pixel.length);
|
||||
byte[] expected = {(byte) 0, (byte) 0, (byte) 0};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals( expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ public class FastCMYKToRGBTest {
|
||||
assertEquals(1, pixel.length);
|
||||
int expected = 0x0;
|
||||
int rgb = pixel[0] & 0xFFFFFF;
|
||||
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
|
||||
assertEquals(expected, rgb, String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +132,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(3, pixel.length);
|
||||
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i)};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +151,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(3, pixel.length);
|
||||
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i)};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +170,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(4, pixel.length);
|
||||
byte[] expected = {(byte) (255 - i), (byte) i, (byte) (127 - i), (byte) 0xff};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +190,7 @@ public class FastCMYKToRGBTest {
|
||||
assertEquals(1, pixel.length);
|
||||
int expected = (((byte) (255 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (127 - i)) & 0xFF;
|
||||
int rgb = pixel[0] & 0xFFFFFF;
|
||||
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
|
||||
assertEquals(expected, rgb, String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +210,7 @@ public class FastCMYKToRGBTest {
|
||||
assertEquals(1, pixel.length);
|
||||
int expected = (((byte) (127 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (255 - i)) & 0xFF;
|
||||
int rgb = pixel[0] & 0xFFFFFF;
|
||||
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected), expected, rgb);
|
||||
assertEquals( expected, rgb, String.format("Was: 0x%08x, expected: 0x%08x", rgb, expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +229,7 @@ public class FastCMYKToRGBTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(1, pixel.length);
|
||||
int expected = 0xFF << 24 | (((byte) (255 - i)) & 0xFF) << 16 | (((byte) i) & 0xFF) << 8 | ((byte) (127 - i)) & 0xFF;
|
||||
assertEquals(String.format("Was: 0x%08x, expected: 0x%08x", pixel[0], expected), expected, pixel[0]);
|
||||
assertEquals(expected, pixel[0], String.format("Was: 0x%08x, expected: 0x%08x", pixel[0], expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -34,8 +34,6 @@ import com.twelvemonkeys.imageio.metadata.jpeg.JPEG;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegment;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegmentUtil;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -43,7 +41,8 @@ import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JFIFThumbnailReaderTest
|
||||
@@ -82,9 +81,9 @@ public class JFIFThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
assertNull(JFIFThumbnail.from(new JFIF(1, 1, 0, 1, 1, 0, 0, new byte[0])));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncated() throws IOException {
|
||||
JFIFThumbnail.from(new JFIF(1, 1, 0, 1, 1, 255, 170, new byte[99]));
|
||||
assertThrows(IIOException.class, () -> JFIFThumbnail.from(new JFIF(1, 1, 0, 1, 1, 255, 170, new byte[99])));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+14
-15
@@ -34,9 +34,6 @@ import com.twelvemonkeys.imageio.metadata.jpeg.JPEG;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegment;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegmentUtil;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
@@ -46,7 +43,9 @@ import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JFXXThumbnailReaderTest
|
||||
@@ -70,7 +69,7 @@ public class JFXXThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
return JFXXThumbnail.from(JFXX.read(new DataInputStream(jfxx.segmentData()), jfxx.length()), thumbnailReader);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
thumbnailReader.dispose();
|
||||
}
|
||||
@@ -80,37 +79,37 @@ public class JFXXThumbnailReaderTest extends AbstractThumbnailReaderTest {
|
||||
assertNull(JFXXThumbnail.from(null, thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromNullThumbnail() throws IOException {
|
||||
JFXXThumbnail.from(new JFXX(JFXX.JPEG, null), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> JFXXThumbnail.from(new JFXX(JFXX.JPEG, null), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromEmpty() throws IOException {
|
||||
JFXXThumbnail.from(new JFXX(JFXX.JPEG, new byte[0]), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> JFXXThumbnail.from(new JFXX(JFXX.JPEG, new byte[0]), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncatedJPEG() throws IOException {
|
||||
JFXXThumbnail.from(new JFXX(JFXX.JPEG, new byte[99]), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> JFXXThumbnail.from(new JFXX(JFXX.JPEG, new byte[99]), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncatedRGB() throws IOException {
|
||||
byte[] thumbnail = new byte[765];
|
||||
thumbnail[0] = (byte) 160;
|
||||
thumbnail[1] = 90;
|
||||
|
||||
JFXXThumbnail.from(new JFXX(JFXX.RGB, thumbnail), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> JFXXThumbnail.from(new JFXX(JFXX.RGB, thumbnail), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testFromTruncatedIndexed() throws IOException {
|
||||
byte[] thumbnail = new byte[365];
|
||||
thumbnail[0] = (byte) 160;
|
||||
thumbnail[1] = 90;
|
||||
|
||||
JFXXThumbnail.from(new JFXX(JFXX.INDEXED, thumbnail), thumbnailReader);
|
||||
assertThrows(IIOException.class, () -> JFXXThumbnail.from(new JFXX(JFXX.INDEXED, thumbnail), thumbnailReader));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.jpeg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
@@ -48,8 +47,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
/**
|
||||
* JPEGImage10MetadataTest.
|
||||
|
||||
+96
-102
@@ -35,7 +35,6 @@ import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -58,17 +57,19 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.io.*;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||
import static java.time.Duration.ofMillis;
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
import static org.mockito.AdditionalMatchers.and;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -189,7 +190,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
|
||||
private static void assertJPEGPixelsEqual(byte[] expected, byte[] actual, @SuppressWarnings("SameParameterValue") int actualOffset) {
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
assertEquals(String.format("Difference in pixel %d", i), expected[i], actual[i + actualOffset], 5);
|
||||
assertEquals(expected[i], actual[i + actualOffset], 5, String.format("Difference in pixel %d", i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +569,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
// TODO: There's a bug in com.sun.imageio.plugins.png.PNGImageReaderSpi.canDecode
|
||||
// causing files < 8 bytes to not be recognized as anything...
|
||||
for (TestData data : getBrokenTestData()) {
|
||||
assertTrue(data.toString(), provider.canDecodeInput(data.getInputStream()));
|
||||
assertTrue(provider.canDecodeInput(data.getInputStream()), data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,30 +601,28 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 200)
|
||||
@Test
|
||||
public void testBrokenGetRawImageTypeIgnoreMetadata() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
assertTimeoutPreemptively(ofMillis(200), () -> {
|
||||
try {
|
||||
for (TestData broken : getBrokenTestData()) {
|
||||
reader.setInput(broken.getInputStream(), true, true);
|
||||
|
||||
try {
|
||||
for (TestData broken : getBrokenTestData()) {
|
||||
reader.setInput(broken.getInputStream(), true, true);
|
||||
|
||||
try {
|
||||
reader.getRawImageType(0);
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
assertNotNull(expected.getMessage());
|
||||
}
|
||||
catch (IOException expected) {
|
||||
if (!(expected instanceof EOFException)) {
|
||||
try {
|
||||
reader.getRawImageType(0);
|
||||
} catch (IIOException expected) {
|
||||
assertNotNull(expected.getMessage());
|
||||
} catch (IOException expected) {
|
||||
if (!(expected instanceof EOFException)) {
|
||||
assertNotNull(expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -652,30 +651,28 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 200)
|
||||
@Test
|
||||
public void testBrokenGetImageTypesIgnoreMetadata() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
assertTimeoutPreemptively(ofMillis(200), () -> {
|
||||
try {
|
||||
for (TestData broken : getBrokenTestData()) {
|
||||
reader.setInput(broken.getInputStream(), true, true);
|
||||
|
||||
try {
|
||||
for (TestData broken : getBrokenTestData()) {
|
||||
reader.setInput(broken.getInputStream(), true, true);
|
||||
|
||||
try {
|
||||
reader.getImageTypes(0);
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
assertNotNull(expected.getMessage());
|
||||
}
|
||||
catch (IOException expected) {
|
||||
if (!(expected instanceof EOFException)) {
|
||||
try {
|
||||
reader.getImageTypes(0);
|
||||
} catch (IIOException expected) {
|
||||
assertNotNull(expected.getMessage());
|
||||
} catch (IOException expected) {
|
||||
if (!(expected instanceof EOFException)) {
|
||||
assertNotNull(expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -786,21 +783,21 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
return (IIOMetadataNode) elements.item(0);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testGetImageMetadataOutOfBounds() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
||||
try {
|
||||
// Any sample should do here
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/gray-sample.jpg")));
|
||||
reader.getImageMetadata(-1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> reader.getImageMetadata(-1));
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testBrokenBogusSegmentLengthReadWithDestination() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
||||
@@ -815,18 +812,14 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setDestination(image);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
reader.read(0, param);
|
||||
});
|
||||
|
||||
try {
|
||||
reader.read(0, param);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Even if we get an exception here, the image should contain 10-15% of the image
|
||||
assertRGBEquals(0xffffffff, image.getRGB(0, 0)); // white area
|
||||
assertRGBEquals(0xff0000ff, image.getRGB(67, 22)); // blue area
|
||||
assertRGBEquals(0xffff00ff, image.getRGB(83, 22)); // purple area
|
||||
|
||||
throw e;
|
||||
}
|
||||
// Even if we get an exception here, the image should contain 10-15% of the image
|
||||
assertRGBEquals(0xffffffff, image.getRGB(0, 0)); // white area
|
||||
assertRGBEquals(0xff0000ff, image.getRGB(67, 22)); // blue area
|
||||
assertRGBEquals(0xffff00ff, image.getRGB(83, 22)); // purple area
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
@@ -1023,7 +1016,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
reader.setInput(data.getInputStream());
|
||||
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
|
||||
|
||||
assertTrue(data + " has no image types", types.hasNext());
|
||||
assertTrue(types.hasNext(), data + " has no image types");
|
||||
|
||||
boolean hasRGBType = false;
|
||||
boolean hasCMYKType = false;
|
||||
@@ -1036,15 +1029,15 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
hasRGBType = true;
|
||||
}
|
||||
else if (csType == ColorSpace.TYPE_CMYK) {
|
||||
assertTrue("CMYK types should be delivered after RGB types (violates \"contract\" of more \"natural\" type first) for " + data, hasRGBType);
|
||||
assertTrue(hasRGBType, "CMYK types should be delivered after RGB types (violates \"contract\" of more \"natural\" type first) for " + data);
|
||||
|
||||
hasCMYKType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("No RGB types for " + data, hasRGBType);
|
||||
assertTrue("No CMYK types for " + data, hasCMYKType);
|
||||
assertTrue(hasRGBType, "No RGB types for " + data);
|
||||
assertTrue(hasCMYKType, "No CMYK types for " + data);
|
||||
}
|
||||
|
||||
reader.dispose();
|
||||
@@ -1064,7 +1057,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
ImageTypeSpecifier rawType = reader.getRawImageType(0);
|
||||
assertNotNull("No raw type for " + data, rawType);
|
||||
assertNotNull(rawType, "No raw type for " + data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1079,7 +1072,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
reader.setInput(data.getInputStream());
|
||||
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
|
||||
|
||||
assertTrue(data + " has no image types", types.hasNext());
|
||||
assertTrue(types.hasNext(), data + " has no image types");
|
||||
|
||||
ImageTypeSpecifier cmykType = null;
|
||||
|
||||
@@ -1093,7 +1086,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull("No CMYK types for " + data, cmykType);
|
||||
assertNotNull(cmykType, "No CMYK types for " + data);
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setDestinationType(cmykType);
|
||||
@@ -1124,7 +1117,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
reader.setInput(data.getInputStream());
|
||||
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
|
||||
|
||||
assertTrue(data + " has no image types", types.hasNext());
|
||||
assertTrue(types.hasNext(), data + " has no image types");
|
||||
|
||||
ImageTypeSpecifier cmykType = null;
|
||||
ImageTypeSpecifier rgbType = null;
|
||||
@@ -1145,8 +1138,8 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull("No RGB types for " + data, rgbType);
|
||||
assertNotNull("No CMYK types for " + data, cmykType);
|
||||
assertNotNull(rgbType, "No RGB types for " + data);
|
||||
assertNotNull(cmykType, "No CMYK types for " + data);
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setSourceRegion(new Rectangle(reader.getWidth(0), 8)); // We don't really need to read it all
|
||||
@@ -1239,13 +1232,13 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
|
||||
while (imageTypes.hasNext()) {
|
||||
ImageTypeSpecifier specifier = imageTypes.next();
|
||||
assertNotEquals("RGB JPEGs can't be decoded as Gray as it has no luminance (Y) component", ColorSpace.TYPE_GRAY, specifier.getColorModel().getColorSpace().getType());
|
||||
assertNotEquals(ColorSpace.TYPE_GRAY, specifier.getColorModel().getColorSpace().getType(), "RGB JPEGs can't be decoded as Gray as it has no luminance (Y) component");
|
||||
}
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
@Test
|
||||
public void testRGBAsGray() throws IOException {
|
||||
final JPEGImageReader reader = createReader();
|
||||
try {
|
||||
@@ -1259,7 +1252,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
param.setDestinationType(ImageTypeSpecifiers.createGrayscale(8, DataBuffer.TYPE_BYTE));
|
||||
|
||||
// Should ideally throw IIOException due to destination type mismatch, but throws IllegalArgumentException...
|
||||
reader.read(0, param);
|
||||
assertThrows(Exception.class, () -> reader.read(0, param));
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
@@ -1434,7 +1427,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
for (int i = 0; i < reader.getNumImages(true); i++) {
|
||||
try {
|
||||
IIOMetadata metadata = reader.getImageMetadata(i);
|
||||
assertNotNull(String.format("Image metadata null for %s image %s", testData, i), metadata);
|
||||
assertNotNull(metadata, String.format("Image metadata null for %s image %s", testData, i));
|
||||
|
||||
Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName());
|
||||
assertNotNull(tree);
|
||||
@@ -1489,7 +1482,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource(resource))) {
|
||||
reader.setInput(stream);
|
||||
IIOMetadata metadata = reader.getImageMetadata(0);
|
||||
assertNotNull(String.format("%s: null metadata", resource), metadata);
|
||||
assertNotNull( metadata, String.format("%s: null metadata", resource));
|
||||
|
||||
Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName());
|
||||
assertNotNull(tree);
|
||||
@@ -1550,11 +1543,11 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
ImageReaderSpi provider = spiClass.newInstance();
|
||||
|
||||
ImageReader reader = provider.createReaderInstance();
|
||||
assumeNotNull(reader);
|
||||
assumeTrue(reader != null, "Reader should not be null");
|
||||
return reader;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
assumeNoException(t);
|
||||
assumeTrue(false, "An exception occurred: " + t.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -1569,11 +1562,11 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
fail("Expected tree is null, actual tree is non-null");
|
||||
}
|
||||
|
||||
assertEquals(String.format("%s: Node names differ", message), expectedTree.getNodeName(), actualTree.getNodeName());
|
||||
assertEquals(expectedTree.getNodeName(), actualTree.getNodeName(), String.format("%s: Node names differ", message));
|
||||
|
||||
NamedNodeMap expectedAttributes = expectedTree.getAttributes();
|
||||
NamedNodeMap actualAttributes = actualTree.getAttributes();
|
||||
assertEquals(String.format("%s: Number of attributes for <%s> differ", message, expectedTree.getNodeName()), expectedAttributes.getLength(), actualAttributes.getLength());
|
||||
assertEquals(expectedAttributes.getLength(), actualAttributes.getLength(), String.format("%s: Number of attributes for <%s> differ", message, expectedTree.getNodeName()));
|
||||
for (int i = 0; i < expectedAttributes.getLength(); i++) {
|
||||
Node item = expectedAttributes.item(i);
|
||||
String nodeValue = item.getNodeValue();
|
||||
@@ -1583,19 +1576,19 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
nodeValue = StringUtil.capitalize(nodeValue);
|
||||
}
|
||||
|
||||
assertEquals(String.format("%s: \"%s\" attribute for <%s> differ", message, item.getNodeName(), expectedTree.getNodeName()), nodeValue, actualAttributes.getNamedItem(item.getNodeName()).getNodeValue());
|
||||
assertEquals(nodeValue, actualAttributes.getNamedItem(item.getNodeName()).getNodeValue());
|
||||
}
|
||||
|
||||
// Test for equal user objects.
|
||||
// - array equals or reflective equality... Most user objects does not have a decent equals method.. :-P
|
||||
if (expectedTree instanceof IIOMetadataNode) {
|
||||
assertTrue(String.format("%s: %s not an IIOMetadataNode", message, expectedTree.getNodeName()), actualTree instanceof IIOMetadataNode);
|
||||
assertTrue(actualTree instanceof IIOMetadataNode, String.format("%s: %s not an IIOMetadataNode", message, expectedTree.getNodeName()));
|
||||
|
||||
Object expectedUserObject = ((IIOMetadataNode) expectedTree).getUserObject();
|
||||
|
||||
if (expectedUserObject != null) {
|
||||
Object actualUserObject = ((IIOMetadataNode) actualTree).getUserObject();
|
||||
assertNotNull(String.format("%s: User object missing for <%s>", message, expectedTree.getNodeName()), actualUserObject);
|
||||
assertNotNull(actualUserObject, String.format("%s: User object missing for <%s>", message, expectedTree.getNodeName()));
|
||||
assertEqualUserObjects(String.format("%s: User objects for <%s MarkerTag\"%s\"> differ", message, expectedTree.getNodeName(), ((IIOMetadataNode) expectedTree).getAttribute("MarkerTag")), expectedUserObject, actualUserObject);
|
||||
}
|
||||
}
|
||||
@@ -1609,7 +1602,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
List<IIOMetadataNode> expectedChildren = sortNodes(expectedTree.getChildNodes());
|
||||
List<IIOMetadataNode> actualChildren = sortNodes(actualTree.getChildNodes());
|
||||
|
||||
assertEquals(String.format("%s: Number of child nodes for %s differ", message, expectedTree.getNodeName()), expectedChildren.size(), actualChildren.size());
|
||||
assertEquals(expectedChildren.size(), actualChildren.size(), String.format("%s: Number of child nodes for %s differ", message, expectedTree.getNodeName()));
|
||||
|
||||
for (int i = 0; i < expectedChildren.size(); i++) {
|
||||
assertTreesEquals(message + "<" + expectedTree.getNodeName() + ">", expectedChildren.get(i), actualChildren.get(i));
|
||||
@@ -1623,26 +1616,26 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
|
||||
if (expectedUserObject instanceof ICC_Profile) {
|
||||
if (actualUserObject instanceof ICC_Profile) {
|
||||
assertArrayEquals(message, ((ICC_Profile) expectedUserObject).getData(), ((ICC_Profile) actualUserObject).getData());
|
||||
assertArrayEquals(((ICC_Profile) expectedUserObject).getData(), ((ICC_Profile) actualUserObject).getData(), message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (expectedUserObject instanceof byte[]) {
|
||||
if (actualUserObject instanceof byte[]) {
|
||||
assertArrayEquals(message, (byte[]) expectedUserObject, (byte[]) actualUserObject);
|
||||
assertArrayEquals((byte[]) expectedUserObject, (byte[]) actualUserObject, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (expectedUserObject instanceof JPEGHuffmanTable) {
|
||||
if (actualUserObject instanceof JPEGHuffmanTable) {
|
||||
assertArrayEquals(message, ((JPEGHuffmanTable) expectedUserObject).getLengths(), ((JPEGHuffmanTable) actualUserObject).getLengths());
|
||||
assertArrayEquals(message, ((JPEGHuffmanTable) expectedUserObject).getValues(), ((JPEGHuffmanTable) actualUserObject).getValues());
|
||||
assertArrayEquals(((JPEGHuffmanTable) expectedUserObject).getLengths(), ((JPEGHuffmanTable) actualUserObject).getLengths(), message);
|
||||
assertArrayEquals(((JPEGHuffmanTable) expectedUserObject).getValues(), ((JPEGHuffmanTable) actualUserObject).getValues(), message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (expectedUserObject instanceof JPEGQTable) {
|
||||
if (actualUserObject instanceof JPEGQTable) {
|
||||
assertArrayEquals(message, ((JPEGQTable) expectedUserObject).getTable(), ((JPEGQTable) actualUserObject).getTable());
|
||||
assertArrayEquals(((JPEGQTable) expectedUserObject).getTable(), ((JPEGQTable) actualUserObject).getTable(), message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2007,35 +2000,36 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 1000L)
|
||||
@Test
|
||||
public void testInfiniteLoopCorrupt() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(1), () -> {
|
||||
try (ImageInputStream iis = ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg"))) {
|
||||
reader.setInput(iis);
|
||||
|
||||
try (ImageInputStream iis = ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg"))) {
|
||||
reader.setInput(iis);
|
||||
|
||||
try {
|
||||
reader.read(0, null);
|
||||
try {
|
||||
reader.read(0, null);
|
||||
} catch (IIOException expected) {
|
||||
assertThat(expected.getMessage(), allOf(containsString("SOF"), containsString("stream")));
|
||||
}
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
assertThat(expected.getMessage(), allOf(containsString("SOF"), containsString("stream")));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 1000L)
|
||||
@Test
|
||||
public void testInfiniteLoopCorruptRaster() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(1), () -> {
|
||||
try (ImageInputStream iis = ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg"))) {
|
||||
reader.setInput(iis);
|
||||
|
||||
try (ImageInputStream iis = ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg"))) {
|
||||
reader.setInput(iis);
|
||||
|
||||
try {
|
||||
reader.readRaster(0, null);
|
||||
try {
|
||||
reader.readRaster(0, null);
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
assertThat(expected.getMessage(), allOf(containsString("SOF"), containsString("stream")));
|
||||
}
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
assertThat(expected.getMessage(), allOf(containsString("SOF"), containsString("stream")));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -35,7 +35,7 @@ import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
@@ -64,8 +64,7 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
+31
-29
@@ -35,7 +35,7 @@ import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegment;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegmentUtil;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -44,12 +44,12 @@ import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JPEGSegmentImageInputStreamTest
|
||||
@@ -68,33 +68,33 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
return getClass().getResource(pName);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new JPEGSegmentImageInputStream(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new JPEGSegmentImageInputStream(null));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testStreamNonJPEG() throws IOException {
|
||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[] {42, 42, 0, 0, 77, 99})));
|
||||
stream.read();
|
||||
assertThrows(IIOException.class, () -> stream.read());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testStreamNonJPEGArray() throws IOException {
|
||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[] {42, 42, 0, 0, 77, 99})));
|
||||
stream.readFully(new byte[1]);
|
||||
assertThrows(IIOException.class, () -> stream.readFully(new byte[1]));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testStreamEmpty() throws IOException {
|
||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[0])));
|
||||
stream.read();
|
||||
assertThrows(IIOException.class, () -> stream.read());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testStreamEmptyArray() throws IOException {
|
||||
ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[0])));
|
||||
stream.readFully(new byte[1]);
|
||||
assertThrows(IIOException.class, () -> stream.readFully(new byte[1]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,27 +230,29 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
}
|
||||
|
||||
|
||||
@Test(timeout = 1000L)
|
||||
@Test
|
||||
public void testInfiniteLoopCorrupt() throws IOException {
|
||||
try (ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg")))) {
|
||||
long length = 0;
|
||||
while (stream.read() != -1) {
|
||||
length++;
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(1), () -> {
|
||||
try (ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg")))) {
|
||||
long length = 0;
|
||||
while (stream.read() != -1) {
|
||||
length++;
|
||||
}
|
||||
|
||||
assertEquals(25504L, length); // Sanity check: same as file size, except..?
|
||||
}
|
||||
|
||||
assertEquals(25504L, length); // Sanity check: same as file size, except..?
|
||||
}
|
||||
try (ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg")))) {
|
||||
long length = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = stream.read(buffer)) != -1) {
|
||||
length += read;
|
||||
}
|
||||
|
||||
try (ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(getClassLoaderResource("/broken-jpeg/110115680-6d6dce80-7d84-11eb-99df-4cb21df3b09f.jpeg")))) {
|
||||
long length = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = stream.read(buffer)) != -1) {
|
||||
length += read;
|
||||
assertEquals(25504L, length); // Sanity check: same as file size, except..?
|
||||
}
|
||||
|
||||
assertEquals(25504L, length); // Sanity check: same as file size, except..?
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -30,14 +30,14 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.jpeg;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class LuminanceToGrayTest {
|
||||
@Test
|
||||
@@ -56,7 +56,7 @@ public class LuminanceToGrayTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(1, pixel.length);
|
||||
byte[] expected = {(byte) i};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class LuminanceToGrayTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(1, pixel.length);
|
||||
byte[] expected = {(byte) i};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class LuminanceToGrayTest {
|
||||
assertNotNull(pixel);
|
||||
assertEquals(2, pixel.length);
|
||||
byte[] expected = {(byte) i, (byte) (255 - i)};
|
||||
assertArrayEquals(String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)), expected, pixel);
|
||||
assertArrayEquals(expected, pixel, String.format("Was: %s, expected: %s", Arrays.toString(pixel), Arrays.toString(expected)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user