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
@@ -44,12 +44,10 @@
*/
package com.twelvemonkeys.util;
import org.junit.Test;
import java.io.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Abstract test class for {@link Object} methods and contracts.
@@ -119,7 +117,7 @@ public abstract class ObjectAbstractTest {
@Test
public void testObjectEqualsSelf() {
Object obj = makeObject();
assertEquals("A Object should equal itself", obj, obj);
assertEquals(obj, obj, "A Object should equal itself");
}
@Test
@@ -131,25 +129,24 @@ public abstract class ObjectAbstractTest {
@Test
public void testObjectHashCodeEqualsSelfHashCode() {
Object obj = makeObject();
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
assertEquals(obj.hashCode(), obj.hashCode(), "hashCode should be repeatable");
}
@Test
public void testObjectHashCodeEqualsContract() {
Object obj1 = makeObject();
if (obj1.equals(obj1)) {
assertEquals(
"[1] When two objects are equal, their hashCodes should be also.",
obj1.hashCode(), obj1.hashCode());
assertEquals(obj1.hashCode(), obj1.hashCode(),
"[1] When two objects are equal, their hashCodes should be also.");
}
Object obj2 = makeObject();
if (obj1.equals(obj2)) {
assertEquals(
"[2] When two objects are equal, their hashCodes should be also.",
obj1.hashCode(), obj2.hashCode());
obj1.hashCode(), obj2.hashCode(),
"[2] When two objects are equal, their hashCodes should be also.");
assertTrue(
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
obj2.equals(obj1));
obj2.equals(obj1),
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true");
}
}
@@ -166,7 +163,7 @@ public abstract class ObjectAbstractTest {
Object dest = in.readObject();
in.close();
if (isEqualsCheckable()) {
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
assertEquals(obj, dest, "obj != deserialize(serialize(obj))");
}
}
}
@@ -199,8 +196,8 @@ public abstract class ObjectAbstractTest {
if (object instanceof Serializable) {
String name = getCanonicalEmptyCollectionName(object);
assertTrue(
"Canonical empty collection (" + name + ") is not in CVS",
new File(name).exists());
new File(name).exists(),
"Canonical empty collection (" + name + ") is not in CVS");
}
}
}
@@ -216,8 +213,8 @@ public abstract class ObjectAbstractTest {
if (object instanceof Serializable) {
String name = getCanonicalFullCollectionName(object);
assertTrue(
"Canonical full collection (" + name + ") is not in CVS",
new File(name).exists());
new File(name).exists(),
"Canonical full collection (" + name + ") is not in CVS");
}
}
}