mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-25 00:00:03 -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
+11
-9
@@ -32,16 +32,16 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SVGImageReaderSpiTest.
|
||||
@@ -83,18 +83,20 @@ public class SVGImageReaderSpiTest {
|
||||
public void canDecodeInput() throws Exception {
|
||||
for (String validInput : VALID_INPUTS) {
|
||||
try (ImageInputStream input = ImageIO.createImageInputStream(getClass().getResource(validInput))) {
|
||||
assertTrue("Can't read valid input: " + validInput, provider.canDecodeInput(input));
|
||||
assertTrue(provider.canDecodeInput(input), "Can't read valid input: " + validInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test will time out, if EOFs are not properly detected, see #275
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
public void canDecodeInputInvalid() throws Exception {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse("Claims to read invalid input:" + invalidInput, provider.canDecodeInput(input));
|
||||
assertTimeoutPreemptively(Duration.ofMillis(5000), () -> {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse(provider.canDecodeInput(input), "Claims to read invalid input:" + invalidInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+13
-15
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
@@ -52,10 +49,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -128,18 +124,18 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
int current = image.getRGB(x, y);
|
||||
if (x < quadPoint) {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF0000FF, current);
|
||||
assertEquals( 0xFF0000FF, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFFFF0000, current);
|
||||
assertEquals(0xFFFF0000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF00FF00, current);
|
||||
assertEquals(0xFF00FF00, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF000000, current);
|
||||
assertEquals(0xFF000000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,14 +167,14 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
@@ -316,7 +312,7 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SecurityException.class)
|
||||
@Test
|
||||
public void testDisallowedExternalResources() throws URISyntaxException, IOException {
|
||||
// system-property set to true in surefire-plugin-settings in the pom
|
||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
||||
@@ -333,7 +329,9 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
// `reader.read` for `/svg/barChart.svg` should raise
|
||||
// a SecurityException when External Resources are blocked
|
||||
// because the API invocation gets preference
|
||||
reader.read(0, param);
|
||||
assertThrows(SecurityException.class, () -> {
|
||||
reader.read(0, param);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
|
||||
+4
-5
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.wmf;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
@@ -42,6 +39,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* WMFImageReaderTest
|
||||
*
|
||||
@@ -77,14 +76,14 @@ public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
+19
-17
@@ -33,8 +33,8 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
import com.twelvemonkeys.xml.XMLSerializer;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.mockito.InOrder;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -59,8 +59,8 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -204,11 +204,11 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes", rawFound);
|
||||
assertTrue(rawFound, "ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes");
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Known issue: Subsampled reading is currently broken")
|
||||
@Disabled("Known issue: Subsampled reading is currently broken")
|
||||
@Test
|
||||
public void testReadWithSubsampleParamPixelsIndexed8() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
@@ -235,7 +235,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
// TODO: 1. Subsampling is currently broken, should fix it.
|
||||
// 2. BMPs are (normally) stored bottom/up, meaning y subsampling offsets will differ from normal
|
||||
// subsampling of the same data with an offset... Should we deal with this in the reader? Yes?
|
||||
@Ignore("Known issue: Subsampled reading is currently broken")
|
||||
@Disabled("Known issue: Subsampled reading is currently broken")
|
||||
@Test
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
@@ -260,7 +260,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
assertSubsampledImageDataEquals("Subsampled image data does not match expected", image, subsampled, param);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testReadCorruptCausesIIOException() throws IOException {
|
||||
// See https://bugs.openjdk.java.net/browse/JDK-8066904
|
||||
// NullPointerException when calling ImageIO.read(InputStream) with corrupt BMP
|
||||
@@ -268,7 +268,9 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
|
||||
try {
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/broken-bmp/corrupted-bmp.bmp")));
|
||||
reader.read(0);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
reader.read(0);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
@@ -331,7 +333,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Ignore this test if not on an Oracle JRE (com.sun...BMPImageReader not available)
|
||||
assumeNoException(e);
|
||||
assumeTrue(false, "Skipping test: BMPImageReaderSpi not available on non-Oracle JREs");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -383,7 +385,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
new XMLSerializer(expected, "UTF-8").serialize(expectedTree, false);
|
||||
new XMLSerializer(actual, "UTF-8").serialize(actualTree, false);
|
||||
|
||||
assertEquals(e.getMessage(), new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8));
|
||||
assertEquals(new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8), e.getMessage());
|
||||
|
||||
throw e;
|
||||
}
|
||||
@@ -392,24 +394,24 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
|
||||
private void assertNodeEquals(final String message, final Node expected, final Node actual) {
|
||||
assertEquals(message + " class differs", expected.getClass(), actual.getClass());
|
||||
assertEquals(expected.getClass(), actual.getClass(), message + " class differs");
|
||||
|
||||
if (!excludeEqualValueTest(expected)) {
|
||||
assertEquals(message, expected.getNodeValue(), actual.getNodeValue());
|
||||
assertEquals(expected.getNodeValue(), actual.getNodeValue(), message);
|
||||
|
||||
if (expected instanceof IIOMetadataNode) {
|
||||
IIOMetadataNode expectedIIO = (IIOMetadataNode) expected;
|
||||
IIOMetadataNode actualIIO = (IIOMetadataNode) actual;
|
||||
|
||||
assertEquals(message, expectedIIO.getUserObject(), actualIIO.getUserObject());
|
||||
assertEquals(expectedIIO.getUserObject(), actualIIO.getUserObject(), message);
|
||||
}
|
||||
}
|
||||
|
||||
NodeList expectedChildNodes = expected.getChildNodes();
|
||||
NodeList actualChildNodes = actual.getChildNodes();
|
||||
|
||||
assertTrue(message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes),
|
||||
expectedChildNodes.getLength() <= actualChildNodes.getLength());
|
||||
assertTrue(expectedChildNodes.getLength() <= actualChildNodes.getLength(),
|
||||
message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes));
|
||||
|
||||
for (int i = 0; i < expectedChildNodes.getLength(); i++) {
|
||||
Node expectedChild = expectedChildNodes.item(i);
|
||||
@@ -423,7 +425,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(message + " node name differs", expectedChild.getLocalName(), actualChild.getLocalName());
|
||||
assertEquals(expectedChild.getLocalName(), actualChild.getLocalName(), message + " node name differs");
|
||||
assertNodeEquals(message + "/" + expectedChild.getLocalName(), expectedChild, actualChild);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
@@ -44,7 +41,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CURImageReaderTest
|
||||
@@ -93,16 +92,16 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
||||
if (hotspot != Image.UndefinedProperty || pParam == null) {
|
||||
|
||||
// Typically never happens, because of weirdness with UndefinedProperty
|
||||
assertNotNull("Hotspot for cursor not present", hotspot);
|
||||
assertNotNull(hotspot, "Hotspot for cursor not present");
|
||||
|
||||
// Image weirdness
|
||||
assertNotSame("Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)", Image.UndefinedProperty, hotspot);
|
||||
assertNotSame(Image.UndefinedProperty, hotspot, "Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)");
|
||||
|
||||
assertTrue(String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()), hotspot instanceof Point);
|
||||
assertTrue(hotspot instanceof Point, String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()));
|
||||
assertEquals(pExpected, hotspot);
|
||||
}
|
||||
|
||||
assertNotNull("Hotspot for cursor not present", reader.getHotSpot(0));
|
||||
assertNotNull(reader.getHotSpot(0), "Hotspot for cursor not present");
|
||||
assertEquals(pExpected, reader.getHotSpot(0));
|
||||
}
|
||||
|
||||
@@ -141,14 +140,14 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
||||
// TODO: Test cursor is transparent
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue")
|
||||
@Disabled("Known issue")
|
||||
@Override
|
||||
public void testNotBadCaching() throws IOException {
|
||||
super.testNotBadCaching();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading currently not supported")
|
||||
@Disabled("Known issue: Subsampled reading currently not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
+5
-5
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
@@ -42,6 +39,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ICOImageReaderTest
|
||||
*
|
||||
@@ -98,14 +98,14 @@ public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue")
|
||||
@Disabled("Known issue")
|
||||
@Override
|
||||
public void testNotBadCaching() throws IOException {
|
||||
super.testNotBadCaching();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading currently not supported")
|
||||
@Disabled("Known issue: Subsampled reading currently not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
+5
-6
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RLE4DecoderTest {
|
||||
|
||||
@@ -82,8 +81,8 @@ public class RLE4DecoderTest {
|
||||
int r = channel.read(plain);
|
||||
plain.rewind();
|
||||
|
||||
assertEquals("Difference at line " + i, r, d);
|
||||
assertArrayEquals("Difference at line " + i, plain.array(), decoded.array());
|
||||
assertEquals(r, d, "Difference at line " + i);
|
||||
assertArrayEquals(plain.array(), decoded.array(), "Difference at line " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +103,7 @@ public class RLE4DecoderTest {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int expected = plainSream.read();
|
||||
assertEquals("Differs at " + pos, expected, decoded.read());
|
||||
assertEquals(expected, decoded.read(), "Differs at " + pos);
|
||||
|
||||
if (expected < 0) {
|
||||
break;
|
||||
|
||||
+3
-4
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RLE8DecoderTest {
|
||||
|
||||
@@ -108,7 +107,7 @@ public class RLE8DecoderTest {
|
||||
while (true) {
|
||||
int expected = plainSream.read();
|
||||
|
||||
assertEquals("Differs at " + pos, expected, decoded.read());
|
||||
assertEquals(expected, decoded.read(), "Differs at " + pos);
|
||||
|
||||
if (expected < 0) {
|
||||
break;
|
||||
|
||||
+34
-25
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.geom.Path2D;
|
||||
@@ -39,36 +37,39 @@ import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.readExpectedPath;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdobePathBuilderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullBytes() {
|
||||
new AdobePathBuilder((byte[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder((byte[]) null));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new AdobePathBuilder((DataInput) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder((DataInput) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEmpty() {
|
||||
new AdobePathBuilder(new byte[0]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[0]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateShortPath() {
|
||||
new AdobePathBuilder(new byte[3]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[3]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateImpossiblePath() {
|
||||
new AdobePathBuilder(new byte[7]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[7]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,18 +83,20 @@ public class AdobePathBuilderTest {
|
||||
assertNotNull(path);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPath() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD);
|
||||
buffer.putShort((short) 1);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPathToo() throws IOException {
|
||||
byte[] data = new byte[52];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -102,11 +105,13 @@ public class AdobePathBuilderTest {
|
||||
buffer.position(buffer.position() + 22);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testLongPath() throws IOException {
|
||||
byte[] data = new byte[78];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -117,18 +122,22 @@ public class AdobePathBuilderTest {
|
||||
buffer.position(buffer.position() + 24);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testPathMissingLength() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+32
-24
@@ -31,7 +31,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -39,36 +38,37 @@ import java.awt.geom.Path2D;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.readExpectedPath;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class AdobePathReaderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullBytes() {
|
||||
new AdobePathReader((byte[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader((byte[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new AdobePathReader((DataInput) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader((DataInput) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEmpty() {
|
||||
new AdobePathReader(new byte[0]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[0]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateShortPath() {
|
||||
new AdobePathReader(new byte[3]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[3]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateImpossiblePath() {
|
||||
new AdobePathReader(new byte[7]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[7]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,18 +82,20 @@ public class AdobePathReaderTest {
|
||||
assertNotNull(path);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPath() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD);
|
||||
buffer.putShort((short) 1);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPathToo() throws IOException {
|
||||
byte[] data = new byte[52];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -102,11 +104,13 @@ public class AdobePathReaderTest {
|
||||
buffer.position(buffer.position() + 22);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testLongPath() throws IOException {
|
||||
byte[] data = new byte[78];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -117,18 +121,22 @@ public class AdobePathReaderTest {
|
||||
buffer.position(buffer.position() + 24);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testPathMissingLength() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+54
-55
@@ -30,9 +30,9 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AdobePathSegmentTest.
|
||||
@@ -42,20 +42,19 @@ import static org.junit.Assert.*;
|
||||
* @version $Id: AdobePathSegmentTest.java,v 1.0 13/12/14 harald.kuhr Exp$
|
||||
*/
|
||||
public class AdobePathSegmentTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateBadSelectorNegative() {
|
||||
new AdobePathSegment(-1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateBadSelector() {
|
||||
new AdobePathSegment(9, 2);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(9, 2));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLengthRecordNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, -1);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,9 +71,9 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(-1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLengthRecordNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, -42);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, -42));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,19 +106,19 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 44));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, -16.1, -16.1, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, -16.1, -16.1, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 16.1, 16.1, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 16.1, 16.1, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,20 +135,20 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 44));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, -16.5, 0, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, -16.5, 0, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecorOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 0, -17, 0, 0, 16.5, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 0, -17, 0, 0, 16.5, 1));
|
||||
}
|
||||
|
||||
/// Closed subpath
|
||||
@@ -168,19 +167,19 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 44));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, -16.5, -.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, -16.5, -.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, .5, 16.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, .5, 16.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,59 +196,59 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 44));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, -.5, -16.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, -.5, -16.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 16.5, .5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 16.5, .5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringRule() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.INITIAL_FILL_RULE_RECORD, 0).toString();
|
||||
assertTrue(string, string.startsWith("Rule"));
|
||||
assertTrue(string, string.contains("Initial"));
|
||||
assertTrue(string, string.contains("fill"));
|
||||
assertTrue(string, string.contains("rule=0"));
|
||||
assertTrue(string.startsWith("Rule"), string);
|
||||
assertTrue(string.contains("Initial"), string);
|
||||
assertTrue(string.contains("fill"), string);
|
||||
assertTrue(string.contains("rule=0"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringLength() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, 2).toString();
|
||||
assertTrue(string, string.startsWith("Len"));
|
||||
assertTrue(string, string.contains("Closed"));
|
||||
assertTrue(string, string.contains("subpath"));
|
||||
assertTrue(string, string.contains("length=2"));
|
||||
assertTrue(string.startsWith("Len"), string);
|
||||
assertTrue(string.contains("Closed"), string);
|
||||
assertTrue(string.contains("subpath"), string);
|
||||
assertTrue(string.contains("length=2"), string);
|
||||
|
||||
string = new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, 42).toString();
|
||||
assertTrue(string, string.startsWith("Len"));
|
||||
assertTrue(string, string.contains("Open"));
|
||||
assertTrue(string, string.contains("subpath"));
|
||||
assertTrue(string, string.contains("length=42"));
|
||||
assertTrue(string.startsWith("Len"), string);
|
||||
assertTrue(string.contains("Open"), string);
|
||||
assertTrue(string.contains("subpath"), string);
|
||||
assertTrue(string.contains("length=42"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringOther() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 0, 0, 1, 1, 0, 0).toString();
|
||||
assertTrue(string, string.startsWith("Pt"));
|
||||
assertTrue(string, string.contains("Open"));
|
||||
assertTrue(string, string.contains("Bezier"));
|
||||
assertTrue(string, string.contains("linked"));
|
||||
assertTrue(string.startsWith("Pt"), string);
|
||||
assertTrue(string.contains("Open"), string);
|
||||
assertTrue(string.contains("Bezier"), string);
|
||||
assertTrue(string.contains("linked"), string);
|
||||
|
||||
string = new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 0, 0, 1, 1, 0, 0).toString();
|
||||
assertTrue(string, string.startsWith("Pt"));
|
||||
assertTrue(string, string.contains("Closed"));
|
||||
assertTrue(string, string.contains("Bezier"));
|
||||
assertTrue(string, string.contains("linked"));
|
||||
assertTrue(string.startsWith("Pt"), string);
|
||||
assertTrue(string.contains("Closed"), string);
|
||||
assertTrue(string.contains("Bezier"), string);
|
||||
assertTrue(string.contains("linked"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
-11
@@ -31,7 +31,6 @@
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -41,11 +40,11 @@ import java.awt.geom.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.twelvemonkeys.imageio.path.AdobePathSegment.*;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AdobePathWriterTest.
|
||||
@@ -56,22 +55,22 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class AdobePathWriterTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterNull() {
|
||||
new AdobePathWriter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterInvalid() {
|
||||
new AdobePathWriter(new Path2D.Double(Path2D.WIND_NON_ZERO));
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(new Path2D.Double(Path2D.WIND_NON_ZERO)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterOutOfBounds() {
|
||||
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
|
||||
path.append(new Ellipse2D.Double(.5, 0.5, 2, 2), false);
|
||||
|
||||
new AdobePathWriter(path);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(path));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,14 +92,14 @@ public class AdobePathWriterTest {
|
||||
new AdobePathWriter(path);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNotClosed() {
|
||||
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
path.moveTo(.5, .5);
|
||||
path.lineTo(1, .5);
|
||||
path.curveTo(1, 1, 1, 1, .5, 1);
|
||||
|
||||
new AdobePathWriter(path).writePath();
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(path).writePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+18
-18
@@ -33,7 +33,6 @@ package com.twelvemonkeys.imageio.path;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
@@ -48,8 +47,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PathsTest.
|
||||
@@ -63,9 +63,9 @@ public class PathsTest {
|
||||
IIORegistry.getDefaultInstance().registerServiceProvider(new URLImageInputStreamSpi());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadPathNull() throws IOException {
|
||||
Paths.readPath(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.readPath(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,14 +127,14 @@ public class PathsTest {
|
||||
assertPathEquals(readExpectedPath("/ser/grape-path.ser"), path);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullPath() {
|
||||
Paths.applyClippingPath(null, new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY));
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(null, new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullSource() {
|
||||
Paths.applyClippingPath(new GeneralPath(), null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(new GeneralPath(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,9 +165,9 @@ public class PathsTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullDestination() {
|
||||
Paths.applyClippingPath(new GeneralPath(), new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY), null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(new GeneralPath(), new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,9 +199,9 @@ public class PathsTest {
|
||||
// TODO: Mor sophisticated test that tests all pixels outside path...
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadClippedNull() throws IOException {
|
||||
Paths.readClipped(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.readClipped(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,7 +243,7 @@ public class PathsTest {
|
||||
}
|
||||
|
||||
static void assertPathEquals(final Path2D expectedPath, final Path2D actualPath) {
|
||||
assertNotNull("Expected path is null, check your tests...", expectedPath);
|
||||
assertNotNull(expectedPath, "Expected path is null, check your tests...");
|
||||
assertNotNull(actualPath);
|
||||
|
||||
PathIterator expectedIterator = expectedPath.getPathIterator(null);
|
||||
@@ -253,19 +253,19 @@ public class PathsTest {
|
||||
float[] actualCoords = new float[6];
|
||||
|
||||
while(!expectedIterator.isDone()) {
|
||||
assertFalse("Less points than expected", actualIterator.isDone());
|
||||
assertFalse(actualIterator.isDone(), "Less points than expected");
|
||||
|
||||
int expectedType = expectedIterator.currentSegment(expectedCoords);
|
||||
int actualType = actualIterator.currentSegment(actualCoords);
|
||||
|
||||
assertEquals("Unexpected segment type", expectedType, actualType);
|
||||
assertArrayEquals("Unexpected coordinates", expectedCoords, actualCoords, 0);
|
||||
assertEquals( expectedType, actualType, "Unexpected segment type");
|
||||
assertArrayEquals(expectedCoords, actualCoords, 0, "Unexpected coordinates");
|
||||
|
||||
actualIterator.next();
|
||||
expectedIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("More points than expected", actualIterator.isDone());
|
||||
assertTrue( actualIterator.isDone(), "More points than expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+27
-29
@@ -30,11 +30,9 @@
|
||||
|
||||
package com.twelvemonkeys.imageio;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.awt.*;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -48,7 +46,7 @@ import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ImageReaderBaseTest
|
||||
@@ -64,36 +62,36 @@ public class ImageReaderBaseTest {
|
||||
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB)
|
||||
);
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationZeroWidth() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 0, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 0, 42));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNegativeWidth() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), -1, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), -1, 42));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationZeroHeight() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 42, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 42, 0));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNegativeHeight() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 42, -1);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 42, -1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNullTypes() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, null, 42, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, null, 42, 42));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNoTypes() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, Collections.<ImageTypeSpecifier>emptyList().iterator(), 42, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, Collections.<ImageTypeSpecifier>emptyList().iterator(), 42, 42));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,11 +160,11 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(1, destination.getHeight());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestination() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestination(new BufferedImage(21, 1, BufferedImage.TYPE_USHORT_565_RGB));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,18 +189,18 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(7, destination.getHeight());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestinationType() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestinationTypeAlt() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_BGR));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,22 +213,22 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamDestinationExceedsIntegerMax() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setSourceRegion(new Rectangle(3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE)); // 6 442 057 734 pixels
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6 * Short.MAX_VALUE, 4 * Short.MAX_VALUE); // 25 768 230 936 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6 * Short.MAX_VALUE, 4 * Short.MAX_VALUE)); // 25 768 230 936 pixels
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationDimensionExceedsIntegerMax() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE); // 6 442 057 734 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE)); // 6 442 057 734 pixels
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationStorageExceedsIntegerMax() throws IIOException {
|
||||
Set<ImageTypeSpecifier> byteTypes = singleton(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR));
|
||||
ImageReaderBase.getDestination(null, byteTypes.iterator(), Short.MAX_VALUE, Short.MAX_VALUE); // 1 073 676 289 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(null, byteTypes.iterator(), Short.MAX_VALUE, Short.MAX_VALUE)); // 1 073 676 289 pixels
|
||||
// => 3 221 028 867 bytes needed in continuous array, not possible
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -7,9 +7,9 @@ import com.twelvemonkeys.imageio.StandardImageMetadataSupport.SubimageInterpreta
|
||||
import com.twelvemonkeys.imageio.StandardImageMetadataSupport.TextEntry;
|
||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import java.awt.image.*;
|
||||
@@ -23,22 +23,23 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.twelvemonkeys.imageio.StandardImageMetadataSupport.builder;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class StandardImageMetadataSupportTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNullBuilder() {
|
||||
new StandardImageMetadataSupport(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new StandardImageMetadataSupport(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNullType() {
|
||||
new StandardImageMetadataSupport(builder(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> new StandardImageMetadataSupport(builder(null)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void builderNullType() {
|
||||
builder(null).build();
|
||||
assertThrows(IllegalArgumentException.class, () -> builder(null).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,10 +90,10 @@ public class StandardImageMetadataSupportTest {
|
||||
assertEquals("TRUE", compressionLossless.getAttribute("value"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void withCompressionLossyIllegal() {
|
||||
builder(ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY))
|
||||
.withCompressionLossless(false);
|
||||
assertThrows(IllegalArgumentException.class, () -> builder(ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY))
|
||||
.withCompressionLossless(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -31,9 +31,9 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import com.twelvemonkeys.imageio.color.CIELabColorConverter.Illuminant;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CIELabColorConverterTest.
|
||||
@@ -43,9 +43,9 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
* @version $Id: CIELabColorConverterTest.java,v 1.0 22/10/15 harald.kuhr Exp$
|
||||
*/
|
||||
public class CIELabColorConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNoIllumninant() {
|
||||
new CIELabColorConverter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new CIELabColorConverter(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+38
-39
@@ -1,7 +1,5 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
@@ -9,7 +7,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ColorProfilesTest {
|
||||
@Test
|
||||
@@ -53,9 +52,9 @@ public class ColorProfilesTest {
|
||||
assertFalse(ColorProfiles.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_PYCC)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_sRGBNull() {
|
||||
ColorProfiles.isCS_sRGB(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.isCS_sRGB(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,29 +70,29 @@ public class ColorProfilesTest {
|
||||
assertFalse(ColorProfiles.isCS_GRAY(ICC_Profile.getInstance(ColorSpace.CS_PYCC)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_GRAYNull() {
|
||||
ColorProfiles.isCS_GRAY(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.isCS_GRAY(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileNull() {
|
||||
ColorProfiles.createProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileNull() throws IOException {
|
||||
ColorProfiles.readProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawNull() {
|
||||
ColorProfiles.createProfileRaw(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawNull() throws IOException {
|
||||
ColorProfiles.readProfileRaw(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,74 +109,74 @@ public class ColorProfilesTest {
|
||||
assertArrayEquals(data, profileRaw.getData());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawBadData() {
|
||||
ColorProfiles.createProfileRaw(new byte[5]);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(new byte[5]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawBadData() throws IOException {
|
||||
// NOTE: The array here is larger, as there's a bug in OpenJDK 15 & 16, that throws
|
||||
// ArrayIndexOutOfBoundsException if the stream is shorter than the profile signature...
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(new byte[40]));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(new byte[40])));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileBadData() {
|
||||
ColorProfiles.createProfile(new byte[5]);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(new byte[5]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileBadData() throws IOException {
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(new byte[5]));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(new byte[5])));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfileRaw(Arrays.copyOf(data, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(Arrays.copyOf(data, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfile(Arrays.copyOf(data, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(Arrays.copyOf(data, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfileRaw(Arrays.copyOf(data, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(Arrays.copyOf(data, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfile(Arrays.copyOf(data, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(Arrays.copyOf(data, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 125)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-7
@@ -30,15 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
/**
|
||||
* ColorSpacesTest
|
||||
@@ -154,9 +155,9 @@ public class ColorSpacesTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_sRGBNull() {
|
||||
ColorSpaces.isCS_sRGB(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorSpaces.isCS_sRGB(null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -175,9 +176,9 @@ public class ColorSpacesTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_GRAYNull() {
|
||||
ColorSpaces.isCS_GRAY(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorSpaces.isCS_GRAY(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-7
@@ -31,21 +31,20 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class DiscreteAlphaIndexColorModelTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new DiscreteAlphaIndexColorModel(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new DiscreteAlphaIndexColorModel(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,7 +201,7 @@ public class DiscreteAlphaIndexColorModelTest {
|
||||
assertEquals(2, raster.getHeight());
|
||||
|
||||
assertTrue(colorModel.isCompatibleRaster(raster));
|
||||
assertThat(raster, CoreMatchers.is(WritableRaster.class)); // Specific subclasses are in sun.awt package
|
||||
assertThat(raster, instanceOf(WritableRaster.class)); // Checks if raster is an instance of WritableRaster or its subclass
|
||||
assertThat(raster.getTransferType(), CoreMatchers.equalTo(DataBuffer.TYPE_BYTE));
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
@@ -39,16 +37,18 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class KCMSSanitizerStrategyTest {
|
||||
private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '};
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testFixProfileNullProfile() throws Exception {
|
||||
new KCMSSanitizerStrategy().fixProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new KCMSSanitizerStrategy().fixProfile(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +77,7 @@ public class KCMSSanitizerStrategyTest {
|
||||
try {
|
||||
Method isSealed = Class.class.getMethod("isSealed");
|
||||
Boolean result = (Boolean) isSealed.invoke(ICC_Profile.class);
|
||||
assumeFalse("Can't mock ICC_Profile, class is sealed (as of JDK 19).", result);
|
||||
assumeFalse(result, "Can't mock ICC_Profile, class is sealed (as of JDK 19).");
|
||||
}
|
||||
catch (ReflectiveOperationException ignore) {
|
||||
// We can't have sealed classes if we don't have the isSealed method...
|
||||
|
||||
+4
-4
@@ -30,19 +30,19 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.awt.color.ICC_Profile;
|
||||
|
||||
import static com.twelvemonkeys.imageio.color.KCMSSanitizerStrategyTest.assumeICC_ProfileNotSealed;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
public class LCMSSanitizerStrategyTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testFixProfileNullProfile() throws Exception {
|
||||
new LCMSSanitizerStrategy().fixProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new LCMSSanitizerStrategy().fixProfile(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.spi.ImageInputStreamSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
+2
-3
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class UInt32ColorModelTest {
|
||||
|
||||
|
||||
+2
-2
@@ -30,11 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.spi;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ProviderInfoTest
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.spi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageWriter;
|
||||
@@ -43,7 +43,7 @@ import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ReaderWriterProviderInfoTest.
|
||||
|
||||
+36
-89
@@ -30,8 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -44,7 +44,8 @@ import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -69,7 +70,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(new ByteArrayInputStream(new byte[0]), null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +83,8 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("stream"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("stream"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +97,8 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("channel"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("channel"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +108,13 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
for (byte value : data) {
|
||||
assertEquals("Wrong data read", value & 0xff, stream.read());
|
||||
assertEquals(value & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
|
||||
assertEquals("Wrong data read", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,16 +124,16 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
|
||||
assertEquals("Wrong data read", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,14 +143,14 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[7];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +161,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[9];
|
||||
|
||||
@@ -168,9 +169,9 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
// Read backwards
|
||||
long newPos = data.length - result.length - i * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] buffer = new byte[data.length * 2];
|
||||
stream.read(buffer);
|
||||
@@ -200,7 +201,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
// Create stream
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i - 1L)) >>> 63L, stream.readBit());
|
||||
assertEquals((value << (i - 1L)) >>> 63L, stream.readBit(), String.format("bit %d differ", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +216,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new FileCache(input, null))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(String.format("bit %d differ", i), value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -232,7 +233,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
for (int i = 1; i <= 60; i++) {
|
||||
stream.seek(0);
|
||||
stream.setBitOffset(i % 8);
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i % 8)) >>> (64L - i), stream.readBits(i));
|
||||
assertEquals((value << (i % 8)) >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i * 2 % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -251,12 +252,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -267,12 +263,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,12 +280,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -305,12 +291,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,12 +308,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -343,12 +319,7 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,36 +334,12 @@ public class BufferedChannelImageInputStreamFileCacheTest {
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(-1, stream.read(new byte[1], 0, 1));
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readFully(new byte[1]);
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readByte();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
|
||||
assertThrows(EOFException.class, () -> stream.readFully(new byte[1]));
|
||||
assertThrows(EOFException.class, stream::readByte);
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
for (byte value : bytes) {
|
||||
|
||||
+34
-90
@@ -30,9 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
@@ -43,8 +40,10 @@ import java.nio.ByteOrder;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -69,7 +68,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(new ByteArrayInputStream(new byte[0])))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +81,8 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("stream"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("stream"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +95,8 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("channel"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("channel"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +106,13 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
for (byte value : data) {
|
||||
assertEquals("Wrong data read", value & 0xff, stream.read());
|
||||
assertEquals(value & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
|
||||
assertEquals("Wrong data read", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,16 +122,16 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
|
||||
assertEquals("Wrong data read", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,14 +141,14 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[7];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +159,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] result = new byte[9];
|
||||
|
||||
@@ -168,9 +167,9 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
// Read backwards
|
||||
long newPos = data.length - result.length - i * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +180,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
InputStream input = randomDataToInputStream(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
assertEquals("Stream length should be unknown", -1, stream.length());
|
||||
assertEquals(-1, stream.length(), "Stream length should be unknown");
|
||||
|
||||
byte[] buffer = new byte[data.length * 2];
|
||||
stream.read(buffer);
|
||||
@@ -200,7 +199,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
// Create stream
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i - 1L)) >>> 63L, stream.readBit());
|
||||
assertEquals((value << (i - 1L)) >>> 63L, stream.readBit(), String.format("bit %d differ", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +214,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new MemoryCache(input))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(String.format("bit %d differ", i), value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -232,7 +231,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
for (int i = 1; i <= 60; i++) {
|
||||
stream.seek(0);
|
||||
stream.setBitOffset(i % 8);
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i % 8)) >>> (64L - i), stream.readBits(i));
|
||||
assertEquals((value << (i % 8)) >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i * 2 % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -251,12 +250,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -267,12 +261,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,12 +278,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -305,12 +289,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,12 +306,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -343,12 +317,7 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,36 +332,11 @@ public class BufferedChannelImageInputStreamMemoryCacheTest {
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(-1, stream.read(new byte[1], 0, 1));
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readFully(new byte[1]);
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readByte();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, () -> stream.readFully(new byte[1]));
|
||||
assertThrows(EOFException.class, stream::readByte);
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
for (byte value : bytes) {
|
||||
|
||||
+32
-90
@@ -30,9 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
@@ -44,8 +41,10 @@ import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -71,7 +70,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(File.createTempFile("empty", ".tmp")))) {
|
||||
assertEquals("Data length should be same as stream length", 0, stream.length());
|
||||
assertEquals(0, stream.length(), "Data length should be same as stream length");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +83,8 @@ public class BufferedChannelImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("inputstream"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("inputstream"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +97,8 @@ public class BufferedChannelImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("channel"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("channel"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +108,10 @@ public class BufferedChannelImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
for (byte value : data) {
|
||||
assertEquals("Wrong data read", value & 0xff, stream.read());
|
||||
assertEquals(value & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,13 +122,13 @@ public class BufferedChannelImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,14 +139,14 @@ public class BufferedChannelImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[7];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +157,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[9];
|
||||
|
||||
@@ -166,9 +165,9 @@ public class BufferedChannelImageInputStreamTest {
|
||||
// Read backwards
|
||||
long newPos = stream.length() - result.length - i * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +178,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedChannelImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] buffer = new byte[data.length * 2];
|
||||
stream.read(buffer);
|
||||
@@ -198,7 +197,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
// Create stream
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i - 1L)) >>> 63L, stream.readBit());
|
||||
assertEquals((value << (i - 1L)) >>> 63L, stream.readBit(), String.format("bit %d differ", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +212,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
try (ImageInputStream stream = new BufferedChannelImageInputStream(new FileInputStream(file))) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(String.format("bit %d differ", i), value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -230,7 +229,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
for (int i = 1; i <= 60; i++) {
|
||||
stream.seek(0);
|
||||
stream.setBitOffset(i % 8);
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i % 8)) >>> (64L - i), stream.readBits(i));
|
||||
assertEquals((value << (i % 8)) >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i * 2 % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -249,12 +248,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -265,12 +259,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,12 +276,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -302,13 +286,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 4; i++) {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,13 +302,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 8; i++) {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -341,12 +313,7 @@ public class BufferedChannelImageInputStreamTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,36 +328,11 @@ public class BufferedChannelImageInputStreamTest {
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(-1, stream.read(new byte[1], 0, 1));
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readFully(new byte[1]);
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readByte();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, () -> stream.readFully(new byte[1]));
|
||||
assertThrows(EOFException.class, stream::readByte);
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
for (byte value : bytes) {
|
||||
|
||||
+4
-5
@@ -1,13 +1,12 @@
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageInputStreamSpi;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
public class BufferedFileImageInputStreamSpiTest extends ImageInputStreamSpiTest<File> {
|
||||
@Override
|
||||
@@ -24,7 +23,7 @@ public class BufferedFileImageInputStreamSpiTest extends ImageInputStreamSpiTest
|
||||
public void testReturnNullWhenFileDoesNotExist() throws IOException {
|
||||
// This is really stupid behavior, but it is consistent with the JRE bundled SPIs.
|
||||
File input = new File("a-file-that-should-not-exist-ever.fnf");
|
||||
assumeFalse("File should not exist: " + input.getPath(), input.exists());
|
||||
assumeFalse(input.exists(), "File should not exist: " + input.getPath());
|
||||
assertNull(provider.createInputStreamInstance(input));
|
||||
}
|
||||
}
|
||||
+33
-90
@@ -30,9 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
@@ -43,8 +40,10 @@ import java.nio.ByteOrder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -71,7 +70,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(File.createTempFile("empty", ".tmp"))) {
|
||||
assertEquals("Data length should be same as stream length", 0, stream.length());
|
||||
assertEquals(0, stream.length(), "Data length should be same as stream length");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +84,8 @@ public class BufferedFileImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("file"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("file"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +98,8 @@ public class BufferedFileImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("raf"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue( message.contains("raf"), "Exception message does not contain parameter name");
|
||||
assertTrue( message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,10 +109,10 @@ public class BufferedFileImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
for (byte value : data) {
|
||||
assertEquals("Wrong data read", value & 0xff, stream.read());
|
||||
assertEquals(value & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,13 +123,13 @@ public class BufferedFileImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,14 +140,14 @@ public class BufferedFileImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[7];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +158,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[9];
|
||||
|
||||
@@ -167,9 +166,9 @@ public class BufferedFileImageInputStreamTest {
|
||||
// Read backwards
|
||||
long newPos = stream.length() - result.length - i * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +179,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
File file = randomDataToFile(data);
|
||||
|
||||
try (BufferedFileImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
assertEquals("File length should be same as stream length", file.length(), stream.length());
|
||||
assertEquals(file.length(), stream.length(), "File length should be same as stream length");
|
||||
|
||||
byte[] buffer = new byte[data.length * 2];
|
||||
stream.read(buffer);
|
||||
@@ -199,7 +198,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
// Create stream
|
||||
try (ImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i - 1L)) >>> 63L, stream.readBit());
|
||||
assertEquals((value << (i - 1L)) >>> 63L, stream.readBit(), String.format("bit %d differ", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,7 +213,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
try (ImageInputStream stream = new BufferedFileImageInputStream(file)) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(String.format("bit %d differ", i), value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -231,7 +230,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
for (int i = 1; i <= 60; i++) {
|
||||
stream.seek(0);
|
||||
stream.setBitOffset(i % 8);
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i % 8)) >>> (64L - i), stream.readBits(i));
|
||||
assertEquals((value << (i % 8)) >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i * 2 % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -250,12 +249,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -266,12 +260,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,12 +277,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -304,12 +288,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,12 +305,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -341,13 +315,7 @@ public class BufferedFileImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 8; i++) {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,36 +330,11 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(-1, stream.read(new byte[1], 0, 1));
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readFully(new byte[1]);
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readByte();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, () -> stream.readFully(new byte[1]));
|
||||
assertThrows(EOFException.class, stream::readByte);
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
|
||||
stream.seek(0);
|
||||
for (byte value : bytes) {
|
||||
@@ -429,5 +372,5 @@ public class BufferedFileImageInputStreamTest {
|
||||
assertEquals(size, len + head);
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -33,7 +33,6 @@ package com.twelvemonkeys.imageio.stream;
|
||||
import com.twelvemonkeys.io.ole2.CompoundDocument;
|
||||
import com.twelvemonkeys.io.ole2.Entry;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
@@ -42,8 +41,10 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static java.util.Arrays.fill;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -71,8 +72,8 @@ public class BufferedImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("stream"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("stream"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +314,7 @@ public class BufferedImageInputStreamTest {
|
||||
|
||||
for (int i = 1; i < 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(i + " bits differ", value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), i + " bits differ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,8 +341,8 @@ public class BufferedImageInputStreamTest {
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull("Catalog should not be null", catalog);
|
||||
assertNotNull("Input stream can never be null", catalog.getInputStream());
|
||||
assertNotNull(catalog, "Catalog should not be null");
|
||||
assertNotNull(catalog.getInputStream(), "Input stream can never be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+29
-28
@@ -30,13 +30,14 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* ByteArrayImageInputStreamTest
|
||||
@@ -51,7 +52,7 @@ public class ByteArrayImageInputStreamTest {
|
||||
@Test
|
||||
public void testCreate() {
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(new byte[0]);
|
||||
assertEquals("Data length should be same as stream length", 0, stream.length());
|
||||
assertEquals(0, stream.length(), "Data length should be same as stream length");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,8 +64,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("data"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("data"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +78,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("data"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("data"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +92,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("offset"));
|
||||
assertTrue("Exception message does not contain -1", message.contains("-1"));
|
||||
assertTrue(message.contains("offset"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("-1"), "Exception message does not contain -1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +106,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("offset"));
|
||||
assertTrue("Exception message does not contain 2", message.contains("2"));
|
||||
assertTrue(message.contains("offset"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("2"), "Exception message does not contain 2");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +120,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("length"));
|
||||
assertTrue("Exception message does not contain -1", message.contains("-1"));
|
||||
assertTrue(message.contains("length"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("-1"), "Exception message does not contain -1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +134,8 @@ public class ByteArrayImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("length"));
|
||||
assertTrue("Exception message does not contain ™", message.contains("2"));
|
||||
assertTrue(message.contains("length"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("2"), "Exception message does not contain ™");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,10 +146,10 @@ public class ByteArrayImageInputStreamTest {
|
||||
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data);
|
||||
|
||||
assertEquals("Data length should be same as stream length", data.length, stream.length());
|
||||
assertEquals(data.length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
for (byte b : data) {
|
||||
assertEquals("Wrong data read", b & 0xff, stream.read());
|
||||
assertEquals(b & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,10 +162,10 @@ public class ByteArrayImageInputStreamTest {
|
||||
int length = random.nextInt(data.length - offset);
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data, offset, length);
|
||||
|
||||
assertEquals("Data length should be same as stream length", length, stream.length());
|
||||
assertEquals(length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
for (int i = offset; i < offset + length; i++) {
|
||||
assertEquals("Wrong data read", data[i] & 0xff, stream.read());
|
||||
assertEquals(data[i] & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,13 +176,13 @@ public class ByteArrayImageInputStreamTest {
|
||||
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data);
|
||||
|
||||
assertEquals("Data length should be same as stream length", data.length, stream.length());
|
||||
assertEquals(data.length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,13 +195,13 @@ public class ByteArrayImageInputStreamTest {
|
||||
int length = 10240;
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data, offset, length);
|
||||
|
||||
assertEquals("Data length should be same as stream length", length, stream.length());
|
||||
assertEquals(length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[1024];
|
||||
|
||||
for (int i = 0; i < length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, offset + i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, offset + i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,14 +212,14 @@ public class ByteArrayImageInputStreamTest {
|
||||
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data);
|
||||
|
||||
assertEquals("Data length should be same as stream length", data.length, stream.length());
|
||||
assertEquals(data.length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[7];
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ public class ByteArrayImageInputStreamTest {
|
||||
|
||||
ByteArrayImageInputStream stream = new ByteArrayImageInputStream(data);
|
||||
|
||||
assertEquals("Data length should be same as stream length", data.length, stream.length());
|
||||
assertEquals(data.length, stream.length(), "Data length should be same as stream length");
|
||||
|
||||
byte[] result = new byte[9];
|
||||
|
||||
@@ -237,9 +238,9 @@ public class ByteArrayImageInputStreamTest {
|
||||
// Read backwards
|
||||
long newPos = stream.length() - result.length - i * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-88
@@ -30,10 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
@@ -43,8 +39,12 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.stream.BufferedImageInputStreamTest.rangeEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public class DirectImageInputStreamTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(new ByteArrayInputStream(new byte[0]), 0)) {
|
||||
assertEquals("Data length should be same as stream length", 0, stream.length());
|
||||
assertEquals(0, stream.length(), "Data length should be same as stream length");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class DirectImageInputStreamTest {
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertNotNull("Null exception message", expected.getMessage());
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Exception message does not contain parameter name", message.contains("stream"));
|
||||
assertTrue("Exception message does not contain null", message.contains("null"));
|
||||
assertTrue(message.contains("stream"), "Exception message does not contain parameter name");
|
||||
assertTrue(message.contains("null"), "Exception message does not contain null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class DirectImageInputStreamTest {
|
||||
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(input)) {
|
||||
for (byte value : data) {
|
||||
assertEquals("Wrong data read", value & 0xff, stream.read());
|
||||
assertEquals(value & 0xff, stream.read(), "Wrong data read");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class DirectImageInputStreamTest {
|
||||
|
||||
for (int i = 0; i < data.length / result.length; i++) {
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 0; i < data.length / result.length; i += 2) {
|
||||
stream.readFully(result);
|
||||
stream.skipBytes(result.length);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, i * result.length, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, i * result.length, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,15 +137,15 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 0; i < data.length / (2 * result.length); i++) {
|
||||
long newPos = i * 2 * result.length;
|
||||
stream.seek(newPos);
|
||||
assertEquals("Wrong stream position", newPos, stream.getStreamPosition());
|
||||
assertEquals(newPos, stream.getStreamPosition(), "Wrong stream position");
|
||||
stream.readFully(result);
|
||||
assertTrue("Wrong data read: " + i, rangeEquals(data, (int) newPos, result, 0, result.length));
|
||||
assertTrue(rangeEquals(data, (int) newPos, result, 0, result.length), "Wrong data read: " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Ignore("Bit reading requires backwards seek or buffer...")
|
||||
@Disabled("Bit reading requires backwards seek or buffer...")
|
||||
@Test
|
||||
public void testReadBitRandom() throws IOException {
|
||||
byte[] bytes = new byte[8];
|
||||
@@ -155,13 +155,13 @@ public class DirectImageInputStreamTest {
|
||||
// Create stream
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(input)) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i - 1L)) >>> 63L, stream.readBit());
|
||||
assertEquals((value << (i - 1L)) >>> 63L, stream.readBit(), String.format("bit %d differ", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Ignore("Bit reading requires backwards seek or buffer...")
|
||||
@Disabled("Bit reading requires backwards seek or buffer...")
|
||||
@Test
|
||||
public void testReadBitsRandom() throws IOException {
|
||||
byte[] bytes = new byte[8];
|
||||
@@ -172,14 +172,14 @@ public class DirectImageInputStreamTest {
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(input)) {
|
||||
for (int i = 1; i <= 64; i++) {
|
||||
stream.seek(0);
|
||||
assertEquals(String.format("bit %d differ", i), value >>> (64L - i), stream.readBits(i));
|
||||
assertEquals(value >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Ignore("Bit reading requires backwards seek or buffer...")
|
||||
@Disabled("Bit reading requires backwards seek or buffer...")
|
||||
@Test
|
||||
public void testReadBitsRandomOffset() throws IOException {
|
||||
byte[] bytes = new byte[8];
|
||||
@@ -191,7 +191,7 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 1; i <= 60; i++) {
|
||||
stream.seek(0);
|
||||
stream.setBitOffset(i % 8);
|
||||
assertEquals(String.format("bit %d differ", i), (value << (i % 8)) >>> (64L - i), stream.readBits(i));
|
||||
assertEquals((value << (i % 8)) >>> (64L - i), stream.readBits(i), String.format("bit %d differ", i));
|
||||
assertEquals(i * 2L % 8, stream.getBitOffset());
|
||||
}
|
||||
}
|
||||
@@ -211,12 +211,7 @@ public class DirectImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(new ByteArrayInputStream(bytes))) {
|
||||
@@ -228,12 +223,7 @@ public class DirectImageInputStreamTest {
|
||||
assertEquals(buffer.getShort(), stream.readShort());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,13 +240,7 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 4; i++) {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(new ByteArrayInputStream(bytes))) {
|
||||
@@ -268,12 +252,7 @@ public class DirectImageInputStreamTest {
|
||||
assertEquals(buffer.getInt(), stream.readInt());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,13 +268,7 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 8; i++) {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(new ByteArrayInputStream(bytes))) {
|
||||
@@ -306,13 +279,7 @@ public class DirectImageInputStreamTest {
|
||||
for (int i = 0; i < bytes.length / 8; i++) {
|
||||
assertEquals(buffer.getLong(), stream.readLong());
|
||||
}
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,36 +294,11 @@ public class DirectImageInputStreamTest {
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(-1, stream.read(new byte[1], 0, 1));
|
||||
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readFully(new byte[1]);
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readByte();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readShort();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readInt();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
stream.readLong();
|
||||
}
|
||||
});
|
||||
assertThrows(EOFException.class, () -> stream.readFully(new byte[1]));
|
||||
assertThrows(EOFException.class, stream::readByte);
|
||||
assertThrows(EOFException.class, stream::readShort);
|
||||
assertThrows(EOFException.class, stream::readInt);
|
||||
assertThrows(EOFException.class, stream::readLong);
|
||||
}
|
||||
|
||||
try (DirectImageInputStream stream = new DirectImageInputStream(new ByteArrayInputStream(bytes))) {
|
||||
|
||||
+7
-7
@@ -1,14 +1,14 @@
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.ImageInputStreamSpi;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
abstract class ImageInputStreamSpiTest<T> {
|
||||
protected final ImageInputStreamSpi provider = createProvider();
|
||||
@@ -42,14 +42,14 @@ abstract class ImageInputStreamSpiTest<T> {
|
||||
assertNotNull(provider.getDescription(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNull() throws IOException {
|
||||
provider.createInputStreamInstance(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> provider.createInputStreamInstance(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNullCached() throws IOException {
|
||||
provider.createInputStreamInstance(null, true, ImageIO.getCacheDirectory());
|
||||
assertThrows(IllegalArgumentException.class, () -> provider.createInputStreamInstance(null, true, ImageIO.getCacheDirectory()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-3
@@ -2,10 +2,9 @@ package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import com.twelvemonkeys.imageio.spi.ProviderInfo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class StreamProviderInfoTest {
|
||||
private final ProviderInfo providerInfo = new StreamProviderInfo();
|
||||
|
||||
+10
-9
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageInputStreamImpl;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
@@ -40,7 +38,8 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SubImageInputStreamTestCase
|
||||
@@ -66,16 +65,18 @@ public class SubImageInputStreamTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullStream() throws IOException {
|
||||
new SubImageInputStream(null, 1);
|
||||
fail("Expected IllegalArgumentException with null stream");
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubImageInputStream(null, 1);
|
||||
}, "Expected IllegalArgumentException with null stream");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNegativeLength() throws IOException {
|
||||
new SubImageInputStream(createStream(0), -1);
|
||||
fail("Expected IllegalArgumentException with negative length");
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubImageInputStream(createStream(0), -1);
|
||||
}, "Expected IllegalArgumentException with negative length");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+14
-14
@@ -31,15 +31,15 @@
|
||||
package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* IIOInputStreamAdapter
|
||||
@@ -54,9 +54,9 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new IIOInputStreamAdapter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new IIOInputStreamAdapter(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,11 +70,11 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
|
||||
IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertTrue("Unexpected end of stream", -1 != stream.read());
|
||||
assertTrue(-1 != stream.read(), "Unexpected end of stream");
|
||||
}
|
||||
|
||||
assertEquals("Read value after end of stream", -1, stream.read());
|
||||
assertEquals("Read value after end of stream", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Read value after end of stream");
|
||||
assertEquals(-1, stream.read(), "Read value after end of stream");
|
||||
|
||||
// Make sure underlying stream is positioned at end of substream after close
|
||||
stream.close();
|
||||
@@ -90,11 +90,11 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes));
|
||||
IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
assertTrue("Unexpected end of stream", -1 != stream.read());
|
||||
assertTrue(-1 != stream.read(), "Unexpected end of stream");
|
||||
}
|
||||
|
||||
assertEquals("Read value after end of stream", -1, stream.read());
|
||||
assertEquals("Read value after end of stream", -1, stream.read());
|
||||
assertEquals(-1, stream.read(), "Read value after end of stream");
|
||||
assertEquals(-1, stream.read(), "Read value after end of stream");
|
||||
|
||||
// Make sure we don't read outside stream boundaries
|
||||
assertTrue(input.getStreamPosition() <= 9);
|
||||
@@ -109,7 +109,7 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes));
|
||||
IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 10);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
assertTrue("Unexpected end of stream", -1 != stream.read());
|
||||
assertTrue(-1 != stream.read(), "Unexpected end of stream");
|
||||
}
|
||||
|
||||
// Make sure we don't read outside stream boundaries
|
||||
@@ -132,7 +132,7 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
assertEquals(10, input.getStreamPosition());
|
||||
|
||||
IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input);
|
||||
assertEquals("Should not skip backwards", 0, stream.skip(-5));
|
||||
assertEquals(0, stream.skip(-5), "Should not skip backwards");
|
||||
assertEquals(10, input.getStreamPosition());
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class IIOInputStreamAdapterTest extends InputStreamAbstractTest {
|
||||
assertEquals(10, input.getStreamPosition());
|
||||
|
||||
IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9);
|
||||
assertEquals("Should not skip backwards", 0, stream.skip(-5));
|
||||
assertEquals(0, stream.skip(-5), "Should not skip backwards");
|
||||
assertEquals(10, input.getStreamPosition());
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -31,14 +31,14 @@
|
||||
package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import com.twelvemonkeys.io.OutputStreamAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* IIOOutputStreamAdapterTestCase
|
||||
@@ -53,9 +53,9 @@ public class IIOOutputStreamAdapterTest extends OutputStreamAbstractTest {
|
||||
return new IIOOutputStreamAdapter(new MemoryCacheImageOutputStream(new ByteArrayOutputStream()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new IIOOutputStreamAdapter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new IIOOutputStreamAdapter(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* IIOUtilTest
|
||||
|
||||
+88
-100
@@ -33,8 +33,7 @@ package com.twelvemonkeys.imageio.util;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -63,7 +62,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(String.format("%s not provided by %s for '%s'", pReaderClass.getSimpleName(), provider.getClass().getSimpleName(), pFormat), found);
|
||||
assertTrue(found, String.format("%s not provided by %s for '%s'", pReaderClass.getSimpleName(), provider.getClass().getSimpleName(), pFormat));
|
||||
}
|
||||
|
||||
private boolean isOurProvider(final ImageReaderSpi spi) {
|
||||
@@ -164,7 +164,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
for (TestData data : testData) {
|
||||
ImageInputStream stream = data.getInputStream();
|
||||
assertNotNull(stream);
|
||||
assertTrue("Provider is expected to be able to decode data: " + data, provider.canDecodeInput(stream));
|
||||
assertTrue(provider.canDecodeInput(stream), "Provider is expected to be able to decode data: " + data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Could not test data for read", e);
|
||||
}
|
||||
|
||||
assertFalse("ImageReader can read null input", canRead);
|
||||
assertFalse(canRead, "ImageReader can read null input");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,16 +227,16 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause(String.format("Image %s index %s could not be read: %s", data.getInput(), i, e), e);
|
||||
}
|
||||
|
||||
assertNotNull(String.format("Image %s index %s was null!", data.getInput(), i), image);
|
||||
assertNotNull(image, String.format("Image %s index %s was null!", data.getInput(), i));
|
||||
|
||||
assertEquals(
|
||||
String.format("Image %s index %s has wrong width: %s", data.getInput(), i, image.getWidth()),
|
||||
data.getDimension(i).width,
|
||||
image.getWidth()
|
||||
image.getWidth(),
|
||||
String.format("Image %s index %s has wrong width: %s", data.getInput(), i, image.getWidth())
|
||||
);
|
||||
assertEquals(
|
||||
String.format("Image %s index %s has wrong height: %s", data.getInput(), i, image.getHeight()),
|
||||
data.getDimension(i).height, image.getHeight()
|
||||
data.getDimension(i).height, image.getHeight(),
|
||||
String.format("Image %s index %s has wrong height: %s", data.getInput(), i, image.getHeight())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -306,67 +306,55 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testReadNoInput() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
// Do not set input
|
||||
|
||||
try {
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
reader.read(0);
|
||||
fail("Read image with no input");
|
||||
}
|
||||
catch (IOException e) {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testReadIndexNegativeWithParam() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
try {
|
||||
reader.read(-1, reader.getDefaultReadParam());
|
||||
fail("Read image with illegal index");
|
||||
}
|
||||
catch (IOException e) {
|
||||
failBecause("Image could not be read", e);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
reader.read(-1, reader.getDefaultReadParam());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testReadIndexOutOfBoundsWithParam() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
try {
|
||||
reader.read(Short.MAX_VALUE, reader.getDefaultReadParam());
|
||||
fail("Read image with index out of bounds");
|
||||
}
|
||||
catch (IOException e) {
|
||||
failBecause("Image could not be read", e);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
reader.read(Short.MAX_VALUE, reader.getDefaultReadParam());
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testReadNoInputWithParam() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
// Do not set input
|
||||
|
||||
try {
|
||||
reader.read(0, reader.getDefaultReadParam());
|
||||
fail("Read image with no input");
|
||||
}
|
||||
catch (IOException e) {
|
||||
failBecause("Image could not be read", e);
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
reader.read(0);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
@@ -387,9 +375,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(data.getDimension(0).width, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(data.getDimension(0).height, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -408,9 +396,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(data.getDimension(0).width, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(data.getDimension(0).height, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -429,9 +417,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), data.getDimension(0).width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), data.getDimension(0).height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(data.getDimension(0).width, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(data.getDimension(0).height, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -454,9 +442,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), 10, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(10, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(10, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
}
|
||||
|
||||
reader.dispose();
|
||||
@@ -479,9 +467,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: ", (data.getDimension(0).width + 4) / 5, image.getWidth());
|
||||
assertEquals("Read image has wrong height: ", (data.getDimension(0).height + 4) / 5, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals((data.getDimension(0).width + 4) / 5, image.getWidth(), "Read image has wrong width: ");
|
||||
assertEquals((data.getDimension(0).height + 4) / 5, image.getHeight(), "Read image has wrong height: ");
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -516,8 +504,8 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected final void assertSubsampledImageDataEquals(String message, BufferedImage expected, BufferedImage actual, ImageReadParam param) throws IOException {
|
||||
assertNotNull("Expected image was null", expected);
|
||||
assertNotNull("Actual image was null!", actual);
|
||||
assertNotNull(expected, "Expected image was null");
|
||||
assertNotNull(actual, "Actual image was null!");
|
||||
|
||||
if (expected == actual) {
|
||||
return;
|
||||
@@ -528,9 +516,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
int xSub = param.getSourceXSubsampling();
|
||||
int ySub = param.getSourceYSubsampling();
|
||||
|
||||
assertEquals("Subsampled image has wrong width: ", (expected.getWidth() - xOff + xSub - 1) / xSub, actual.getWidth());
|
||||
assertEquals("Subsampled image has wrong height: ", (expected.getHeight() - yOff + ySub - 1) / ySub, actual.getHeight());
|
||||
assertEquals("Subsampled has different type", expected.getType(), actual.getType());
|
||||
assertEquals((expected.getWidth() - xOff + xSub - 1) / xSub, actual.getWidth(), "Subsampled image has wrong width: ");
|
||||
assertEquals((expected.getHeight() - yOff + ySub - 1) / ySub, actual.getHeight(), "Subsampled image has wrong height: ");
|
||||
assertEquals(expected.getType(), actual.getType(), "Subsampled has different type");
|
||||
|
||||
for (int y = 0; y < actual.getHeight(); y++) {
|
||||
for (int x = 0; x < actual.getWidth(); x++) {
|
||||
@@ -551,15 +539,15 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
System.err.println("tempActual.getAbsolutePath(): " + tempActual.getAbsolutePath());
|
||||
ImageIO.write(actual, "PNG", tempActual);
|
||||
|
||||
assertEquals(String.format("%s ARGB at (%d, %d)", message, x, y), String.format("#%08x", expectedRGB), String.format("#%08x", actualRGB));
|
||||
assertEquals(String.format("#%08x", expectedRGB), String.format("#%08x", actualRGB), String.format("%s ARGB at (%d, %d)", message, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertImageDataEquals(String message, BufferedImage expected, BufferedImage actual) {
|
||||
assertNotNull("Expected image was null", expected);
|
||||
assertNotNull("Actual image was null!", actual);
|
||||
assertNotNull(expected, "Expected image was null");
|
||||
assertNotNull(actual, "Actual image was null!");
|
||||
|
||||
if (expected == actual) {
|
||||
return;
|
||||
@@ -570,10 +558,10 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
int expectedRGB = expected.getRGB(x, y);
|
||||
int actualRGB = actual.getRGB(x, y);
|
||||
|
||||
assertEquals(String.format("%s alpha at (%d, %d)", message, x, y), (expectedRGB >> 24) & 0xff, (actualRGB >> 24) & 0xff, 5);
|
||||
assertEquals(String.format("%s red at (%d, %d)", message, x, y), (expectedRGB >> 16) & 0xff, (actualRGB >> 16) & 0xff, 5);
|
||||
assertEquals(String.format("%s green at (%d, %d)", message, x, y), (expectedRGB >> 8) & 0xff, (actualRGB >> 8) & 0xff, 5);
|
||||
assertEquals(String.format("%s blue at (%d, %d)", message, x, y), expectedRGB & 0xff, actualRGB & 0xff, 5);
|
||||
assertEquals((expectedRGB >> 24) & 0xff, (actualRGB >> 24) & 0xff, 5, String.format("%s alpha at (%d, %d)", message, x, y));
|
||||
assertEquals((expectedRGB >> 16) & 0xff, (actualRGB >> 16) & 0xff, 5, String.format("%s red at (%d, %d)", message, x, y));
|
||||
assertEquals((expectedRGB >> 8) & 0xff, (actualRGB >> 8) & 0xff, 5, String.format("%s green at (%d, %d)", message, x, y));
|
||||
assertEquals(expectedRGB & 0xff, actualRGB & 0xff, 5, String.format("%s blue at (%d, %d)", message, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -595,9 +583,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), 10, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(10, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(10, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -622,9 +610,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
|
||||
final BufferedImage image = reader.read(imageIndex, param);
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), r.width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), r.height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(r.width, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(r.height, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
try {
|
||||
assertImageDataEquals("Images differ", roi, image);
|
||||
@@ -678,9 +666,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), 10, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(10, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(10, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
}
|
||||
|
||||
reader.dispose();
|
||||
@@ -705,9 +693,9 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(), 5, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(), 5, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(5, image.getWidth(), "Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(5, image.getHeight(), "Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -798,11 +786,11 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(),
|
||||
data.getDimension(0).width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(),
|
||||
data.getDimension(0).height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals( data.getDimension(0).width, image.getWidth(),
|
||||
"Read image has wrong width: " + image.getWidth());
|
||||
assertEquals( data.getDimension(0).height, image.getHeight(),
|
||||
"Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -821,11 +809,11 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
failBecause("Image could not be read", e);
|
||||
}
|
||||
|
||||
assertNotNull("Image was null!", image);
|
||||
assertEquals("Read image has wrong width: " + image.getWidth(),
|
||||
data.getDimension(0).width, image.getWidth());
|
||||
assertEquals("Read image has wrong height: " + image.getHeight(),
|
||||
data.getDimension(0).height, image.getHeight());
|
||||
assertNotNull(image, "Image was null!");
|
||||
assertEquals(data.getDimension(0).width, image.getWidth(),
|
||||
"Read image has wrong width: " + image.getWidth());
|
||||
assertEquals(data.getDimension(0).height, image.getHeight(),
|
||||
"Read image has wrong height: " + image.getHeight());
|
||||
|
||||
reader.dispose();
|
||||
}
|
||||
@@ -954,7 +942,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
fail("Could not read image width: " + e);
|
||||
}
|
||||
assertEquals("Wrong width reported", data.getDimension(0).width, width);
|
||||
assertEquals(data.getDimension(0).width, width, "Wrong width reported");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -993,7 +981,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
fail("Could not read image width: " + e);
|
||||
}
|
||||
assertEquals("Wrong width reported", 0, width);
|
||||
assertEquals(0, width, "Wrong width reported");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -1010,7 +998,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
fail("Could not read image height: " + e);
|
||||
}
|
||||
assertEquals("Wrong height reported", data.getDimension(0).height, height);
|
||||
assertEquals(data.getDimension(0).height, height, "Wrong height reported");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -1028,7 +1016,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
fail("Could not read image height: " + e);
|
||||
}
|
||||
assertEquals("Wrong height reported", 0, height);
|
||||
assertEquals(0, height, "Wrong height reported");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -1067,7 +1055,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
fail("Could not read image aspect ratio" + e);
|
||||
}
|
||||
Dimension d = data.getDimension(0);
|
||||
assertEquals("Wrong aspect aspect ratio", d.getWidth() / d.getHeight(), aspectRatio, 0.001);
|
||||
assertEquals(d.getWidth() / d.getHeight(), aspectRatio, 0.001, "Wrong aspect aspect ratio");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -1085,7 +1073,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
catch (IOException e) {
|
||||
fail("Could not read image aspect ratio" + e);
|
||||
}
|
||||
assertEquals("Wrong aspect aspect ratio", 0f, aspectRatio, 0f);
|
||||
assertEquals(0f, aspectRatio, 0f, "Wrong aspect aspect ratio");
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@@ -1381,7 +1369,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("ImageTypeSpecifier from getRawImageType should be in the iterator from getImageTypes", rawFound);
|
||||
assertTrue(rawFound, "ImageTypeSpecifier from getRawImageType should be in the iterator from getImageTypes");
|
||||
}
|
||||
|
||||
reader.dispose();
|
||||
@@ -1487,7 +1475,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Wrong message: " + message, message.contains("dest"));
|
||||
assertTrue(message.contains("dest"), "Wrong message: " + message);
|
||||
}
|
||||
}
|
||||
reader.dispose();
|
||||
@@ -1637,7 +1625,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
BufferedImage two = reader.read(0);
|
||||
|
||||
// Test for same BufferedImage instance
|
||||
assertNotSame("Multiple reads return same (mutable) image", one, two);
|
||||
assertNotSame(one, two, "Multiple reads return same (mutable) image");
|
||||
|
||||
// Test for same backing storage (array)
|
||||
one.setRGB(0, 0, Color.BLACK.getRGB());
|
||||
@@ -1721,7 +1709,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
BufferedImage one = reader.readThumbnail(i, j);
|
||||
BufferedImage two = reader.readThumbnail(i, j);
|
||||
|
||||
assertNotSame("Multiple reads return same (mutable) image", one, two);
|
||||
assertNotSame(one, two, "Multiple reads return same (mutable) image");
|
||||
|
||||
Graphics2D g = one.createGraphics();
|
||||
try {
|
||||
@@ -1786,13 +1774,13 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
reader.dispose();
|
||||
}
|
||||
|
||||
@Ignore("TODO: Implement")
|
||||
@Disabled("TODO: Implement")
|
||||
@Test
|
||||
public void testSetDestinationBands() {
|
||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
}
|
||||
|
||||
@Ignore("TODO: Implement")
|
||||
@Disabled("TODO: Implement")
|
||||
@Test
|
||||
public void testSetSourceBands() {
|
||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||
@@ -1893,7 +1881,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
||||
public ImageInputStream getInputStream() {
|
||||
try {
|
||||
ImageInputStream stream = ImageIO.createImageInputStream(input);
|
||||
assertNotNull("Could not create ImageInputStream for input: " + input, stream);
|
||||
assertNotNull(stream, "Could not create ImageInputStream for input: " + input);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
+2
-3
@@ -32,14 +32,13 @@ package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import java.awt.color.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ImageTypeSpecifiersTest {
|
||||
|
||||
|
||||
+9
-15
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -50,10 +49,8 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -145,7 +142,7 @@ public abstract class ImageWriterAbstractTest<T extends ImageWriter> {
|
||||
throw new AssertionError(e.getMessage(), e);
|
||||
}
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
assertTrue(buffer.size() > 0, "No image data written");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,26 +161,23 @@ public abstract class ImageWriterAbstractTest<T extends ImageWriter> {
|
||||
throw new AssertionError(e.getMessage(), e);
|
||||
}
|
||||
|
||||
assertEquals("Image data written", 0, buffer.size());
|
||||
assertEquals(0, buffer.size(), "Image data written");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testWriteNoOutput() throws IOException {
|
||||
ImageWriter writer = createWriter();
|
||||
|
||||
try {
|
||||
writer.write(getTestData(0));
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
writer.write(getTestData(0));
|
||||
}, "Expected IllegalStateException when no output is set on writer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultWriteParam() throws IOException {
|
||||
ImageWriter writer = createWriter();
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
assertNotNull("Default ImageWriteParam is null", param);
|
||||
assertNotNull(param, "Default ImageWriteParam is null");
|
||||
}
|
||||
|
||||
// TODO: Test writing with params
|
||||
|
||||
+4
-7
@@ -30,17 +30,14 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.IndexColorModel;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* IndexedImageTypeSpecifierTestCase
|
||||
@@ -82,9 +79,9 @@ public class IndexedImageTypeSpecifierTest {
|
||||
assertNotEquals(spec.hashCode(), different.hashCode());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new IndexedImageTypeSpecifier(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new IndexedImageTypeSpecifier(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-8
@@ -1,15 +1,13 @@
|
||||
package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import java.awt.*;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.*;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* RasterUtilsTest.
|
||||
@@ -19,15 +17,15 @@ import static org.junit.Assert.assertSame;
|
||||
* @version $Id: RasterUtilsTest.java,v 1.0 05/05/2021 haraldk Exp$
|
||||
*/
|
||||
public class RasterUtilsTest {
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testAsByteRasterFromNull() {
|
||||
RasterUtils.asByteRaster((Raster) null);
|
||||
assertThrows(NullPointerException.class, () -> RasterUtils.asByteRaster((Raster) null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantCast")
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testAsByteRasterWritableFromNull() {
|
||||
RasterUtils.asByteRaster((WritableRaster) null);
|
||||
assertThrows(NullPointerException.class, () -> RasterUtils.asByteRaster((WritableRaster) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import com.twelvemonkeys.imageio.color.ColorSpaces;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
@@ -42,7 +40,9 @@ import java.awt.image.PixelInterleavedSampleModel;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class UInt32ImageTypeSpecifierTest {
|
||||
private static final ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
|
||||
+2
-3
@@ -1,8 +1,7 @@
|
||||
package com.twelvemonkeys.imageio.plugins.hdr.tonemap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DefaultToneMapperTest {
|
||||
|
||||
|
||||
+2
-3
@@ -1,8 +1,7 @@
|
||||
package com.twelvemonkeys.imageio.plugins.hdr.tonemap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class GammaToneMapperTest {
|
||||
private final GammaToneMapper mapper = new GammaToneMapper();
|
||||
|
||||
+2
-3
@@ -1,8 +1,7 @@
|
||||
package com.twelvemonkeys.imageio.plugins.hdr.tonemap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class NullToneMapperTest {
|
||||
private final NullToneMapper mapper = new NullToneMapper();
|
||||
|
||||
+5
-4
@@ -32,8 +32,9 @@ package com.twelvemonkeys.imageio.plugins.icns;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
@@ -126,14 +127,14 @@ public class ICNSImageReaderTest extends ImageReaderAbstractTest<ICNSImageReader
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
|
||||
+12
-14
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.plugins.icns;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
@@ -45,8 +43,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* ICNSImageWriterTest.
|
||||
@@ -78,15 +77,14 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWriteNonSquare() throws IOException {
|
||||
// ICNS only supports square icons (except some arcane 16x12 we don't currently support)
|
||||
ImageWriter writer = createWriter();
|
||||
try (ImageOutputStream stream = ImageIO.createImageOutputStream(new ByteArrayOutputStream())) {
|
||||
|
||||
writer.setOutput(stream);
|
||||
|
||||
writer.write(new BufferedImage(32, 64, BufferedImage.TYPE_INT_ARGB));
|
||||
assertThrows(IllegalArgumentException.class, () -> writer.write(new BufferedImage(32, 64, BufferedImage.TYPE_INT_ARGB)));
|
||||
|
||||
}
|
||||
finally {
|
||||
@@ -94,7 +92,7 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWriteBadSize() throws IOException {
|
||||
// ICNS only supports sizes in multiples of 2 (16, 32, 64, ..., 1024 + 48 and 96)
|
||||
ImageWriter writer = createWriter();
|
||||
@@ -102,7 +100,7 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
|
||||
writer.setOutput(stream);
|
||||
|
||||
writer.write(new BufferedImage(17, 17, BufferedImage.TYPE_INT_ARGB));
|
||||
assertThrows(IllegalArgumentException.class, () -> writer.write(new BufferedImage(17, 17, BufferedImage.TYPE_INT_ARGB)));
|
||||
|
||||
}
|
||||
finally {
|
||||
@@ -121,7 +119,7 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testWriteSequenceNotStarted() throws IOException {
|
||||
// ICNS only supports sizes in multiples of 2 (16, 32, 64, ..., 1024 + 48 and 96)
|
||||
ImageWriter writer = createWriter();
|
||||
@@ -130,7 +128,7 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
writer.setOutput(stream);
|
||||
|
||||
BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
|
||||
writer.writeToSequence(new IIOImage(image, null, null), writer.getDefaultWriteParam());
|
||||
assertThrows(IllegalStateException.class, () -> writer.writeToSequence(new IIOImage(image, null, null), writer.getDefaultWriteParam()));
|
||||
|
||||
}
|
||||
finally {
|
||||
@@ -138,21 +136,21 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testEndSequenceNotStarted() throws IOException {
|
||||
// ICNS only supports sizes in multiples of 2 (16, 32, 64, ..., 1024 + 48 and 96)
|
||||
ImageWriter writer = createWriter();
|
||||
try (ImageOutputStream stream = ImageIO.createImageOutputStream(new ByteArrayOutputStream())) {
|
||||
|
||||
writer.setOutput(stream);
|
||||
writer.endWriteSequence();
|
||||
assertThrows(IllegalStateException.class, () -> writer.endWriteSequence());
|
||||
}
|
||||
finally {
|
||||
writer.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testPrepareSequenceAlreadyStarted() throws IOException {
|
||||
// ICNS only supports sizes in multiples of 2 (16, 32, 64, ..., 1024 + 48 and 96)
|
||||
ImageWriter writer = createWriter();
|
||||
@@ -160,7 +158,7 @@ public class ICNSImageWriterTest extends ImageWriterAbstractTest<ICNSImageWriter
|
||||
|
||||
writer.setOutput(stream);
|
||||
writer.prepareWriteSequence(null);
|
||||
writer.prepareWriteSequence(null);
|
||||
assertThrows(IllegalStateException.class, () -> writer.prepareWriteSequence(null));
|
||||
}
|
||||
finally {
|
||||
writer.dispose();
|
||||
|
||||
+6
-13
@@ -2,8 +2,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
@@ -15,8 +13,9 @@ import javax.imageio.metadata.IIOMetadataNode;
|
||||
import java.awt.image.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static java.awt.image.BufferedImage.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class IFFImageMetadataTest {
|
||||
|
||||
@@ -42,20 +41,14 @@ public class IFFImageMetadataTest {
|
||||
// Other formats
|
||||
assertNull(metadata.getNativeMetadataFormatName());
|
||||
assertNull(metadata.getExtraMetadataFormatNames());
|
||||
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
metadata.getAsTree("com_foo_bar_1.0");
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
metadata.getAsTree("com_foo_bar_1.0");
|
||||
});
|
||||
|
||||
// Read-only
|
||||
assertTrue(metadata.isReadOnly());
|
||||
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
metadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName));
|
||||
}
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
metadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
@@ -45,8 +43,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* IFFImageReaderTestCase
|
||||
*
|
||||
@@ -144,9 +142,9 @@ public class IFFImageReaderTest extends ImageReaderAbstractTest<IFFImageReader>
|
||||
for (int i = 0; i < 32; i++) {
|
||||
// Make sure the color model is really EHB
|
||||
try {
|
||||
assertEquals("red", (reds[i] & 0xff) / 2, reds[i + 32] & 0xff);
|
||||
assertEquals("blue", (blues[i] & 0xff) / 2, blues[i + 32] & 0xff);
|
||||
assertEquals("green", (greens[i] & 0xff) / 2, greens[i + 32] & 0xff);
|
||||
assertEquals((reds[i] & 0xff) / 2, reds[i + 32] & 0xff, "red");
|
||||
assertEquals((blues[i] & 0xff) / 2, blues[i + 32] & 0xff, "blue");
|
||||
assertEquals((greens[i] & 0xff) / 2, greens[i + 32] & 0xff, "green");
|
||||
}
|
||||
catch (AssertionError err) {
|
||||
throw new AssertionError("Color " + i + " " + err.getMessage(), err);
|
||||
|
||||
+9
-11
@@ -33,8 +33,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
|
||||
import com.twelvemonkeys.image.MonochromeColorModel;
|
||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
@@ -49,8 +47,8 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* JPEG2000ImageWriterTest
|
||||
*
|
||||
@@ -104,7 +102,7 @@ public class IFFImageWriterTest extends ImageWriterAbstractTest<IFFImageWriter>
|
||||
stream.close(); // Force data to be written
|
||||
}
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
assertTrue(buffer.size() > 0, "No image data written");
|
||||
|
||||
ImageInputStream input = ImageIO.createImageInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
BufferedImage written = ImageIO.read(input);
|
||||
@@ -129,14 +127,14 @@ public class IFFImageWriterTest extends ImageWriterAbstractTest<IFFImageWriter>
|
||||
|
||||
if (expected.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_GRAY) {
|
||||
// NOTE: For some reason, gray data seems to be one step off...
|
||||
assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000, 0x10000);
|
||||
assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00, 0x100);
|
||||
assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff, 0x1);
|
||||
assertEquals(expectedRGB & 0xff0000, actualRGB & 0xff0000, 0x10000, "R(" + x + "," + y + ")");
|
||||
assertEquals(expectedRGB & 0x00ff00, actualRGB & 0x00ff00, 0x100, "G(" + x + "," + y + ")");
|
||||
assertEquals(expectedRGB & 0x0000ff, actualRGB & 0x0000ff, 0x1, "B(" + x + "," + y + ")");
|
||||
}
|
||||
else {
|
||||
assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000);
|
||||
assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00);
|
||||
assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff);
|
||||
assertEquals(expectedRGB & 0xff0000, actualRGB & 0xff0000, "R(" + x + "," + y + ")");
|
||||
assertEquals(expectedRGB & 0x00ff00, actualRGB & 0x00ff00, "G(" + x + "," + y + ")");
|
||||
assertEquals(expectedRGB & 0x0000ff, actualRGB & 0x0000ff, "B(" + x + "," + y + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-14
@@ -5,15 +5,13 @@ import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderAbstractTest;
|
||||
import com.twelvemonkeys.io.enc.Encoder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* RGB8RLEDecoderTest.
|
||||
@@ -42,36 +40,39 @@ public class RGB8RLEDecoderTest extends DecoderAbstractTest {
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]);
|
||||
|
||||
int count = decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
assertEquals("Should not be able to read any bytes", 0, count);
|
||||
assertEquals(0, count, "Should not be able to read any bytes");
|
||||
}
|
||||
|
||||
@Test(expected = EOFException.class)
|
||||
@Test
|
||||
public final void testDecodePartial() throws IOException {
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0});
|
||||
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
fail("Should not be able to read any bytes");
|
||||
assertThrows(EOFException.class, () -> {
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
}, "Should not be able to read any bytes");
|
||||
}
|
||||
|
||||
@Test(expected = EOFException.class)
|
||||
@Test
|
||||
public final void testDecodePartialToo() throws IOException {
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0, 0, 0, 1, 0, 0});
|
||||
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
fail("Should not be able to read any bytes");
|
||||
assertThrows(EOFException.class, () -> {
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
}, "Should not be able to read any bytes");
|
||||
}
|
||||
|
||||
@Test(expected = DecodeException.class)
|
||||
@Test
|
||||
public final void testDecodeZeroRun() throws IOException {
|
||||
// The spec says that 0-runs should be used to signal that the run is > 127,
|
||||
// and contained in the next byte, however, this is not used in practise and not supported.
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0, 0, 0, 0});
|
||||
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
fail("Should not be able to read any bytes");
|
||||
assertThrows(DecodeException.class, () -> {
|
||||
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
|
||||
}, "Should not be able to read any bytes");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-5
@@ -33,9 +33,6 @@ package com.twelvemonkeys.imageio.plugins.jpeg.jaiinterop;
|
||||
import com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
@@ -47,7 +44,9 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests the JAI TIFFImageReader delegating to our JPEGImageReader.
|
||||
@@ -99,7 +98,7 @@ public class JAITIFFImageReaderInteroperabilityTest extends ImageReaderAbstractT
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Ignore("Fails in TIFFImageReader")
|
||||
@Disabled("Fails in TIFFImageReader")
|
||||
@Override
|
||||
public void testSetDestinationIllegal() {
|
||||
}
|
||||
|
||||
+7
-11
@@ -33,10 +33,6 @@ package com.twelvemonkeys.imageio.plugins.jpeg.jep262interop;
|
||||
import com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
@@ -48,7 +44,10 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
/**
|
||||
* Tests the JEP 262 TIFFImageReader delegating to our JPEGImageReader.
|
||||
@@ -69,12 +68,9 @@ public class JEP262TIFFImageReaderInteroperabilityTest extends ImageReaderAbstra
|
||||
}
|
||||
}, true);
|
||||
|
||||
if (providers.hasNext()) {
|
||||
return providers.next();
|
||||
}
|
||||
|
||||
// Skip tests if we have no Spi (ie. pre JDK 9)
|
||||
throw new AssumptionViolatedException("Provider " + JEP_262_PROVIDER_CLASS_NAME + " not found");
|
||||
assumeTrue(providers.hasNext(), "Provider " + JEP_262_PROVIDER_CLASS_NAME + " not found");
|
||||
return providers.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,7 +97,7 @@ public class JEP262TIFFImageReaderInteroperabilityTest extends ImageReaderAbstra
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Ignore("Fails in TIFFImageReader")
|
||||
@Disabled("Fails in TIFFImageReader")
|
||||
@Override
|
||||
public void testSetDestinationIllegal() {
|
||||
}
|
||||
|
||||
+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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -30,9 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractEntryTest
|
||||
@@ -51,9 +50,9 @@ public class AbstractEntryTest extends EntryAbstractTest {
|
||||
return new AbstractEntry(identifier, value) {};
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEntryNullId() {
|
||||
createEntry(null, new Object());
|
||||
assertThrows(IllegalArgumentException.class, () -> createEntry(null, new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-8
@@ -30,14 +30,12 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CompoundDirectoryTest
|
||||
@@ -60,9 +58,9 @@ public abstract class CompoundDirectoryAbstractTest extends DirectoryAbstractTes
|
||||
return createCompoundDirectory(Collections.<Directory>singleton(createSingleDirectory(entries)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullDirectories() {
|
||||
createCompoundDirectory(Collections.<Directory>singleton(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> createCompoundDirectory(Collections.<Directory>singleton(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,12 +101,12 @@ public abstract class CompoundDirectoryAbstractTest extends DirectoryAbstractTes
|
||||
assertSame(three, directory.getDirectory(2));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testOutOfBounds() {
|
||||
Directory only = createSingleDirectory(null);
|
||||
CompoundDirectory directory = createCompoundDirectory(Collections.<Directory>singleton(only));
|
||||
|
||||
directory.getDirectory(directory.directoryCount());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> directory.getDirectory(directory.directoryCount()));
|
||||
}
|
||||
|
||||
protected static final class TestDirectory extends AbstractDirectory {
|
||||
|
||||
+4
-4
@@ -31,11 +31,11 @@
|
||||
package com.twelvemonkeys.imageio.metadata;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* DirectoryTest
|
||||
@@ -65,9 +65,9 @@ public abstract class DirectoryAbstractTest extends ObjectAbstractTest {
|
||||
assertEquals(0, directory.size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullEntries() {
|
||||
createDirectory(Collections.<Entry>singleton(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> createDirectory(Collections.<Entry>singleton(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -31,11 +31,11 @@
|
||||
package com.twelvemonkeys.imageio.metadata;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* EntryTest
|
||||
|
||||
+4
-4
@@ -35,7 +35,6 @@ import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
@@ -44,7 +43,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ReaderAbstractTest
|
||||
@@ -71,9 +71,9 @@ public abstract class MetadataReaderAbstractTest {
|
||||
|
||||
protected abstract MetadataReader createReader();
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadNull() throws IOException {
|
||||
createReader().read(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> createReader().read(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+11
-6
@@ -31,8 +31,8 @@
|
||||
package com.twelvemonkeys.imageio.metadata;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -43,6 +43,8 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* ReaderAbstractTest
|
||||
*
|
||||
@@ -68,14 +70,17 @@ public abstract class MetadataWriterAbstractTest {
|
||||
|
||||
protected abstract MetadataWriter createWriter();
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWriteNullDirectory() throws IOException {
|
||||
createWriter().write(null, new MemoryCacheImageOutputStream(new ByteArrayOutputStream()));
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> createWriter().write(null, new MemoryCacheImageOutputStream(new ByteArrayOutputStream())));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWriteNullStream() throws IOException {
|
||||
createWriter().write(new AbstractDirectory(new ArrayList<Entry>()) {
|
||||
}, null);
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
createWriter().write(new AbstractDirectory(new ArrayList<Entry>()) {
|
||||
}, null)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -36,17 +36,16 @@ import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* EXIFReaderTest
|
||||
@@ -83,14 +82,16 @@ public class EXIFReaderTest extends MetadataReaderAbstractTest {
|
||||
assertEquals(exif.size(), exif.getDirectory(0).size() + exif.getDirectory(1).size());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testDirectoryOutOfBounds() throws IOException {
|
||||
InputStream data = getData();
|
||||
|
||||
CompoundDirectory exif = (CompoundDirectory) createReader().read(ImageIO.createImageInputStream(data));
|
||||
|
||||
assertEquals(2, exif.directoryCount());
|
||||
assertNotNull(exif.getDirectory(exif.directoryCount()));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
exif.getDirectory(exif.directoryCount());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-3
@@ -37,7 +37,6 @@ import com.twelvemonkeys.imageio.metadata.tiff.TIFFReader;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.io.FastByteArrayOutputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
@@ -47,8 +46,8 @@ import java.io.InputStream;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* TIFFWriterTest
|
||||
|
||||
+8
-9
@@ -30,9 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata.exif;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* RationalTest
|
||||
@@ -43,19 +42,19 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RationalTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testZeroDenominator() {
|
||||
new Rational(1, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(1, 0));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testLongMinValueNumerator() {
|
||||
new Rational(Long.MIN_VALUE, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(Long.MIN_VALUE, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testLongMinValueDenominator() {
|
||||
new Rational(1, Long.MIN_VALUE);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(1, Long.MIN_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-3
@@ -33,14 +33,13 @@ package com.twelvemonkeys.imageio.metadata.iptc;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* IPTCReaderTest
|
||||
|
||||
+4
-5
@@ -34,7 +34,6 @@ import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.MetadataWriter;
|
||||
import com.twelvemonkeys.imageio.metadata.MetadataWriterAbstractTest;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -43,8 +42,9 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* IPTCWriterTest.
|
||||
@@ -72,8 +72,7 @@ public class IPTCWriterTest extends MetadataWriterAbstractTest {
|
||||
public void testRewriteExisting() throws IOException {
|
||||
IPTCReader reader = createReader();
|
||||
Directory iptc = reader.read(getDataAsIIS());
|
||||
assumeNotNull(iptc);
|
||||
|
||||
assumeTrue(iptc != null, "IPTC object should not be null");
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(bytes);
|
||||
createWriter().write(iptc, stream);
|
||||
|
||||
+6
-7
@@ -31,8 +31,6 @@
|
||||
package com.twelvemonkeys.imageio.metadata.jpeg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -47,8 +45,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JPEGQualityTest
|
||||
@@ -97,7 +96,7 @@ public class JPEGQualityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Need a JPEG test image with bad DQT data...")
|
||||
@Disabled("Need a JPEG test image with bad DQT data...")
|
||||
@Test
|
||||
public void testGetQualityBadData() throws IOException {
|
||||
ImageInputStream stream = ImageIO.createImageInputStream(getClass().getResourceAsStream("/bad-data"));
|
||||
@@ -257,9 +256,9 @@ public class JPEGQualityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetQTablesNull() throws IOException {
|
||||
JPEGQuality.getQTables(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> JPEGQuality.getQTables(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -31,11 +31,11 @@
|
||||
package com.twelvemonkeys.imageio.metadata.jpeg;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* JPEGSegmentTest
|
||||
|
||||
+9
-10
@@ -31,7 +31,6 @@
|
||||
package com.twelvemonkeys.imageio.metadata.jpeg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -46,8 +45,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* JPEGSegmentUtilTest
|
||||
@@ -148,7 +147,7 @@ public class JPEGSegmentUtilTest {
|
||||
}
|
||||
|
||||
ICC_Profile profile = ICC_Profile.getInstance(new SequenceInputStream(Collections.enumeration(Arrays.asList(streams))));
|
||||
assertNotNull("Profile could not be read, probably bad data", profile);
|
||||
assertNotNull(profile, "Profile could not be read, probably bad data");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,9 +155,9 @@ public class JPEGSegmentUtilTest {
|
||||
List<JPEGSegment> segments = JPEGSegmentUtil.readSegments(getData("/jpeg/9788245605525.jpg"), JPEGSegmentUtil.ALL_SEGMENTS);
|
||||
assertEquals(7, segments.size());
|
||||
|
||||
assertEquals(segments.toString(), JPEG.SOF0, segments.get(3).marker());
|
||||
assertEquals(segments.toString(), null, segments.get(3).identifier());
|
||||
assertEquals(segments.toString(), JPEG.SOS, segments.get(segments.size() - 1).marker());
|
||||
assertEquals(JPEG.SOF0, segments.get(3).marker(), segments.toString());
|
||||
assertEquals(null, segments.get(3).identifier(), segments.toString());
|
||||
assertEquals(JPEG.SOS, segments.get(segments.size() - 1).marker(), segments.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,9 +165,9 @@ public class JPEGSegmentUtilTest {
|
||||
List<JPEGSegment> segments = JPEGSegmentUtil.readSegments(getData("/jpeg/ts_open_300dpi.jpg"), JPEGSegmentUtil.ALL_SEGMENTS);
|
||||
assertEquals(27, segments.size());
|
||||
|
||||
assertEquals(segments.toString(), JPEG.SOF0, segments.get(23).marker());
|
||||
assertEquals(segments.toString(), null, segments.get(23).identifier());
|
||||
assertEquals(segments.toString(), JPEG.SOS, segments.get(segments.size() - 1).marker());
|
||||
assertEquals(JPEG.SOF0, segments.get(23).marker(), segments.toString());
|
||||
assertEquals(null, segments.get(23).identifier(), segments.toString());
|
||||
assertEquals(JPEG.SOS, segments.get(segments.size() - 1).marker(), segments.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-3
@@ -33,15 +33,14 @@ package com.twelvemonkeys.imageio.metadata.psd;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.MetadataReaderAbstractTest;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* PhotoshopReaderTest
|
||||
|
||||
+2
-4
@@ -34,8 +34,6 @@ import com.twelvemonkeys.imageio.metadata.*;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.io.FastByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.ImageOutputStreamImpl;
|
||||
@@ -47,8 +45,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* TIFFWriterTest
|
||||
|
||||
+11
-13
@@ -2,15 +2,13 @@ package com.twelvemonkeys.imageio.metadata.tiff;
|
||||
|
||||
import com.twelvemonkeys.io.FastByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* HalfTest.
|
||||
@@ -39,7 +37,7 @@ public class HalfTest {
|
||||
@Test
|
||||
public void testExactEncoding() {
|
||||
for (short half = -2048; half < 2048; half++) {
|
||||
assertEquals(String.valueOf(half), half, Half.shortBitsToFloat(Half.floatToShortBits(half)), 0);
|
||||
assertEquals(half, Half.shortBitsToFloat(Half.floatToShortBits(half)), 0, String.valueOf(half));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +101,14 @@ public class HalfTest {
|
||||
// TODO: More... But we just delegate to Float.toString, so no worries... :-)
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testParseHalfNull() {
|
||||
Half.parseHalf(null);
|
||||
assertThrows(NullPointerException.class, () -> Half.parseHalf(null));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testParseHalfBad() {
|
||||
Half.parseHalf("foo");
|
||||
assertThrows(NumberFormatException.class, () -> Half.parseHalf("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,14 +118,14 @@ public class HalfTest {
|
||||
// TODO: More... But we just delegate to Float.valueOf, so no worries... :-)
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testValueOfNull() {
|
||||
Half.valueOf(null);
|
||||
assertThrows(NullPointerException.class, () -> Half.valueOf(null));
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testValueOfBad() {
|
||||
Half.valueOf("foo");
|
||||
assertThrows(NumberFormatException.class, () -> Half.valueOf("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
-11
@@ -30,9 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata.tiff;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* RationalTest
|
||||
@@ -42,20 +41,20 @@ import static org.junit.Assert.assertEquals;
|
||||
* @version $Id: RationalTest.java,v 1.0 Nov 18, 2009 3:23:17 PM haraldk Exp$
|
||||
*/
|
||||
public class RationalTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testZeroDenominator() {
|
||||
new Rational(1, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(1, 0));
|
||||
}
|
||||
|
||||
// TODO: Find a solution to this problem, as we should be able to work with it...
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testLongMinValueNumerator() {
|
||||
new Rational(Long.MIN_VALUE, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(Long.MIN_VALUE, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testLongMinValueDenominator() {
|
||||
new Rational(1, Long.MIN_VALUE);
|
||||
assertThrows(IllegalArgumentException.class, () -> new Rational(1, Long.MIN_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,8 +161,8 @@ public class RationalTest {
|
||||
assertEquals(Rational.ZERO, new Rational(0, 386).divides(x));
|
||||
}
|
||||
|
||||
@Test(expected = ArithmeticException.class)
|
||||
@Test
|
||||
public void testDivideZero() {
|
||||
new Rational(3037141, 3247033).divides(new Rational(0, 1));
|
||||
assertThrows(ArithmeticException.class, () -> new Rational(3037141, 3247033).divides(new Rational(0, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -32,7 +32,10 @@ package com.twelvemonkeys.imageio.metadata.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.EntryAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* TIFFEntryTest
|
||||
@@ -51,9 +54,9 @@ public class TIFFEntryTest extends EntryAbstractTest {
|
||||
return new TIFFEntry(identifier, (short) type, value);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEXIFEntryIllegalType() {
|
||||
createEXIFEntry(0, null, -1);
|
||||
assertThrows(IllegalArgumentException.class, () -> createEXIFEntry(0, null, -1));
|
||||
}
|
||||
|
||||
// TODO: TIFF/EXIF specific tests
|
||||
|
||||
+49
-41
@@ -32,17 +32,17 @@ package com.twelvemonkeys.imageio.metadata.tiff;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
@@ -86,14 +86,16 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
assertEquals(exif.size(), exif.getDirectory(0).size() + exif.getDirectory(1).size());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testDirectoryOutOfBounds() throws IOException {
|
||||
InputStream data = getData();
|
||||
|
||||
CompoundDirectory exif = (CompoundDirectory) createReader().read(ImageIO.createImageInputStream(data));
|
||||
|
||||
assertEquals(2, exif.directoryCount());
|
||||
assertNotNull(exif.getDirectory(exif.directoryCount()));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
exif.getDirectory(exif.directoryCount());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -365,21 +367,23 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 200)
|
||||
@Test
|
||||
public void testReadCyclicExifWithoutLoopOrOOME() throws IOException {
|
||||
// This EXIF segment has an interesting bug...
|
||||
// The bits per sample value (0x 0008 0008 0008) overwrites half the IFD1 link offset (should be 0x00000000),
|
||||
// effectively making it a loop back to the IFD0 at offset 0x0000008...
|
||||
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/exif-loop.bin"))) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(12, directory.getDirectory(0).size());
|
||||
assertEquals("Polarr Photo Editor", directory.getDirectory(0).getEntryById(TIFF.TAG_SOFTWARE).getValue());
|
||||
assertEquals("2019:02:27 09:22:59", directory.getDirectory(0).getEntryById(TIFF.TAG_DATE_TIME).getValueAsString());
|
||||
}
|
||||
assertTimeoutPreemptively(Duration.ofMillis(200), () -> {
|
||||
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/exif-loop.bin"))) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(12, directory.getDirectory(0).size());
|
||||
assertEquals("Polarr Photo Editor", directory.getDirectory(0).getEntryById(TIFF.TAG_SOFTWARE).getValue());
|
||||
assertEquals("2019:02:27 09:22:59", directory.getDirectory(0).getEntryById(TIFF.TAG_DATE_TIME).getValueAsString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 100)
|
||||
@Test
|
||||
public void testIFDLoop() throws IOException {
|
||||
byte[] looping = new byte[] {
|
||||
'M', 'M', 0, 42,
|
||||
@@ -391,16 +395,17 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
0, 0, 0, 0, //
|
||||
0, 0, 0, 8, // IFD1 pointer
|
||||
};
|
||||
assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 100)
|
||||
@Test
|
||||
public void testIFDLoopNested() throws IOException {
|
||||
byte[] looping = new byte[] {
|
||||
'M', 'M', 0, 42,
|
||||
@@ -412,16 +417,17 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
0, 0, 0, 8, // sub IFD pointer -> IFD0
|
||||
0, 0, 0, 0, // End of IFD chain
|
||||
};
|
||||
assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 100)
|
||||
@Test
|
||||
public void testSubIFDLoop() throws IOException {
|
||||
byte[] looping = new byte[] {
|
||||
'M', 'M', 0, 42,
|
||||
@@ -439,16 +445,17 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
0, 0, 0, 1, // count
|
||||
0, 0, 0, 26, // sub IFD pointer -> sub IFD
|
||||
};
|
||||
assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(timeout = 100)
|
||||
@Test
|
||||
public void testSubIFDLoopNested() throws IOException {
|
||||
byte[] looping = new byte[] {
|
||||
'M', 'M', 0, 42,
|
||||
@@ -466,12 +473,13 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
0, 0, 0, 1, // count
|
||||
0, 0, 0, 8, // sub IFD pointer -> IFD0
|
||||
};
|
||||
assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
try (ImageInputStream stream = new ByteArrayImageInputStream(looping)) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
assertEquals(1, directory.directoryCount());
|
||||
assertEquals(1, directory.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,7 +34,6 @@ import com.twelvemonkeys.imageio.metadata.*;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.io.FastByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
@@ -47,7 +46,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* TIFFWriterTest
|
||||
@@ -272,7 +272,7 @@ public class TIFFWriterTest extends MetadataWriterAbstractTest {
|
||||
Directory read = new TIFFReader().read(new ByteArrayImageInputStream(data));
|
||||
|
||||
assertNotNull(read.getEntryById(TIFF.TAG_SOFTWARE));
|
||||
assertTrue("value not an string array", read.getEntryById(TIFF.TAG_SOFTWARE).getValue() instanceof String[]);
|
||||
assertTrue(read.getEntryById(TIFF.TAG_SOFTWARE).getValue() instanceof String[], "value not an string array");
|
||||
assertArrayEquals(strings, (String[]) read.getEntryById(TIFF.TAG_SOFTWARE).getValue());
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -32,11 +32,10 @@ package com.twelvemonkeys.imageio.metadata.xmp;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.EntryAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* XMPEntryTest
|
||||
|
||||
+18
-16
@@ -32,9 +32,9 @@ package com.twelvemonkeys.imageio.metadata.xmp;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -45,6 +45,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -54,7 +55,6 @@ import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.DirectImageInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
@@ -494,24 +494,26 @@ public class XMPReaderTest extends MetadataReaderAbstractTest {
|
||||
assertThat(exif.getEntryById("http://ns.adobe.com/exif/1.0/NativeDigest"), hasValue("36864,40960,40961,37121,37122,40962,40963,37510,40964,36867,36868,33434,33437,34850,34852,34855,34856,37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37396,41483,41484,41486,41487,41488,41492,41493,41495,41728,41729,41730,41985,41986,41987,41988,41989,41990,41991,41992,41993,41994,41995,41996,42016,0,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,30;A7F21D25E2C562F152B2C4ECC9E534DA"));
|
||||
}
|
||||
|
||||
@Test(timeout = 2500L)
|
||||
@Test
|
||||
public void testNoExternalRequest() throws Exception {
|
||||
String maliciousXML = resourceAsString("/xmp/xmp-jpeg-xxe.xml");
|
||||
assertTimeoutPreemptively(Duration.ofMillis(2500L), () -> {
|
||||
String maliciousXML = resourceAsString("/xmp/xmp-jpeg-xxe.xml");
|
||||
|
||||
try (HTTPServer server = new HTTPServer()) {
|
||||
String dynamicXML = maliciousXML.replace("http://localhost:7777/", "http://localhost:" + server.port() + "/");
|
||||
try (HTTPServer server = new HTTPServer()) {
|
||||
String dynamicXML = maliciousXML.replace("http://localhost:7777/", "http://localhost:" + server.port() + "/");
|
||||
|
||||
try (DirectImageInputStream input = new DirectImageInputStream(new ByteArrayInputStream(dynamicXML.getBytes(StandardCharsets.UTF_8)));) {
|
||||
createReader().read(input);
|
||||
} catch (IOException ioe) {
|
||||
if (ioe.getMessage().contains("501")) {
|
||||
throw new AssertionError("Reading should not cause external requests", ioe);
|
||||
try (DirectImageInputStream input = new DirectImageInputStream(new ByteArrayInputStream(dynamicXML.getBytes(StandardCharsets.UTF_8)));) {
|
||||
createReader().read(input);
|
||||
} catch (IOException ioe) {
|
||||
if (ioe.getMessage().contains("501")) {
|
||||
throw new AssertionError("Reading should not cause external requests", ioe);
|
||||
}
|
||||
|
||||
// Any other exception is a bug (but might happen if the parser does not support certain features)
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
// Any other exception is a bug (but might happen if the parser does not support certain features)
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String resourceAsString(String name) throws IOException {
|
||||
|
||||
+2
-3
@@ -30,15 +30,14 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata.xmp;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* XMPScannerTestCase
|
||||
|
||||
+2
-4
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.plugins.dcx;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -44,8 +42,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* DCXImageReaderTest
|
||||
|
||||
+3
-4
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.plugins.pcx;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
@@ -45,8 +43,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.*;
|
||||
|
||||
|
||||
/**
|
||||
* PCXImageReaderTest
|
||||
|
||||
+5
-5
@@ -34,9 +34,6 @@ import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStreamSpi;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -47,8 +44,11 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.twelvemonkeys.imageio.plugins.pict.PICTImageReaderSpi.isOtherFormat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ICOImageReaderTestCase
|
||||
@@ -142,7 +142,7 @@ public class PICTImageReaderTest extends ImageReaderAbstractTest<PICTImageReader
|
||||
assertTrue(isOtherFormat(new ByteArrayImageInputStream(new byte[] {'M', 'M', 0, 43, 0, 0, 0, 0})));
|
||||
}
|
||||
|
||||
@Ignore("Known issue")
|
||||
@Disabled("Known issue")
|
||||
@Test
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
|
||||
+8
-9
@@ -33,8 +33,6 @@ package com.twelvemonkeys.imageio.plugins.pict;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
@@ -48,7 +46,8 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PICTImageWriterTest
|
||||
@@ -100,7 +99,7 @@ public class PICTImageWriterTest extends ImageWriterAbstractTest<PICTImageWriter
|
||||
stream.close(); // Force data to be written
|
||||
}
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
assertTrue(buffer.size() > 0, "No image data written");
|
||||
|
||||
ImageInputStream input = new ByteArrayImageInputStream(buffer.toByteArray());
|
||||
BufferedImage written = ImageIO.read(input);
|
||||
@@ -124,13 +123,13 @@ public class PICTImageWriterTest extends ImageWriterAbstractTest<PICTImageWriter
|
||||
if (original.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_GRAY) {
|
||||
// NOTE: For some reason, gray data seems to be one step off...
|
||||
// ...and vary with different backing CMSs... :-(
|
||||
assertTrue(String.format("original 0x%08x != gray! (%d,%d)", originalRGB, x, y), expectedR == expectedG && expectedG == expectedB);
|
||||
assertTrue(String.format("written 0x%08x != gray! (%d,%d)", writtenRGB, x, y), actualR == actualG && actualG == actualB);
|
||||
assertTrue(expectedR == expectedG && expectedG == expectedB, String.format("original 0x%08x != gray! (%d,%d)", originalRGB, x, y));
|
||||
assertTrue(actualR == actualG && actualG == actualB, String.format("written 0x%08x != gray! (%d,%d)", writtenRGB, x, y));
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("Test data %d R(%d,%d)", i, x, y), expectedR, actualR);
|
||||
assertEquals(String.format("Test data %d G(%d,%d)", i, x, y), expectedG, actualG);
|
||||
assertEquals(String.format("Test data %d B(%d,%d)", i, x, y), expectedB, actualB);
|
||||
assertEquals(expectedR, actualR, String.format("Test data %d R(%d,%d)", i, x, y));
|
||||
assertEquals(expectedG, actualG, String.format("Test data %d G(%d,%d)", i, x, y));
|
||||
assertEquals(expectedB, actualB, String.format("Test data %d B(%d,%d)", i, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -2,11 +2,10 @@ package com.twelvemonkeys.imageio.plugins.pict;
|
||||
|
||||
import com.twelvemonkeys.imageio.plugins.pict.QuickTime.ImageDesc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* QTBMPDecompressorTest.
|
||||
|
||||
+2
-3
@@ -2,9 +2,8 @@ package com.twelvemonkeys.imageio.plugins.pict;
|
||||
|
||||
import com.twelvemonkeys.imageio.plugins.pict.QuickTime.ImageDesc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* QTBMPDecompressorTest.
|
||||
|
||||
+2
-3
@@ -2,9 +2,8 @@ package com.twelvemonkeys.imageio.plugins.pict;
|
||||
|
||||
import com.twelvemonkeys.imageio.plugins.pict.QuickTime.ImageDesc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* QTBMPDecompressorTest.
|
||||
|
||||
+3
-3
@@ -10,8 +10,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
/**
|
||||
* PNTGImageReaderTest.
|
||||
@@ -59,7 +59,7 @@ public class PNTGImageReaderTest extends ImageReaderAbstractTest<PNTGImageReader
|
||||
for (TestData data : testData) {
|
||||
ImageInputStream stream = data.getInputStream();
|
||||
assertNotNull(stream);
|
||||
assertTrue("Provider is expected to be able to decode data: " + data, provider.canDecodeInput(stream));
|
||||
assertTrue(provider.canDecodeInput(stream), "Provider is expected to be able to decode data: " + data);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.twelvemonkeys.imageio.plugins.pntg;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.image.*;
|
||||
|
||||
|
||||
+3
-3
@@ -30,15 +30,15 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.pnm;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfoTest.assertClassExists;
|
||||
import static com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfoTest.assertClassesExist;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PAMImageReaderSpiTest.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user