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(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import static org.junit.jupiter.api.Assertions.assertEquals;
77

8-
public class CyclicDependencyTest {
8+
class CyclicDependencyTest {
99

1010
@Test
11-
public void whenDependencyBetweenSchemaThenValidationSuccessful() throws Exception {
11+
void whenDependencyBetweenSchemaThenValidationSuccessful() throws Exception {
1212

1313
JsonSchemaFactory schemaFactory = JsonSchemaFactory
1414
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.io.InputStream;
99
import java.util.Set;
1010

11-
public class DateTimeDSTTest {
11+
class DateTimeDSTTest {
1212
protected JsonSchema getJsonSchemaFromStreamContentV7(InputStream schemaContent) {
1313
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
1414
return factory.getSchema(schemaContent);
@@ -21,7 +21,7 @@ protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exce
2121
}
2222

2323
@Test
24-
public void shouldWorkV7() throws Exception {
24+
void shouldWorkV7() throws Exception {
2525
String schemaPath = "/schema/dateTimeArray.json";
2626
String dataPath = "/data/dstTimes.json"; // Contains 2020 DST changes for various countries
2727
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* Tests for the non-standard DefaultJsonSchemaIdValidator.
2828
*/
29-
public class DefaultJsonSchemaIdValidatorTest {
29+
class DefaultJsonSchemaIdValidatorTest {
3030
@Test
3131
void givenRelativeIdShouldThrowInvalidSchemaException() {
3232
String schema = "{\r\n" + " \"$id\": \"0\",\r\n"

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

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

1515
class DependentRequiredTest {
1616

17-
public static final String SCHEMA =
17+
static final String SCHEMA =
1818
"{ " +
1919
" \"$schema\":\"https://json-schema.org/draft/2019-09/schema\"," +
2020
" \"type\": \"object\"," +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Test for discriminator.
3131
*/
32-
public class DiscriminatorValidatorTest {
32+
class DiscriminatorValidatorTest {
3333
/**
3434
* Issue 609.
3535
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
import static org.junit.jupiter.api.Assertions.assertEquals;
2828

29-
public class DurationFormatValidatorTest {
29+
class DurationFormatValidatorTest {
3030

3131
@Test
32-
public void durationFormatValidatorTest() throws JsonProcessingException, IOException {
32+
void durationFormatValidatorTest() throws IOException {
3333
ObjectMapper objectMapper = new ObjectMapper();
3434
final String schema = "{\"type\": \"string\", \"format\": \"duration\"}\n";
3535
final JsonNode validTargetNode = objectMapper.readTree("\"P1D\"");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

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

26-
public class ExampleTest {
26+
class ExampleTest {
2727
@Test
28-
public void exampleSchemaLocation() throws Exception {
28+
void exampleSchemaLocation() {
2929
// This creates a schema factory that will use Draft 2012-12 as the default if $schema is not specified in the initial schema
3030
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012, builder ->
3131
builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix("https://www.example.org/", "classpath:schema/"))
@@ -50,7 +50,7 @@ public void exampleSchemaLocation() throws Exception {
5050
}
5151

5252
@Test
53-
public void exampleClasspath() throws Exception {
53+
void exampleClasspath() {
5454
// This creates a schema factory that will use Draft 2012-12 as the default if $schema is not specified in the initial schema
5555
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
5656
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Test ExclusiveMinimumValidator validator.
2929
*/
30-
public class ExclusiveMinimumValidatorTest {
30+
class ExclusiveMinimumValidatorTest {
3131
@Test
3232
void draftV4ShouldHaveExclusiveMinimum() {
3333
String schemaData = "{" +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.fasterxml.jackson.databind.JsonNode;
2525
import com.networknt.schema.SpecVersion.VersionFlag;
2626

27-
public class FormatKeywordFactoryTest {
27+
class FormatKeywordFactoryTest {
2828

2929
public static class CustomFormatKeyword extends FormatKeyword {
3030
public CustomFormatKeyword(Map<String, Format> formats) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/**
3636
* Test for format validator.
3737
*/
38-
public class FormatValidatorTest {
38+
class FormatValidatorTest {
3939
@Test
4040
void unknownFormatNoVocab() {
4141
String schemaData = "{\r\n"
@@ -180,10 +180,10 @@ void patternFormatDeprecated() {
180180
assertEquals(": does not match the custom pattern must be test", messages.iterator().next().getMessage());
181181
}
182182

183-
public static class CustomNumberFormat implements Format {
183+
static class CustomNumberFormat implements Format {
184184
private final BigDecimal compare;
185185

186-
public CustomNumberFormat(BigDecimal compare) {
186+
CustomNumberFormat(BigDecimal compare) {
187187
this.compare = compare;
188188
}
189189

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
import static io.undertow.Handlers.*;
2828

29-
public abstract class HTTPServiceSupport {
29+
abstract class HTTPServiceSupport {
3030

3131
protected static Undertow server = null;
3232

3333
@BeforeAll
34-
public static void setUp() {
34+
static void setUp() {
3535
if (server == null) {
3636
PathHandler pathHandler = path(resource(
3737
new FileResourceManager(
@@ -70,7 +70,7 @@ public static void setUp() {
7070
}
7171

7272
@AfterAll
73-
public static void tearDown() throws Exception {
73+
static void tearDown() throws Exception {
7474
if (server != null) {
7575
try {
7676
Thread.sleep(100);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.networknt.schema.SpecVersion.VersionFlag;
2828
import com.networknt.schema.serialization.JsonMapperFactory;
2929

30-
public class Issue1091Test {
30+
class Issue1091Test {
3131
@Test
3232
@Disabled // Disabled as this test takes quite long to run for ci
3333
void testHasAdjacentKeywordInEvaluationPath() throws Exception {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.InputStream;
2424
import java.util.Set;
2525

26-
public class Issue255Test {
26+
class Issue255Test {
2727
protected JsonSchema getJsonSchemaFromStreamContent(InputStream schemaContent) {
2828
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
2929
return factory.getSchema(schemaContent);
@@ -36,7 +36,7 @@ protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exce
3636
}
3737

3838
@Test
39-
public void shouldFailWhenRequiredPropertiesDoNotExistInReferencedSubSchema() throws Exception {
39+
void shouldFailWhenRequiredPropertiesDoNotExistInReferencedSubSchema() throws Exception {
4040
String schemaPath = "/draft2019-09/issue255.json";
4141
String dataPath = "/data/issue255.json";
4242
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);

0 commit comments

Comments
 (0)