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

View File

@@ -31,9 +31,7 @@
package com.twelvemonkeys.image;
import static java.lang.Math.min;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
@@ -49,7 +47,7 @@ import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* AffineTransformOpTest.
@@ -146,12 +144,12 @@ public class AffineTransformOpTest {
BufferedImage jreResult = jreOp.filter(image, null);
BufferedImage tmResult = tmOp.filter(image, null);
assertNotNull("No result!", tmResult);
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
assertNotNull(tmResult, "No result!");
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
}
}
@@ -164,7 +162,7 @@ public class AffineTransformOpTest {
BufferedImage image = spec.createBufferedImage(width, height);
BufferedImage tmResult = tmOp.filter(image, null);
assertNotNull("No result!", tmResult);
assertNotNull(tmResult, "No result!");
BufferedImage jreResult = null;
@@ -176,18 +174,18 @@ public class AffineTransformOpTest {
}
if (jreResult != null) {
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
}
else {
assertEquals("Bad type", spec.getBufferedImageType(), tmResult.getType());
assertEquals("Incorrect color model", spec.getColorModel(), tmResult.getColorModel());
assertEquals(spec.getBufferedImageType(), tmResult.getType(), "Bad type");
assertEquals(spec.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
assertEquals("Incorrect width", height, tmResult.getWidth());
assertEquals("Incorrect height", width, tmResult.getHeight());
assertEquals(height, tmResult.getWidth(), "Incorrect width");
assertEquals(width, tmResult.getHeight(), "Incorrect height");
}
}
}
@@ -236,12 +234,12 @@ public class AffineTransformOpTest {
}
if (jreResult != null) {
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
}
else {
assertEquals("Incorrect width", height, tmResult.getWidth());
assertEquals("Incorrect height", width, tmResult.getHeight());
assertEquals(height, tmResult.getWidth(), "Incorrect width");
assertEquals(width, tmResult.getHeight(), "Incorrect height");
}
}
}
@@ -277,12 +275,12 @@ public class AffineTransformOpTest {
}
if (jreResult != null) {
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
}
else {
assertEquals("Incorrect width", height, tmResult.getWidth());
assertEquals("Incorrect height", width, tmResult.getHeight());
assertEquals(height, tmResult.getWidth(), "Incorrect width");
assertEquals(width, tmResult.getHeight(), "Incorrect height");
}
}
}

View File

@@ -30,17 +30,16 @@
package com.twelvemonkeys.image;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.awt.*;
import java.awt.color.*;
import java.awt.image.*;
import java.net.URL;
import java.time.Duration;
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.*;
/**
* BufferedImageFactoryTestCase
@@ -50,50 +49,58 @@ import static org.junit.Assert.assertTrue;
* @version $Id: BufferedImageFactoryTestCase.java,v 1.0 May 7, 2010 12:40:08 PM haraldk Exp$
*/
public class BufferedImageFactoryTest {
@Test(expected = IllegalArgumentException.class)
@Test
public void testCreateNullImage() {
new BufferedImageFactory((Image) null);
assertThrows(IllegalArgumentException.class, () -> {
new BufferedImageFactory((Image) null);
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testCreateNullProducer() {
new BufferedImageFactory((ImageProducer) null);
assertThrows(IllegalArgumentException.class, () -> {
new BufferedImageFactory((ImageProducer) null);
});
}
// NPE in Toolkit, ok
@Test(expected = RuntimeException.class)
@Test
public void testGetBufferedImageErrorSourceByteArray() {
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
new BufferedImageFactory(source);
assertThrows(RuntimeException.class, () -> {
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
new BufferedImageFactory(source);
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testGetBufferedImageErrorSourceImageProducer() {
Image source = Toolkit.getDefaultToolkit().createImage((ImageProducer) null);
new BufferedImageFactory(source);
assertThrows(IllegalArgumentException.class, () -> {
new BufferedImageFactory(source);
});
}
// TODO: This is a quite serious bug, however, the bug is in the Toolkit, allowing such images in the first place...
// In any case, there's not much we can do, except until someone is bored and kills the app/thread... :-P
@Ignore("Bug in Toolkit")
@Test(timeout = 1000, expected = ImageConversionException.class)
@Disabled("Bug in Toolkit")
@Test
public void testGetBufferedImageErrorSourceString() {
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
BufferedImageFactory factory = new BufferedImageFactory(source);
factory.getBufferedImage();
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
BufferedImageFactory factory = new BufferedImageFactory(source);
assertThrows(ImageConversionException.class, factory::getBufferedImage);
});
}
// This is a little random, and it would be nicer if we could throw an IllegalArgumentException on create.
// Unfortunately, the API doesn't allow this...
@Test(timeout = 1000, expected = ImageConversionException.class)
@Test
public void testGetBufferedImageErrorSourceURL() {
Image source = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/META-INF/MANIFEST.MF"));
BufferedImageFactory factory = new BufferedImageFactory(source);
factory.getBufferedImage();
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
BufferedImageFactory factory = new BufferedImageFactory(source);
assertThrows(ImageConversionException.class, factory::getBufferedImage);
});
}
@Test
@@ -165,7 +172,7 @@ public class BufferedImageFactoryTest {
assertEquals(3, colorModel.getNumColorComponents());
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
assertTrue(colorModel instanceof IndexColorModel);
assertInstanceOf(IndexColorModel.class, colorModel);
assertTrue(colorModel.hasAlpha());
assertEquals(4, colorModel.getNumComponents());
@@ -196,7 +203,7 @@ public class BufferedImageFactoryTest {
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(x * 2, y * 2), image.getRGB(x, y));
assertEquals(original.getRGB(x * 2, y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
}
}
}
@@ -219,7 +226,7 @@ public class BufferedImageFactoryTest {
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x, 40 + y), image.getRGB(x, y));
assertEquals(original.getRGB(40 + x, 40 + y), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
}
}
}
@@ -243,7 +250,7 @@ public class BufferedImageFactoryTest {
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y));
assertEquals(original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
}
}
}

View File

@@ -30,7 +30,7 @@
package com.twelvemonkeys.image;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.imageio.ImageIO;
import java.awt.*;
@@ -39,7 +39,7 @@ import java.awt.image.IndexColorModel;
import java.awt.image.RenderedImage;
import java.io.InputStream;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class ImageUtilTest {
@@ -116,8 +116,8 @@ public class ImageUtilTest {
public void testImageIsNotBufferedImage() {
// Should not be a buffered image
assertFalse(
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too.",
scaled instanceof BufferedImage
scaled instanceof BufferedImage,
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too."
);
}
@@ -247,7 +247,7 @@ public class ImageUtilTest {
if (original != notContrasted) { // Don't care to test if images are same
for (int y = 0; y < original.getHeight(); y++) {
for (int x = 0; x < original.getWidth(); x++) {
assertEquals("0 constrast should not change image", original.getRGB(x, y), notContrasted.getRGB(x, y));
assertEquals(original.getRGB(x, y), notContrasted.getRGB(x, y), "0 constrast should not change image");
}
}
}
@@ -275,24 +275,24 @@ public class ImageUtilTest {
// RED
if (oR < 127) {
assertTrue("Contrast should be decreased or same", oR >= cR && cR >= dR);
assertTrue(oR >= cR && cR >= dR, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oR <= cR && cR <= dR);
assertTrue(oR <= cR && cR <= dR, "Contrast should be increased or same");
}
// GREEN
if (oG < 127) {
assertTrue("Contrast should be decreased or same", oG >= cG && cG >= dG);
assertTrue(oG >= cG && cG >= dG, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oG <= cG && cG <= dG);
assertTrue(oG <= cG && cG <= dG, "Contrast should be increased or same");
}
// BLUE
if (oB < 127) {
assertTrue("Contrast should be decreased or same", oB >= cB && cB >= dB);
assertTrue(oB >= cB && cB >= dB, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oB <= cB && cB <= dB);
assertTrue(oB <= cB && cB <= dB, "Contrast should be increased or same");
}
}
}
@@ -304,9 +304,9 @@ public class ImageUtilTest {
int r = rgb >> 16 & 0xFF;
int g = rgb >> 8 & 0xFF;
int b = rgb & 0xFF;
assertTrue("Max contrast should only produce primary colors", r == 0 || r == 255);
assertTrue("Max contrast should only produce primary colors", g == 0 || g == 255);
assertTrue("Max contrast should only produce primary colors", b == 0 || b == 255);
assertTrue(r == 0 || r == 255, "Max contrast should only produce primary colors");
assertTrue(g == 0 || g == 255, "Max contrast should only produce primary colors");
assertTrue(b == 0 || b == 255, "Max contrast should only produce primary colors");
}
}
@@ -327,24 +327,24 @@ public class ImageUtilTest {
// RED
if (oR >= 127) {
assertTrue("Contrast should be decreased or same", oR >= cR);
assertTrue(oR >= cR, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oR <= cR);
assertTrue(oR <= cR, "Contrast should be increased or same");
}
// GREEN
if (oG >= 127) {
assertTrue("Contrast should be decreased or same", oG >= cG);
assertTrue(oG >= cG, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oG <= cG);
assertTrue(oG <= cG, "Contrast should be increased or same");
}
// BLUE
if (oB >= 127) {
assertTrue("Contrast should be decreased or same", oB >= cB);
assertTrue(oB >= cB, "Contrast should be decreased or same");
}
else {
assertTrue("Contrast should be increased or same", oB <= cB);
assertTrue(oB <= cB, "Contrast should be increased or same");
}
}
}
@@ -357,7 +357,7 @@ public class ImageUtilTest {
int r = rgb >> 16 & 0xFF;
int g = rgb >> 8 & 0xFF;
int b = rgb & 0xFF;
assertTrue("Minimum contrast should be all gray", r == 127 && g == 127 && b == 127);
assertTrue(r == 127 && g == 127 && b == 127, "Minimum contrast should be all gray");
}
}
@@ -400,7 +400,7 @@ public class ImageUtilTest {
if (original != notSharpened) { // Don't care to test if images are same
for (int y = 0; y < original.getHeight(); y++) {
for (int x = 0; x < original.getWidth(); x++) {
assertEquals("0 sharpen should not change image", original.getRGB(x, y), notSharpened.getRGB(x, y));
assertEquals(original.getRGB(x, y), notSharpened.getRGB(x, y), "0 sharpen should not change image");
}
}
}
@@ -446,13 +446,13 @@ public class ImageUtilTest {
}
// assertEquals("Difference should not change", diffOriginal, diffSharpened);
assertTrue("Abs difference should increase", absDiffOriginal < absDiffSharpened);
assertTrue(absDiffOriginal < absDiffSharpened, "Abs difference should increase");
// assertEquals("Difference should not change", diffOriginal, diffDefault);
assertTrue("Abs difference should increase", absDiffOriginal < absDiffDefault);
assertTrue(absDiffOriginal < absDiffDefault, "Abs difference should increase");
// assertEquals("Difference should not change", diffOriginal, diffMore);
assertTrue("Abs difference should increase", absDiffOriginal < absDiffMore);
assertTrue(absDiffOriginal < absDiffMore, "Abs difference should increase");
// assertEquals("Difference should not change", diffSharpened, diffMore);
assertTrue("Abs difference should increase", absDiffSharpened < absDiffMore);
assertTrue(absDiffSharpened < absDiffMore, "Abs difference should increase");
}
@Test
@@ -466,7 +466,7 @@ public class ImageUtilTest {
if (original != notBlurred) { // Don't care to test if images are same
for (int y = 0; y < original.getHeight(); y++) {
for (int x = 0; x < original.getWidth(); x++) {
assertEquals("0 blur should not change image", original.getRGB(x, y), notBlurred.getRGB(x, y));
assertEquals(original.getRGB(x, y), notBlurred.getRGB(x, y), "0 blur should not change image");
}
}
}
@@ -512,13 +512,13 @@ public class ImageUtilTest {
}
// assertEquals("Difference should not change", diffOriginal, diffBlurred);
assertTrue(String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred), absDiffOriginal > absDiffBlurred);
assertTrue(absDiffOriginal > absDiffBlurred, String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred));
// assertEquals("Difference should not change", diffOriginal, diffDefault);
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffDefault);
assertTrue(absDiffOriginal > absDiffDefault, "Abs difference should decrease");
// assertEquals("Difference should not change", diffOriginal, diffMore);
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffMore);
assertTrue(absDiffOriginal > absDiffMore, "Abs difference should decrease");
// assertEquals("Difference should not change", diffBlurred, diffMore);
assertTrue("Abs difference should decrease", absDiffBlurred > absDiffMore);
assertTrue(absDiffBlurred > absDiffMore, "Abs difference should decrease");
}
@Test
@@ -528,7 +528,7 @@ public class ImageUtilTest {
assertNotNull(sunflower);
BufferedImage image = ImageUtil.createIndexed(sunflower);
assertNotNull("Image was null", image);
assertTrue(image.getColorModel() instanceof IndexColorModel);
assertNotNull(image, "Image was null");
assertInstanceOf(IndexColorModel.class, image.getColorModel());
}
}

View File

@@ -30,8 +30,8 @@
package com.twelvemonkeys.image;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.awt.*;
import java.awt.image.BufferedImage;
@@ -40,7 +40,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* ResampleOpTestCase
@@ -124,7 +124,7 @@ public class ResampleOpTest {
}
}
assertEquals("Filter threw exceptions: ", Collections.EMPTY_LIST, exceptions);
assertEquals(Collections.EMPTY_LIST, exceptions, "Filter threw exceptions: ");
}
// 1x1
@@ -358,7 +358,7 @@ public class ResampleOpTest {
}
}
@Ignore("Not for general unit testing")
@Disabled("Not for general unit testing")
@Test
public void testTime() {
int iterations = 1000;