Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to JUnit 5 #800

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<kryo.major.version>5</kryo.major.version>
<javac.target>1.8</javac.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.7.0</junit.version>
</properties>

<modules>
Expand All @@ -55,9 +56,21 @@
<dependencies>
<!-- Tests. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
20 changes: 10 additions & 10 deletions test/com/esotericsoftware/kryo/CopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CopyTest extends KryoTestCase {
@Before
class CopyTest extends KryoTestCase {
@BeforeEach
public void setUp () throws Exception {
super.setUp();
kryo.setRegistrationRequired(false);
}

@Test
public void testBasic () {
void testBasic () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
Expand All @@ -46,7 +46,7 @@ public void testBasic () {
}

@Test
public void testNested () {
void testNested () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
Expand All @@ -73,7 +73,7 @@ public void testNested () {
}

@Test
public void testReferences () {
void testReferences () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
Expand Down Expand Up @@ -106,7 +106,7 @@ public void testReferences () {
}

@Test
public void testCircularReferences () {
void testCircularReferences () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testCircularReferences () {
}

@Test
public void testShallow () {
void testShallow () {
ArrayList test = new ArrayList();
test.add("one");
test.add("two");
Expand Down
6 changes: 3 additions & 3 deletions test/com/esotericsoftware/kryo/DepthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package com.esotericsoftware.kryo;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DepthTest extends KryoTestCase {
class DepthTest extends KryoTestCase {
static class Node<T> {
Node<T> child;

Expand All @@ -31,7 +31,7 @@ public boolean equals (Object obj) {
}

@Test
public void testDepth () {
void testDepth () {
Node<String> current = new Node<>();
Node<String> root = current;
for (int i = 0; i < 300; i++) {
Expand Down
8 changes: 4 additions & 4 deletions test/com/esotericsoftware/kryo/GarbageCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import com.esotericsoftware.kryo.util.DefaultClassResolver;
import com.esotericsoftware.kryo.util.MapReferenceResolver;

import java.lang.ref.WeakReference;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/** Tests for detecting PermGen memory leaks.
* @author Tumi <serverperformance@gmail.com> */
public class GarbageCollectionTest {
class GarbageCollectionTest {
@Test
public void test () {
void test () {
Kryo kryo = new Kryo(new DefaultClassResolver(), new MapReferenceResolver());
WeakReference<Kryo> kryoWeakRef = new WeakReference(kryo);
kryo = null; // remove strong ref, now kryo is only weak-reachable
Expand Down
2 changes: 1 addition & 1 deletion test/com/esotericsoftware/kryo/KryoAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* Junit Assert wrapper methods class
Expand Down
16 changes: 8 additions & 8 deletions test/com/esotericsoftware/kryo/KryoTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.esotericsoftware.kryo;

import static com.esotericsoftware.minlog.Log.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import com.esotericsoftware.kryo.io.ByteBufferInput;
import com.esotericsoftware.kryo.io.ByteBufferOutput;
Expand All @@ -40,7 +40,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;

import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

/** Convenience methods for round tripping objects.
* @author Nathan Sweet */
Expand All @@ -66,7 +66,7 @@ static interface BufferFactory {
public Input createInput (byte[] buffer);
}

@Before
@BeforeEach
public void setUp () throws Exception {
if (debug && WARN) warn("*** DEBUG TEST ***");

Expand Down Expand Up @@ -213,8 +213,8 @@ public <T> T roundTripWithBufferFactory (int length, T object1, BufferFactory sf
object2 = kryo.readClassAndObject(input);
doAssertEquals(object1, object2);
if (checkLength) {
assertEquals("Incorrect number of bytes read.", length, input.total());
assertEquals("Incorrect number of bytes written.", length, output.total());
assertEquals(length, input.total(), "Incorrect number of bytes read.");
assertEquals(length, output.total(), "Incorrect number of bytes written.");
}

if (debug) return (T)object2;
Expand All @@ -229,7 +229,7 @@ public <T> T roundTripWithBufferFactory (int length, T object1, BufferFactory sf
input = sf.createInput(new ByteArrayInputStream(outStream.toByteArray()), 10);
object2 = kryo.readClassAndObject(input);
doAssertEquals(object1, object2);
if (checkLength) assertEquals("Incorrect number of bytes read.", length, input.total());
if (checkLength) assertEquals(length, input.total(), "Incorrect number of bytes read.");

if (object1 != null) {
// Test null with serializer.
Expand Down Expand Up @@ -257,8 +257,8 @@ public <T> T roundTripWithBufferFactory (int length, T object1, BufferFactory sf
object2 = kryo.readClassAndObject(input);
doAssertEquals(object1, object2);
if (checkLength) {
assertEquals("Incorrect length.", length, output.total());
assertEquals("Incorrect number of bytes read.", length, input.total());
assertEquals( length, output.total(), "Incorrect length.");
assertEquals( length, input.total(), "Incorrect number of bytes read.");
}
input.reset();

Expand Down
10 changes: 5 additions & 5 deletions test/com/esotericsoftware/kryo/ReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
Expand All @@ -30,9 +30,9 @@
import java.util.List;
import java.util.TreeMap;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ReferenceTest extends KryoTestCase {
class ReferenceTest extends KryoTestCase {
public static class Ordering {
public String order;
}
Expand All @@ -46,7 +46,7 @@ public Stuff (Ordering ordering) {
}

@Test
public void testChildObjectBeforeReference () {
void testChildObjectBeforeReference () {
Ordering ordering = new Ordering();
ordering.order = "assbackwards";
Stuff stuff = new Stuff(ordering);
Expand Down Expand Up @@ -82,7 +82,7 @@ protected Stuff create (Kryo kryo, Input input, Class<? extends Stuff> type, int
}

@Test
public void testReadingNestedObjectsFirst () {
void testReadingNestedObjectsFirst () {
ArrayList list = new ArrayList();
list.add("1");
list.add("1");
Expand Down
37 changes: 19 additions & 18 deletions test/com/esotericsoftware/kryo/ReflectionAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -65,7 +65,7 @@ static void assertReflectionEquals (final Object one, final Object another) {
* implementing class. If <code>false</code>, it's only checked if both objects are a {@link List}, {@link Set} or
* {@link Map}. */
static void assertReflectionEquals (final Object one, final Object another, final boolean requireMatchingCollectionClasses) {
assertReflectionEquals(one, another, requireMatchingCollectionClasses, new IdentityHashMap(), "");
assertReflectionEquals(one, another, requireMatchingCollectionClasses, new IdentityHashMap<>(), "");
}

// CHECKSTYLE:OFF
Expand Down Expand Up @@ -97,25 +97,25 @@ private static void assertReflectionEquals (final Object one, final Object anoth
+ one.getClass() + ", " + another.getClass());
}
} else {
assertEquals("Classes don't match on path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ", one.getClass(),
another.getClass());
assertEquals(one.getClass(), another.getClass(),
"Classes don't match on path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ");
}

if (one instanceof AtomicInteger || one instanceof AtomicLong) {
assertEquals("Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ",
((Number)one).longValue(), ((Number)another).longValue());
assertEquals(((Number)one).longValue(), ((Number)another).longValue(),
"Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ");
return;
}

if (one instanceof Calendar) {
assertEquals("Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - \n"
+ ((Calendar)one).getTimeInMillis() + "\n" + ((Calendar)another).getTimeInMillis() + "\n", one, another);
assertEquals(one, another, "Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - \n"
+ ((Calendar)one).getTimeInMillis() + "\n" + ((Calendar)another).getTimeInMillis() + "\n");
return;
}

if (one.getClass().isPrimitive() || one instanceof String || one instanceof Character || one instanceof Boolean
|| one instanceof Number || one instanceof Date) {
assertEquals("Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ", one, another);
assertEquals(one, another, "Values not equals for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ");
return;
}

Expand All @@ -134,11 +134,11 @@ private static void assertReflectionEquals (final Object one, final Object anoth
// correctly (that was issue #34)
final Currency currency1 = (Currency)one;
final Currency currency2 = (Currency)another;
assertEquals("Currency code does not match for currency on path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ",
currency1.getCurrencyCode(), currency2.getCurrencyCode());
assertEquals("Currency default fraction digits do not match for currency on path '"
+ (StringUtils.isEmpty(path) ? "." : path) + "' - ", currency1.getDefaultFractionDigits(),
currency2.getDefaultFractionDigits());
assertEquals(currency1.getCurrencyCode(), currency2.getCurrencyCode(),
"Currency code does not match for currency on path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ");
assertEquals(currency1.getDefaultFractionDigits(), currency2.getDefaultFractionDigits(),
"Currency default fraction digits do not match for currency on path '"
+ (StringUtils.isEmpty(path) ? "." : path) + "' - ");
return;
}

Expand Down Expand Up @@ -170,8 +170,8 @@ private static boolean oneIsAssignable (final Object one, final Object another,
*/
private static void assertCollectionEquals (final Collection m1, final Collection m2, final boolean requireMatchingClasses,
final Map<Object, Object> alreadyChecked, final String path) {
assertEquals("Collection size does not match for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ", m1.size(),
m2.size());
assertEquals(m1.size(), m2.size(),
"Collection size does not match for path '" + (StringUtils.isEmpty(path) ? "." : path) + "' - ");
final Iterator iter1 = m1.iterator();
final Iterator iter2 = m2.iterator();
int i = 0;
Expand All @@ -182,8 +182,9 @@ private static void assertCollectionEquals (final Collection m1, final Collectio

private static void assertMapEquals (final Map<?, ?> m1, final Map<?, ?> m2, final boolean requireMatchingClasses,
final Map<Object, Object> alreadyChecked, final String path) {
assertEquals("Map size does not match for path '" + (StringUtils.isEmpty(path) ? "." : path) + "', map contents:"
+ "\nmap1: " + m1 + "\nmap2: " + m2 + "\n", m1.size(), m2.size());
assertEquals(m1.size(), m2.size(),
"Map size does not match for path '" + (StringUtils.isEmpty(path) ? "." : path) + "', map contents:"
+ "\nmap1: " + m1 + "\nmap2: " + m2 + "\n");
for (final Map.Entry<?, ?> entry : m1.entrySet()) {
assertReflectionEquals(entry.getValue(), m2.get(entry.getKey()), requireMatchingClasses, alreadyChecked,
path + "[" + entry.getKey() + "]");
Expand Down
10 changes: 5 additions & 5 deletions test/com/esotericsoftware/kryo/RegistrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.esotericsoftware.kryo;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
Expand All @@ -28,11 +28,11 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RegistrationTest {
class RegistrationTest {
@Test
public void testDefaultSerializerOrder () {
void testDefaultSerializerOrder () {
Kryo kryo = new Kryo();
kryo.addDefaultSerializer(Fruit.class, new FieldSerializer(kryo, Fruit.class));
FieldSerializer appleSerializer = new FieldSerializer(kryo, Apple.class);
Expand All @@ -41,7 +41,7 @@ public void testDefaultSerializerOrder () {
}

@Test
public void testReplaceRegistration () throws IOException {
void testReplaceRegistration () throws IOException {
Kryo kryo = new Kryo();
kryo.register(double[].class, 7); // Replace long with double[].
kryo.register(Some.class);
Expand Down
Loading