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:
Vyshak Puthusseri
2024-11-12 14:43:15 +05:30
committed by GitHub
parent a67fdd4b80
commit 543acce8a3
194 changed files with 2554 additions and 3086 deletions
@@ -33,8 +33,8 @@ package com.twelvemonkeys.imageio.plugins.bmp;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import com.twelvemonkeys.xml.XMLSerializer;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.mockito.InOrder;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -59,8 +59,8 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeNoException;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
@@ -204,11 +204,11 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
}
}
assertTrue("ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes", rawFound);
assertTrue(rawFound, "ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes");
}
}
@Ignore("Known issue: Subsampled reading is currently broken")
@Disabled("Known issue: Subsampled reading is currently broken")
@Test
public void testReadWithSubsampleParamPixelsIndexed8() throws IOException {
ImageReader reader = createReader();
@@ -235,7 +235,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
// TODO: 1. Subsampling is currently broken, should fix it.
// 2. BMPs are (normally) stored bottom/up, meaning y subsampling offsets will differ from normal
// subsampling of the same data with an offset... Should we deal with this in the reader? Yes?
@Ignore("Known issue: Subsampled reading is currently broken")
@Disabled("Known issue: Subsampled reading is currently broken")
@Test
@Override
public void testReadWithSubsampleParamPixels() throws IOException {
@@ -260,7 +260,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
assertSubsampledImageDataEquals("Subsampled image data does not match expected", image, subsampled, param);
}
@Test(expected = IIOException.class)
@Test
public void testReadCorruptCausesIIOException() throws IOException {
// See https://bugs.openjdk.java.net/browse/JDK-8066904
// NullPointerException when calling ImageIO.read(InputStream) with corrupt BMP
@@ -268,7 +268,9 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/broken-bmp/corrupted-bmp.bmp")));
reader.read(0);
assertThrows(IIOException.class, () -> {
reader.read(0);
});
}
finally {
reader.dispose();
@@ -331,7 +333,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
catch (Exception e) {
e.printStackTrace();
// Ignore this test if not on an Oracle JRE (com.sun...BMPImageReader not available)
assumeNoException(e);
assumeTrue(false, "Skipping test: BMPImageReaderSpi not available on non-Oracle JREs");
return;
}
@@ -383,7 +385,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
new XMLSerializer(expected, "UTF-8").serialize(expectedTree, false);
new XMLSerializer(actual, "UTF-8").serialize(actualTree, false);
assertEquals(e.getMessage(), new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8));
assertEquals(new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8), e.getMessage());
throw e;
}
@@ -392,24 +394,24 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
}
private void assertNodeEquals(final String message, final Node expected, final Node actual) {
assertEquals(message + " class differs", expected.getClass(), actual.getClass());
assertEquals(expected.getClass(), actual.getClass(), message + " class differs");
if (!excludeEqualValueTest(expected)) {
assertEquals(message, expected.getNodeValue(), actual.getNodeValue());
assertEquals(expected.getNodeValue(), actual.getNodeValue(), message);
if (expected instanceof IIOMetadataNode) {
IIOMetadataNode expectedIIO = (IIOMetadataNode) expected;
IIOMetadataNode actualIIO = (IIOMetadataNode) actual;
assertEquals(message, expectedIIO.getUserObject(), actualIIO.getUserObject());
assertEquals(expectedIIO.getUserObject(), actualIIO.getUserObject(), message);
}
}
NodeList expectedChildNodes = expected.getChildNodes();
NodeList actualChildNodes = actual.getChildNodes();
assertTrue(message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes),
expectedChildNodes.getLength() <= actualChildNodes.getLength());
assertTrue(expectedChildNodes.getLength() <= actualChildNodes.getLength(),
message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes));
for (int i = 0; i < expectedChildNodes.getLength(); i++) {
Node expectedChild = expectedChildNodes.item(i);
@@ -423,7 +425,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
}
}
assertEquals(message + " node name differs", expectedChild.getLocalName(), actualChild.getLocalName());
assertEquals(expectedChild.getLocalName(), actualChild.getLocalName(), message + " node name differs");
assertNodeEquals(message + "/" + expectedChild.getLocalName(), expectedChild, actualChild);
}
}
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.ImageReadParam;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
@@ -44,7 +41,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* CURImageReaderTest
@@ -93,16 +92,16 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
if (hotspot != Image.UndefinedProperty || pParam == null) {
// Typically never happens, because of weirdness with UndefinedProperty
assertNotNull("Hotspot for cursor not present", hotspot);
assertNotNull(hotspot, "Hotspot for cursor not present");
// Image weirdness
assertNotSame("Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)", Image.UndefinedProperty, hotspot);
assertNotSame(Image.UndefinedProperty, hotspot, "Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)");
assertTrue(String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()), hotspot instanceof Point);
assertTrue(hotspot instanceof Point, String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()));
assertEquals(pExpected, hotspot);
}
assertNotNull("Hotspot for cursor not present", reader.getHotSpot(0));
assertNotNull(reader.getHotSpot(0), "Hotspot for cursor not present");
assertEquals(pExpected, reader.getHotSpot(0));
}
@@ -141,14 +140,14 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
// TODO: Test cursor is transparent
@Test
@Ignore("Known issue")
@Disabled("Known issue")
@Override
public void testNotBadCaching() throws IOException {
super.testNotBadCaching();
}
@Test
@Ignore("Known issue: Subsampled reading currently not supported")
@Disabled("Known issue: Subsampled reading currently not supported")
@Override
public void testReadWithSubsampleParamPixels() throws IOException {
super.testReadWithSubsampleParamPixels();
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
import java.io.IOException;
@@ -42,6 +39,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* ICOImageReaderTest
*
@@ -98,14 +98,14 @@ public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader>
}
@Test
@Ignore("Known issue")
@Disabled("Known issue")
@Override
public void testNotBadCaching() throws IOException {
super.testNotBadCaching();
}
@Test
@Ignore("Known issue: Subsampled reading currently not supported")
@Disabled("Known issue: Subsampled reading currently not supported")
@Override
public void testReadWithSubsampleParamPixels() throws IOException {
super.testReadWithSubsampleParamPixels();
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
import com.twelvemonkeys.io.enc.Decoder;
import com.twelvemonkeys.io.enc.DecoderStream;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RLE4DecoderTest {
@@ -82,8 +81,8 @@ public class RLE4DecoderTest {
int r = channel.read(plain);
plain.rewind();
assertEquals("Difference at line " + i, r, d);
assertArrayEquals("Difference at line " + i, plain.array(), decoded.array());
assertEquals(r, d, "Difference at line " + i);
assertArrayEquals(plain.array(), decoded.array(), "Difference at line " + i);
}
}
@@ -104,7 +103,7 @@ public class RLE4DecoderTest {
int pos = 0;
while (true) {
int expected = plainSream.read();
assertEquals("Differs at " + pos, expected, decoded.read());
assertEquals(expected, decoded.read(), "Differs at " + pos);
if (expected < 0) {
break;
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
import com.twelvemonkeys.io.enc.Decoder;
import com.twelvemonkeys.io.enc.DecoderStream;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RLE8DecoderTest {
@@ -108,7 +107,7 @@ public class RLE8DecoderTest {
while (true) {
int expected = plainSream.read();
assertEquals("Differs at " + pos, expected, decoded.read());
assertEquals(expected, decoded.read(), "Differs at " + pos);
if (expected < 0) {
break;