Skip to content

Commit 3c1301f

Browse files
committed
Clean up test code
1 parent 578a91f commit 3c1301f

32 files changed

+99
-115
lines changed

src/test/java/com/networknt/schema/CollectorContextTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testCollectorContextWithMultipleThreads() throws Exception {
105105

106106
@SuppressWarnings("unchecked")
107107
@Test
108-
public void testCollectorGetAll() throws JsonMappingException, JsonProcessingException, IOException {
108+
public void testCollectorGetAll() throws IOException {
109109
ObjectMapper objectMapper = new ObjectMapper();
110110
ExecutionContext executionContext = jsonSchemaForCombine.createExecutionContext();
111111
executionContext.getExecutionConfig().setFormatAssertionsEnabled(true);
@@ -218,9 +218,9 @@ private String getSchemaStringMultipleProperties() {
218218

219219
private class ValidationThread implements Runnable {
220220

221-
private String data;
221+
private final String data;
222222

223-
private String name;
223+
private final String name;
224224

225225
private ValidationResult validationResult;
226226

@@ -379,7 +379,7 @@ public Set<ValidationMessage> walk(ExecutionContext executionContext, JsonNode n
379379
}
380380
}
381381

382-
private ValidationResult validate(String jsonData) throws JsonMappingException, JsonProcessingException, Exception {
382+
private ValidationResult validate(String jsonData) throws Exception {
383383
ObjectMapper objectMapper = new ObjectMapper();
384384
ExecutionContext executionContext = this.jsonSchema.createExecutionContext();
385385
Set<ValidationMessage> messages = this.jsonSchema.validate(executionContext, objectMapper.readTree(jsonData));

src/test/java/com/networknt/schema/Issue285Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import static org.junit.jupiter.api.Assertions.assertFalse;
1313

1414
public class Issue285Test {
15-
private ObjectMapper mapper = new ObjectMapper();
16-
private JsonSchemaFactory schemaFactory = JsonSchemaFactory
15+
private final ObjectMapper mapper = new ObjectMapper();
16+
private final JsonSchemaFactory schemaFactory = JsonSchemaFactory
1717
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909))
1818
.schemaMappers(schemaMappers -> schemaMappers
1919
.mapPrefix("http://json-schema.org", "resource:")

src/test/java/com/networknt/schema/Issue366FailSlowTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.networknt.schema;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
45
import static org.junit.jupiter.api.Assertions.assertTrue;
56

67
import com.fasterxml.jackson.databind.JsonNode;
@@ -78,7 +79,7 @@ public void bothValid() throws Exception {
7879
JsonNode testNode = testNodes.get(0).get(2);
7980
JsonNode dataNode = testNode.get("data");
8081
Set<ValidationMessage> errors = jsonSchema.validate(dataNode);
81-
assertTrue(!errors.isEmpty());
82+
assertFalse(errors.isEmpty());
8283
assertEquals(errors.size(), 1);
8384
}
8485

@@ -92,7 +93,7 @@ public void neitherValid() throws Exception {
9293
JsonNode testNode = testNodes.get(0).get(3);
9394
JsonNode dataNode = testNode.get("data");
9495
Set<ValidationMessage> errors = jsonSchema.validate(dataNode);
95-
assertTrue(!errors.isEmpty());
96+
assertFalse(errors.isEmpty());
9697
assertEquals(errors.size(), 3);
9798
}
9899

src/test/java/com/networknt/schema/Issue428Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void runTestFile(String testCaseFile) throws Exception {
4545
if (test.get("valid").asBoolean()) {
4646
if (!errors.isEmpty()) {
4747
System.out.println("---- test case failed ----");
48-
System.out.println("schema: " + schema.toString());
48+
System.out.println("schema: " + schema);
4949
System.out.println("data: " + test.get("data"));
5050
System.out.println("errors:");
5151
for (ValidationMessage error : errors) {

src/test/java/com/networknt/schema/Issue467Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import com.networknt.schema.walk.WalkFlow;
3636

3737
public class Issue467Test {
38-
private static JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
39-
private static String schemaPath = "/schema/issue467.json";
38+
private static final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
39+
private static final String schemaPath = "/schema/issue467.json";
4040

4141
protected ObjectMapper mapper = new ObjectMapper();
4242

src/test/java/com/networknt/schema/Issue493Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
class Issue493Test
1818
{
1919

20-
private static JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
21-
private static String schemaPath1 = "/schema/issue493.json";
20+
private static final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
21+
private static final String schemaPath1 = "/schema/issue493.json";
2222

2323
private JsonNode getJsonNodeFromJsonData (String jsonFilePath)
2424
throws Exception

src/test/java/com/networknt/schema/Issue575Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* This project uses a dependency (com.ethlo.time:itu) to validate time representations. Version 1.51 of this library
1717
* has a problem dealing with certain time zones having a negative offset; for example "-2:30" (Newfoundland time, NDT).
1818
* Moving to version 1.7.0 of this library resolves the issue.
19-
*
19+
* <p>
2020
* This test class confirms that valid negative offsets do not result in a JSON validation error if the ITU library is
2121
* updated to version 1.7.0 or later.
2222
*/

src/test/java/com/networknt/schema/Issue927Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.junit.jupiter.api.Test;
2323

2424
import com.fasterxml.jackson.core.JsonProcessingException;
25-
import com.fasterxml.jackson.databind.JsonMappingException;
2625
import com.networknt.schema.SpecVersion.VersionFlag;
2726
import com.networknt.schema.serialization.JsonMapperFactory;
2827

@@ -31,7 +30,7 @@
3130
*/
3231
public class Issue927Test {
3332
@Test
34-
void test() throws JsonMappingException, JsonProcessingException {
33+
void test() throws JsonProcessingException {
3534
String schema = "{\r\n"
3635
+ " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\r\n"
3736
+ " \"$id\": \"id\",\r\n"

src/test/java/com/networknt/schema/Issue994Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import com.fasterxml.jackson.core.JsonProcessingException;
24-
import com.fasterxml.jackson.databind.JsonMappingException;
2524
import com.fasterxml.jackson.databind.JsonNode;
2625
import com.networknt.schema.SpecVersion.VersionFlag;
2726
import com.networknt.schema.serialization.JsonMapperFactory;
2827

2928
public class Issue994Test {
3029
@Test
31-
void test() throws JsonMappingException, JsonProcessingException {
30+
void test() throws JsonProcessingException {
3231
String schemaData = "{\r\n"
3332
+ " \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\r\n"
3433
+ " \"type\": \"object\",\r\n"

src/test/java/com/networknt/schema/ItemsValidatorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.jupiter.api.Test;
2828

2929
import com.fasterxml.jackson.core.JsonProcessingException;
30-
import com.fasterxml.jackson.databind.JsonMappingException;
3130
import com.fasterxml.jackson.databind.JsonNode;
3231
import com.networknt.schema.SpecVersion.VersionFlag;
3332
import com.networknt.schema.serialization.JsonMapperFactory;
@@ -240,7 +239,7 @@ public void onWalkEnd(WalkEvent walkEvent, Set<ValidationMessage> validationMess
240239
}
241240

242241
@Test
243-
void walkTupleItemsAdditional() throws JsonMappingException, JsonProcessingException {
242+
void walkTupleItemsAdditional() throws JsonProcessingException {
244243
String schemaData = "{\r\n"
245244
+ " \"items\": [\r\n"
246245
+ " {\r\n"
@@ -291,7 +290,7 @@ public void onWalkEnd(WalkEvent walkEvent, Set<ValidationMessage> validationMess
291290
}
292291

293292
@Test
294-
void walkTupleItemsAdditionalDefaults() throws JsonMappingException, JsonProcessingException {
293+
void walkTupleItemsAdditionalDefaults() throws JsonProcessingException {
295294
String schemaData = "{\r\n"
296295
+ " \"items\": [\r\n"
297296
+ " {\r\n"

0 commit comments

Comments
 (0)