Skip to content

Commit

Permalink
Upgrade from JUnit 4 to the JUnit 5 with OpenRewrite recipe and some …
Browse files Browse the repository at this point in the history
…corrections afterward

Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
  • Loading branch information
api-from-the-ion committed Nov 17, 2023
1 parent 5c41302 commit a1444eb
Show file tree
Hide file tree
Showing 44 changed files with 1,016 additions and 796 deletions.
4 changes: 2 additions & 2 deletions demos/customprovider-jdk9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

package customprovider.test;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;

import jakarta.json.Json;
import jakarta.json.stream.JsonGenerator;

import org.eclipse.parsson.demos.customprovider.TestGenerator;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
*
Expand All @@ -23,9 +25,9 @@
public class TestProviderTest {

@Test
public void hello() {
void hello() {
try (JsonGenerator generator = Json.createGenerator(System.out)) {
Assert.assertTrue("TestGenerator is not picked up", generator instanceof TestGenerator);
assertInstanceOf(TestGenerator.class, generator, "TestGenerator is not picked up");
generator.writeStartArray().writeEnd();
}
System.out.println();
Expand Down
10 changes: 8 additions & 2 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
8 changes: 4 additions & 4 deletions impl/src/test/java/org/eclipse/parsson/tests/Issue25Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package org.eclipse.parsson.tests;

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

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

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

import jakarta.json.JsonObject;
import jakarta.json.spi.JsonProvider;
Expand All @@ -32,7 +32,7 @@
public class Issue25Test {

@Test
public void doubleClose() throws IOException {
void doubleClose() throws IOException {
byte[] content = "[\"test\"]".getBytes();
JsonProvider json = JsonProvider.provider();
for (int i = 0; i < 3; i++) {
Expand All @@ -54,7 +54,7 @@ public void doubleClose() throws IOException {
}

@Test
public void doubleCloseWithMoreContent() throws IOException {
void doubleCloseWithMoreContent() throws IOException {
byte[] content = loadResource("/comments.json");
JsonProvider json = JsonProvider.provider();
for (int i = 0; i < 3; i++) {
Expand Down
47 changes: 31 additions & 16 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,30 @@

package org.eclipse.parsson.tests;

import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import jakarta.json.*;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonNumber;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;
import jakarta.json.JsonWriter;

import org.junit.jupiter.api.Test;

/**
* @author Jitendra Kotamraju
*/
public class JsonArrayTest extends TestCase {
public JsonArrayTest(String testName) {
super(testName);
}

public void testArrayEquals() throws Exception {
public class JsonArrayTest {
@Test
void testArrayEquals() throws Exception {
JsonArray expected = Json.createArrayBuilder()
.add(JsonValue.TRUE)
.add(JsonValue.FALSE)
Expand All @@ -59,7 +66,8 @@ public void testArrayEquals() throws Exception {
assertEquals(expected, actual);
}

public void testArrayEqualsUsingCollection() {
@Test
void testArrayEqualsUsingCollection() {
List<Object> list = new ArrayList<>();
list.add(JsonValue.TRUE);
list.add(JsonValue.FALSE);
Expand Down Expand Up @@ -87,21 +95,24 @@ public void testArrayEqualsUsingCollection() {
assertEquals(expected, actual);
}

public void testStringValue() throws Exception {
@Test
void testStringValue() throws Exception {
JsonArray array = Json.createArrayBuilder()
.add("John")
.build();
assertEquals("John", array.getString(0));
}

public void testIntValue() throws Exception {
@Test
void testIntValue() throws Exception {
JsonArray array = Json.createArrayBuilder()
.add(20)
.build();
assertEquals(20, array.getInt(0));
}

public void testAdd() {
@Test
void testAdd() {
JsonArray array = Json.createArrayBuilder().build();
try {
array.add(JsonValue.FALSE);
Expand All @@ -111,7 +122,8 @@ public void testAdd() {
}
}

public void testRemove() {
@Test
void testRemove() {
JsonArray array = Json.createArrayBuilder().build();
try {
array.remove(0);
Expand All @@ -121,7 +133,8 @@ public void testRemove() {
}
}

public void testNumberView() throws Exception {
@Test
void testNumberView() throws Exception {
JsonArray array = Json.createArrayBuilder().add(20).add(10).build();

List<JsonNumber> numberList = array.getValuesAs(JsonNumber.class);
Expand All @@ -133,7 +146,8 @@ public void testNumberView() throws Exception {
assertEquals(10, array.getInt(1));
}

public void testArrayBuilderNpe() {
@Test
void testArrayBuilderNpe() {
try {
JsonArray array = Json.createArrayBuilder().add((JsonValue)null).build();
fail("JsonArrayBuilder#add(null) should throw NullPointerException");
Expand All @@ -142,7 +156,8 @@ public void testArrayBuilderNpe() {
}
}

public void testHashCode() {
@Test
void testHashCode() {
JsonArray array1 = Json.createArrayBuilder().add(1).add(2).add(3).build();
assertTrue(array1.hashCode() == array1.hashCode()); //1st call compute hashCode, 2nd call returns cached value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,41 @@

package org.eclipse.parsson.tests;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.StringReader;
import java.math.BigDecimal;

import jakarta.json.Json;
import jakarta.json.JsonNumber;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;
import junit.framework.TestCase;

import org.eclipse.parsson.api.JsonConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test maxBigDecimalLength limit set from System property.
*/
public class JsonBigDecimalLengthLimitTest extends TestCase {

public JsonBigDecimalLengthLimitTest(String testName) {
super(testName);
}
public class JsonBigDecimalLengthLimitTest {

@Override
protected void setUp() {
@BeforeEach
void setUp() {
System.setProperty(JsonConfig.MAX_BIGDECIMAL_LEN, "500");
}

@Override
protected void tearDown() {
@AfterEach
void tearDown() {
System.clearProperty(JsonConfig.MAX_BIGDECIMAL_LEN);
}

// Test BigDecimal max source characters array length using length equal to system property limit of 500.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalBellowLimit() {
@Test
void testLargeBigDecimalBellowLimit() {
JsonReader reader = Json.createReader(new StringReader(JsonNumberTest.Π_500));
JsonNumber check = Json.createValue(new BigDecimal(JsonNumberTest.Π_500));
JsonValue value = reader.readValue();
Expand All @@ -57,7 +60,8 @@ public void testLargeBigDecimalBellowLimit() {

// Test BigDecimal max source characters array length using length above system property limit of 500.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalAboveLimit() {
@Test
void testLargeBigDecimalAboveLimit() {
JsonReader reader = Json.createReader(new StringReader(JsonNumberTest.Π_501));
try {
reader.readValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,41 @@

package org.eclipse.parsson.tests;

import static org.junit.jupiter.api.Assertions.fail;

import java.math.BigDecimal;
import java.math.RoundingMode;

import jakarta.json.Json;
import junit.framework.TestCase;

import org.eclipse.parsson.api.JsonConfig;

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


/**
* Test maxBigIntegerScale limit set from System property.
*/
public class JsonBigDecimalScaleLimitTest extends TestCase {
public class JsonBigDecimalScaleLimitTest {

private static final int MAX_BIGINTEGER_SCALE = 50000;

public JsonBigDecimalScaleLimitTest(String testName) {
super(testName);
}

@Override
protected void setUp() {

@BeforeEach
void setUp() {
System.setProperty(JsonConfig.MAX_BIGINTEGER_SCALE, Integer.toString(MAX_BIGINTEGER_SCALE));
}

@Override
protected void tearDown() {
@AfterEach
void tearDown() {
System.clearProperty(JsonConfig.MAX_BIGINTEGER_SCALE);
}

// Test BigInteger scale value limit set from system property using value bellow limit.
// Call shall return value.
public void testSystemPropertyBigIntegerScaleBellowLimit() {
@Test
void testSystemPropertyBigIntegerScaleBellowLimit() {
BigDecimal value = new BigDecimal("3.1415926535897932384626433");
Json.createValue(value).bigIntegerValue();
}
Expand All @@ -55,7 +59,8 @@ public void testSystemPropertyBigIntegerScaleBellowLimit() {
// Call shall throw specific UnsupportedOperationException exception.
// Default value is 100000 and system property lowered it to 50000 so value with scale 50001
// test shall fail with exception message matching modified limits.
public void testSystemPropertyBigIntegerScaleAboveLimit() {
@Test
void testSystemPropertyBigIntegerScaleAboveLimit() {
BigDecimal value = new BigDecimal("3.1415926535897932384626433")
.setScale(50001, RoundingMode.HALF_UP);
try {
Expand All @@ -73,7 +78,8 @@ public void testSystemPropertyBigIntegerScaleAboveLimit() {
// Call shall throw specific UnsupportedOperationException exception.
// Default value is 100000 and system property lowered it to 50000 so value with scale -50001
// test shall fail with exception message matching modified limits.
public void testSystemPropertyBigIntegerNegScaleAboveLimit() {
@Test
void testSystemPropertyBigIntegerNegScaleAboveLimit() {
BigDecimal value = new BigDecimal("3.1415926535897932384626433")
.setScale(-50001, RoundingMode.HALF_UP);
try {
Expand Down
Loading

0 comments on commit a1444eb

Please sign in to comment.