Skip to content

Commit d4d0bb3

Browse files
authored
Test Code Cleanup (#1128)
* Clean up test code * Remove unnecessary 'public' keyword on unit tests (and some unnecessary throws)
1 parent 578a91f commit d4d0bb3

File tree

126 files changed

+383
-402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+383
-402
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @see Issue769ContainsTest
1919
* @author vwuilbea
2020
*/
21-
public abstract class AbstractJsonSchemaTest {
21+
abstract class AbstractJsonSchemaTest {
2222

2323
private static final String SCHEMA = "$schema";
2424
private static final SpecVersion.VersionFlag DEFAULT_VERSION_FLAG = SpecVersion.VersionFlag.V202012;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
4545
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
4646

47-
public abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {
47+
abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {
4848

4949
private static String toForwardSlashPath(Path file) {
5050
return file.toString().replace('\\', '/');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* AdditionalPropertiesValidatorTest.
3030
*/
31-
public class AdditionalPropertiesValidatorTest {
31+
class AdditionalPropertiesValidatorTest {
3232
/**
3333
* Tests that the message contains the correct values when additional properties
3434
* schema is false.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import com.networknt.schema.SpecVersion.VersionFlag;
2424

25-
public class AllOfValidatorTest {
25+
class AllOfValidatorTest {
2626
@Test
2727
void invalidTypeShouldThrowJsonSchemaException() {
2828
String schemaData = "{\r\n"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import com.networknt.schema.SpecVersion.VersionFlag;
2424

25-
public class AnyOfValidatorTest {
25+
class AnyOfValidatorTest {
2626
@Test
2727
void invalidTypeShouldThrowJsonSchemaException() {
2828
String schemaData = "{\r\n"

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.util.concurrent.CountDownLatch;
3636
import java.util.concurrent.atomic.AtomicInteger;
3737

38-
public class CollectorContextTest {
38+
class CollectorContextTest {
3939

4040
private static final String SAMPLE_COLLECTOR = "sampleCollector";
4141

@@ -46,13 +46,13 @@ public class CollectorContextTest {
4646
private JsonSchema jsonSchemaForCombine;
4747

4848
@BeforeEach
49-
public void setup() throws Exception {
49+
void setup() throws Exception {
5050
setupSchema();
5151
}
5252

5353
@SuppressWarnings("unchecked")
5454
@Test
55-
public void testCollectorContextWithKeyword() throws Exception {
55+
void testCollectorContextWithKeyword() throws Exception {
5656
ValidationResult validationResult = validate("{\"test-property1\":\"sample1\",\"test-property2\":\"sample2\"}");
5757
Assertions.assertEquals(0, validationResult.getValidationMessages().size());
5858
List<String> contextValues = (List<String>) validationResult.getCollectorContext().get(SAMPLE_COLLECTOR);
@@ -65,7 +65,7 @@ public void testCollectorContextWithKeyword() throws Exception {
6565

6666
@SuppressWarnings("unchecked")
6767
@Test
68-
public void testCollectorContextWithMultipleThreads() throws Exception {
68+
void testCollectorContextWithMultipleThreads() throws Exception {
6969

7070
ValidationThread validationRunnable1 = new ValidationThread("{\"test-property1\":\"sample1\" }", "thread1");
7171
ValidationThread validationRunnable2 = new ValidationThread("{\"test-property1\":\"sample2\" }", "thread2");
@@ -105,7 +105,7 @@ public void testCollectorContextWithMultipleThreads() throws Exception {
105105

106106
@SuppressWarnings("unchecked")
107107
@Test
108-
public void testCollectorGetAll() throws JsonMappingException, JsonProcessingException, IOException {
108+
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));
@@ -427,7 +427,7 @@ public JsonValidator newValidator(SchemaLocation schemaLocation, JsonNodePath ev
427427
}
428428

429429
private class CollectValidator extends AbstractJsonValidator {
430-
public CollectValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonNode schemaNode) {
430+
CollectValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonNode schemaNode) {
431431
super(schemaLocation, evaluationPath, new CollectKeyword(), schemaNode);
432432
}
433433

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* ContentSchemaValidatorTest.
2929
*/
30-
public class ContentSchemaValidatorTest {
30+
class ContentSchemaValidatorTest {
3131
@Test
3232
void annotationCollection() throws JsonProcessingException {
3333
String schemaData = "{\r\n"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.stream.Stream;
1010

1111
@DisplayName("Custom Messages")
12-
public class CustomMessageTest extends AbstractJsonSchemaTestSuite {
12+
class CustomMessageTest extends AbstractJsonSchemaTestSuite {
1313

1414
@TestFactory
1515
@DisplayName("Draft 2019-09 - Custom Messages Enabled")

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.networknt.schema;
1818

19-
import com.fasterxml.jackson.core.JsonProcessingException;
2019
import com.fasterxml.jackson.databind.JsonNode;
2120
import com.fasterxml.jackson.databind.ObjectMapper;
2221
import org.junit.jupiter.api.Test;
@@ -29,7 +28,7 @@
2928

3029
import static org.junit.jupiter.api.Assertions.assertEquals;
3130

32-
public class CustomMetaSchemaTest {
31+
class CustomMetaSchemaTest {
3332

3433
/**
3534
* Introduces the keyword "enumNames".
@@ -41,7 +40,7 @@ public class CustomMetaSchemaTest {
4140
*
4241
* @author klaskalass
4342
*/
44-
public static class EnumNamesKeyword extends AbstractKeyword {
43+
static class EnumNamesKeyword extends AbstractKeyword {
4544

4645
private static final class Validator extends AbstractJsonValidator {
4746
private final List<String> enumValues;
@@ -79,7 +78,7 @@ public Set<ValidationMessage> validate(ExecutionContext executionContext, JsonNo
7978
}
8079

8180

82-
public EnumNamesKeyword() {
81+
EnumNamesKeyword() {
8382
super("enumNames");
8483
}
8584

@@ -115,7 +114,7 @@ private List<String> readStringList(JsonNode node) {
115114
}
116115

117116
@Test
118-
public void customMetaSchemaWithIgnoredKeyword() throws JsonProcessingException, IOException {
117+
void customMetaSchemaWithIgnoredKeyword() throws IOException {
119118
ObjectMapper objectMapper = new ObjectMapper();
120119
final JsonMetaSchema metaSchema = JsonMetaSchema
121120
.builder("https://github.com/networknt/json-schema-validator/tests/schemas/example01", JsonMetaSchema.getV4())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import static org.hamcrest.CoreMatchers.is;
1414
import static org.hamcrest.MatcherAssert.assertThat;
1515

16-
public class CustomUriTest {
16+
class CustomUriTest {
1717
@Test
18-
public void customUri() throws Exception {
18+
void customUri() throws Exception {
1919
/* Given */
2020
final JsonSchemaFactory factory = buildJsonSchemaFactory();
2121
final JsonSchema schema = factory.getSchema(

0 commit comments

Comments
 (0)