mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -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
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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...
|
||||
|
@@ -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,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;
|
||||
|
@@ -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 {
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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.
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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,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))) {
|
||||
|
@@ -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,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();
|
||||
|
@@ -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
|
||||
|
@@ -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());
|
||||
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user