Skip to content

Commit

Permalink
Small improvements in the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
  • Loading branch information
api-from-the-ion authored and lukasj committed Feb 26, 2024
1 parent 85cdc84 commit ebf6534
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 182 deletions.
10 changes: 5 additions & 5 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class JsonArrayTest {
@Test
void testArrayEquals() throws Exception {
void testArrayEquals() {
JsonArray expected = Json.createArrayBuilder()
.add(JsonValue.TRUE)
.add(JsonValue.FALSE)
Expand Down Expand Up @@ -96,15 +96,15 @@ void testArrayEqualsUsingCollection() {
}

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

@Test
void testIntValue() throws Exception {
void testIntValue() {
JsonArray array = Json.createArrayBuilder()
.add(20)
.build();
Expand Down Expand Up @@ -134,7 +134,7 @@ void testRemove() {
}

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

List<JsonNumber> numberList = array.getValuesAs(JsonNumber.class);
Expand All @@ -149,7 +149,7 @@ void testNumberView() throws Exception {
@Test
void testArrayBuilderNpe() {
try {
JsonArray array = Json.createArrayBuilder().add((JsonValue)null).build();
Json.createArrayBuilder().add((JsonValue)null).build();
fail("JsonArrayBuilder#add(null) should throw NullPointerException");
} catch(NullPointerException e) {
// Expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@
public class JsonBuilderTest {

@Test
void testEmptyObject() throws Exception {
void testEmptyObject() {
JsonObject empty = Json.createObjectBuilder()
.build();

JsonObjectTest.testEmpty(empty);
}

@Test
void testEmptyArray() throws Exception {
void testEmptyArray() {
JsonArray empty = Json.createArrayBuilder()
.build();

assertTrue(empty.isEmpty());
}

@Test
void testObject() throws Exception {
void testObject() {
JsonObject person = buildPerson();
JsonObjectTest.testPerson(person);
}

@Test
void testNumber() throws Exception {
void testNumber() {
JsonObject person = buildPerson();
JsonNumber number = person.getJsonNumber("age");
assertEquals(25, number.intValueExact());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@

import jakarta.json.Json;
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonConfig;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonReader;
import jakarta.json.JsonReaderFactory;
import jakarta.json.stream.JsonParsingException;

import org.eclipse.parsson.api.JsonConfig;

import org.junit.jupiter.api.Test;


Expand All @@ -48,7 +47,7 @@ void testJsonReaderDuplicateKey1() {
@Test
void testJsonReaderDuplicateKey2() {
String json = "{\"a\":\"b\",\"a\":\"c\"}";
JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true));
JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.KEY_STRATEGY, JsonConfig.KeyStrategy.NONE));
JsonReader jsonReader = jsonReaderFactory.createReader(new StringReader(json));
try {
jsonReader.readObject();
Expand All @@ -69,8 +68,8 @@ void testJsonReaderDuplicateKey3() {

@Test
void testJsonReaderDuplicateKey4() {
String json = "{\"a\":\"b\",\"b\":{\"c\":\"d\",\"c\":\"e\"}}";;
JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true));
String json = "{\"a\":\"b\",\"b\":{\"c\":\"d\",\"c\":\"e\"}}";
JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(Collections.singletonMap(JsonConfig.KEY_STRATEGY, JsonConfig.KeyStrategy.NONE));
JsonReader jsonReader = jsonReaderFactory.createReader(new StringReader(json));
try {
jsonReader.readObject();
Expand All @@ -90,7 +89,7 @@ void testJsonObjectBuilderDuplcateKey1() {

@Test
void testJsonObjectBuilderDuplcateKey2() {
JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Collections.singletonMap(JsonConfig.REJECT_DUPLICATE_KEYS, true));
JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Collections.singletonMap(JsonConfig.KEY_STRATEGY, JsonConfig.KeyStrategy.NONE));
JsonObjectBuilder objectBuilder = jsonBuilderFactory.createObjectBuilder();
try {
objectBuilder.add("a", "b").add("a", "c").build();
Expand Down
32 changes: 16 additions & 16 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void testObjectStream() throws Exception {
in.close();
}

static void testObject(JsonGenerator generator) throws Exception {
static void testObject(JsonGenerator generator) {
generator
.writeStartObject()
.write("firstName", "John")
Expand All @@ -107,7 +107,7 @@ static void testObject(JsonGenerator generator) throws Exception {
}

@Test
void testArray() throws Exception {
void testArray() {
Writer sw = new StringWriter();
JsonGenerator generator = Json.createGenerator(sw);
generator
Expand Down Expand Up @@ -185,7 +185,7 @@ void testEscapedString1() throws Exception {
}

@Test
void testGeneratorEquals() throws Exception {
void testGeneratorEquals() {
StringWriter sw = new StringWriter();
JsonGenerator generator = Json.createGenerator(sw);
generator.writeStartArray()
Expand Down Expand Up @@ -283,7 +283,7 @@ void testPrettyObjectStream() throws Exception {
}

@Test
void testGenerationException1() throws Exception {
void testGenerationException1() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject();
Expand All @@ -296,7 +296,7 @@ void testGenerationException1() throws Exception {
}

@Test
void testGenerationException2() throws Exception {
void testGenerationException2() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject();
Expand All @@ -309,7 +309,7 @@ void testGenerationException2() throws Exception {
}

@Test
void testGenerationException3() throws Exception {
void testGenerationException3() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
try {
Expand All @@ -321,7 +321,7 @@ void testGenerationException3() throws Exception {
}

@Test
void testGenerationException4() throws Exception {
void testGenerationException4() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartArray();
Expand All @@ -334,7 +334,7 @@ void testGenerationException4() throws Exception {
}

@Test
void testGenerationException5() throws Exception {
void testGenerationException5() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject();
Expand All @@ -347,7 +347,7 @@ void testGenerationException5() throws Exception {
}

@Test
void testGenerationException6() throws Exception {
void testGenerationException6() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject().writeEnd();
Expand All @@ -360,7 +360,7 @@ void testGenerationException6() throws Exception {
}

@Test
void testGenerationException7() throws Exception {
void testGenerationException7() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartArray().writeEnd();
Expand All @@ -374,7 +374,7 @@ void testGenerationException7() throws Exception {


@Test
void testGenerationException8() throws Exception {
void testGenerationException8() {
StringWriter sWriter = new StringWriter();
JsonGenerator generator = Json.createGenerator(sWriter);
generator.writeStartObject();
Expand All @@ -387,7 +387,7 @@ void testGenerationException8() throws Exception {
}

@Test
void testGenerationException9() throws Exception {
void testGenerationException9() {
StringWriter sWriter = new StringWriter();
JsonGenerator generator = Json.createGenerator(sWriter);
generator.writeStartObject();
Expand All @@ -400,7 +400,7 @@ void testGenerationException9() throws Exception {
}

@Test
void testGeneratorArrayDouble() throws Exception {
void testGeneratorArrayDouble() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartArray();
Expand All @@ -427,7 +427,7 @@ void testGeneratorArrayDouble() throws Exception {
}

@Test
void testGeneratorObjectDouble() throws Exception {
void testGeneratorObjectDouble() {
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject();
Expand All @@ -454,7 +454,7 @@ void testGeneratorObjectDouble() throws Exception {
}

@Test
void testIntGenerator() throws Exception {
void testIntGenerator() {
Random r = new Random(System.currentTimeMillis());
JsonGeneratorFactory gf = Json.createGeneratorFactory(null);
JsonReaderFactory rf = Json.createReaderFactory(null);
Expand All @@ -476,7 +476,7 @@ void testIntGenerator() throws Exception {
}

@Test
void testGeneratorBuf() throws Exception {
void testGeneratorBuf() {
JsonGeneratorFactory gf = Json.createGeneratorFactory(null);
JsonReaderFactory rf = Json.createReaderFactory(null);
JsonBuilderFactory bf = Json.createBuilderFactory(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static Iterable<Object[]> data() throws Exception {
return examples;
}

@SuppressWarnings("unchecked")
private static Class<? extends Exception> createExceptionClass(
JsonString exceptionClassName) throws ClassNotFoundException {
if (exceptionClassName != null) {
Expand All @@ -74,8 +75,7 @@ private static JsonArray loadData() {
InputStream testData = JsonPatchTest.class
.getResourceAsStream("/jsonmergepatchdiff.json");
JsonReader reader = Json.createReader(testData);
JsonArray data = (JsonArray) reader.read();
return data;
return (JsonArray) reader.read();
}

@MethodSource("data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static Iterable<Object[]> data() throws Exception {
return examples;
}

@SuppressWarnings("unchecked")
private static Class<? extends Exception> createExceptionClass(
JsonString exceptionClassName) throws ClassNotFoundException {
if (exceptionClassName != null) {
Expand All @@ -74,8 +75,7 @@ private static JsonArray loadData() {
InputStream testData = JsonPatchTest.class
.getResourceAsStream("/jsonmergepatch.json");
JsonReader reader = Json.createReader(testData);
JsonArray data = (JsonArray) reader.read();
return data;
return (JsonArray) reader.read();
}

@MethodSource("data")
Expand Down
14 changes: 7 additions & 7 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class JsonNumberTest {
private static final int DEFAULT_MAX_BIGINTEGER_SCALE = 100000;

@Test
void testFloating() throws Exception {
void testFloating() {
JsonArray array1 = Json.createArrayBuilder().add(10.4).build();
JsonReader reader = Json.createReader(new StringReader("[10.4]"));
JsonArray array2 = reader.readArray();
Expand All @@ -82,7 +82,7 @@ void testFloating() throws Exception {
}

@Test
void testBigDecimal() throws Exception {
void testBigDecimal() {
JsonArray array1 = Json.createArrayBuilder().add(new BigDecimal("10.4")).build();
JsonReader reader = Json.createReader(new StringReader("[10.4]"));
JsonArray array2 = reader.readArray();
Expand All @@ -92,14 +92,14 @@ void testBigDecimal() throws Exception {
}

@Test
void testIntNumberType() throws Exception {
void testIntNumberType() {
JsonArray array1 = Json.createArrayBuilder()
.add(Integer.MIN_VALUE)
.add(Integer.MAX_VALUE)
.add(Integer.MIN_VALUE + 1)
.add(Integer.MAX_VALUE - 1)
.add(12)
.add(12l)
.add(12L)
.add(new BigInteger("0"))
.build();
testNumberType(array1, true);
Expand Down Expand Up @@ -128,7 +128,7 @@ private void testNumberType(JsonArray array, boolean integral) {
}

@Test
void testLongNumberType() throws Exception {
void testLongNumberType() {
JsonArray array1 = Json.createArrayBuilder()
.add(Long.MIN_VALUE)
.add(Long.MAX_VALUE)
Expand Down Expand Up @@ -180,7 +180,7 @@ void testLongNumberType() throws Exception {
// }

@Test
void testBigDecimalNumberType() throws Exception {
void testBigDecimalNumberType() {
JsonArray array1 = Json.createArrayBuilder()
.add(12d)
.add(12.0d)
Expand All @@ -206,7 +206,7 @@ void testBigDecimalNumberType() throws Exception {
}

@Test
void testMinMax() throws Exception {
void testMinMax() {
JsonArray expected = Json.createArrayBuilder()
.add(Integer.MIN_VALUE)
.add(Integer.MAX_VALUE)
Expand Down
Loading

0 comments on commit ebf6534

Please sign in to comment.