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
@@ -2,8 +2,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -15,8 +13,9 @@ import javax.imageio.metadata.IIOMetadataNode;
import java.awt.image.*;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static java.awt.image.BufferedImage.*;
import static org.junit.Assert.*;
public class IFFImageMetadataTest {
@@ -42,20 +41,14 @@ public class IFFImageMetadataTest {
// Other formats
assertNull(metadata.getNativeMetadataFormatName());
assertNull(metadata.getExtraMetadataFormatNames());
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() {
metadata.getAsTree("com_foo_bar_1.0");
}
assertThrows(IllegalArgumentException.class, () -> {
metadata.getAsTree("com_foo_bar_1.0");
});
// Read-only
assertTrue(metadata.isReadOnly());
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
metadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName));
}
assertThrows(IllegalStateException.class, () -> {
metadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName));
});
}
@@ -32,8 +32,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
import org.junit.Test;
import javax.imageio.ImageIO;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
@@ -45,8 +43,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* IFFImageReaderTestCase
*
@@ -144,9 +142,9 @@ public class IFFImageReaderTest extends ImageReaderAbstractTest<IFFImageReader>
for (int i = 0; i < 32; i++) {
// Make sure the color model is really EHB
try {
assertEquals("red", (reds[i] & 0xff) / 2, reds[i + 32] & 0xff);
assertEquals("blue", (blues[i] & 0xff) / 2, blues[i + 32] & 0xff);
assertEquals("green", (greens[i] & 0xff) / 2, greens[i + 32] & 0xff);
assertEquals((reds[i] & 0xff) / 2, reds[i + 32] & 0xff, "red");
assertEquals((blues[i] & 0xff) / 2, blues[i + 32] & 0xff, "blue");
assertEquals((greens[i] & 0xff) / 2, greens[i + 32] & 0xff, "green");
}
catch (AssertionError err) {
throw new AssertionError("Color " + i + " " + err.getMessage(), err);
@@ -33,8 +33,6 @@ package com.twelvemonkeys.imageio.plugins.iff;
import com.twelvemonkeys.image.MonochromeColorModel;
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTest;
import org.junit.Test;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.spi.ImageWriterSpi;
@@ -49,8 +47,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* JPEG2000ImageWriterTest
*
@@ -104,7 +102,7 @@ public class IFFImageWriterTest extends ImageWriterAbstractTest<IFFImageWriter>
stream.close(); // Force data to be written
}
assertTrue("No image data written", buffer.size() > 0);
assertTrue(buffer.size() > 0, "No image data written");
ImageInputStream input = ImageIO.createImageInputStream(new ByteArrayInputStream(buffer.toByteArray()));
BufferedImage written = ImageIO.read(input);
@@ -129,14 +127,14 @@ public class IFFImageWriterTest extends ImageWriterAbstractTest<IFFImageWriter>
if (expected.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_GRAY) {
// NOTE: For some reason, gray data seems to be one step off...
assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000, 0x10000);
assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00, 0x100);
assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff, 0x1);
assertEquals(expectedRGB & 0xff0000, actualRGB & 0xff0000, 0x10000, "R(" + x + "," + y + ")");
assertEquals(expectedRGB & 0x00ff00, actualRGB & 0x00ff00, 0x100, "G(" + x + "," + y + ")");
assertEquals(expectedRGB & 0x0000ff, actualRGB & 0x0000ff, 0x1, "B(" + x + "," + y + ")");
}
else {
assertEquals("R(" + x + "," + y + ")", expectedRGB & 0xff0000, actualRGB & 0xff0000);
assertEquals("G(" + x + "," + y + ")", expectedRGB & 0x00ff00, actualRGB & 0x00ff00);
assertEquals("B(" + x + "," + y + ")", expectedRGB & 0x0000ff, actualRGB & 0x0000ff);
assertEquals(expectedRGB & 0xff0000, actualRGB & 0xff0000, "R(" + x + "," + y + ")");
assertEquals(expectedRGB & 0x00ff00, actualRGB & 0x00ff00, "G(" + x + "," + y + ")");
assertEquals(expectedRGB & 0x0000ff, actualRGB & 0x0000ff, "B(" + x + "," + y + ")");
}
}
}
@@ -5,15 +5,13 @@ import com.twelvemonkeys.io.enc.Decoder;
import com.twelvemonkeys.io.enc.DecoderAbstractTest;
import com.twelvemonkeys.io.enc.Encoder;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* RGB8RLEDecoderTest.
@@ -42,36 +40,39 @@ public class RGB8RLEDecoderTest extends DecoderAbstractTest {
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[0]);
int count = decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
assertEquals("Should not be able to read any bytes", 0, count);
assertEquals(0, count, "Should not be able to read any bytes");
}
@Test(expected = EOFException.class)
@Test
public final void testDecodePartial() throws IOException {
Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0});
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
fail("Should not be able to read any bytes");
assertThrows(EOFException.class, () -> {
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
}, "Should not be able to read any bytes");
}
@Test(expected = EOFException.class)
@Test
public final void testDecodePartialToo() throws IOException {
Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0, 0, 0, 1, 0, 0});
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
fail("Should not be able to read any bytes");
assertThrows(EOFException.class, () -> {
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
}, "Should not be able to read any bytes");
}
@Test(expected = DecodeException.class)
@Test
public final void testDecodeZeroRun() throws IOException {
// The spec says that 0-runs should be used to signal that the run is > 127,
// and contained in the next byte, however, this is not used in practise and not supported.
Decoder decoder = createDecoder();
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[] {0, 0, 0, 0});
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
fail("Should not be able to read any bytes");
assertThrows(DecodeException.class, () -> {
decoder.decode(bytes, ByteBuffer.allocate(BUFFER_SIZE));
}, "Should not be able to read any bytes");
}
@Test