Skip to content

Commit

Permalink
Test Code Cleanup (#1128)
Browse files Browse the repository at this point in the history
* Clean up test code

* Remove unnecessary 'public' keyword on unit tests (and some unnecessary throws)
  • Loading branch information
jkosternl authored Nov 12, 2024
1 parent 578a91f commit d4d0bb3
Show file tree
Hide file tree
Showing 126 changed files with 383 additions and 402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @see Issue769ContainsTest
* @author vwuilbea
*/
public abstract class AbstractJsonSchemaTest {
abstract class AbstractJsonSchemaTest {

private static final String SCHEMA = "$schema";
private static final SpecVersion.VersionFlag DEFAULT_VERSION_FLAG = SpecVersion.VersionFlag.V202012;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

public abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {
abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {

private static String toForwardSlashPath(Path file) {
return file.toString().replace('\\', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* AdditionalPropertiesValidatorTest.
*/
public class AdditionalPropertiesValidatorTest {
class AdditionalPropertiesValidatorTest {
/**
* Tests that the message contains the correct values when additional properties
* schema is false.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/networknt/schema/AllOfValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.networknt.schema.SpecVersion.VersionFlag;

public class AllOfValidatorTest {
class AllOfValidatorTest {
@Test
void invalidTypeShouldThrowJsonSchemaException() {
String schemaData = "{\r\n"
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/networknt/schema/AnyOfValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.networknt.schema.SpecVersion.VersionFlag;

public class AnyOfValidatorTest {
class AnyOfValidatorTest {
@Test
void invalidTypeShouldThrowJsonSchemaException() {
String schemaData = "{\r\n"
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/com/networknt/schema/CollectorContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class CollectorContextTest {
class CollectorContextTest {

private static final String SAMPLE_COLLECTOR = "sampleCollector";

Expand All @@ -46,13 +46,13 @@ public class CollectorContextTest {
private JsonSchema jsonSchemaForCombine;

@BeforeEach
public void setup() throws Exception {
void setup() throws Exception {
setupSchema();
}

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

@SuppressWarnings("unchecked")
@Test
public void testCollectorContextWithMultipleThreads() throws Exception {
void testCollectorContextWithMultipleThreads() throws Exception {

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

@SuppressWarnings("unchecked")
@Test
public void testCollectorGetAll() throws JsonMappingException, JsonProcessingException, IOException {
void testCollectorGetAll() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ExecutionContext executionContext = jsonSchemaForCombine.createExecutionContext();
executionContext.getExecutionConfig().setFormatAssertionsEnabled(true);
Expand Down Expand Up @@ -218,9 +218,9 @@ private String getSchemaStringMultipleProperties() {

private class ValidationThread implements Runnable {

private String data;
private final String data;

private String name;
private final String name;

private ValidationResult validationResult;

Expand Down Expand Up @@ -379,7 +379,7 @@ public Set<ValidationMessage> walk(ExecutionContext executionContext, JsonNode n
}
}

private ValidationResult validate(String jsonData) throws JsonMappingException, JsonProcessingException, Exception {
private ValidationResult validate(String jsonData) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
ExecutionContext executionContext = this.jsonSchema.createExecutionContext();
Set<ValidationMessage> messages = this.jsonSchema.validate(executionContext, objectMapper.readTree(jsonData));
Expand Down Expand Up @@ -427,7 +427,7 @@ public JsonValidator newValidator(SchemaLocation schemaLocation, JsonNodePath ev
}

private class CollectValidator extends AbstractJsonValidator {
public CollectValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonNode schemaNode) {
CollectValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonNode schemaNode) {
super(schemaLocation, evaluationPath, new CollectKeyword(), schemaNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* ContentSchemaValidatorTest.
*/
public class ContentSchemaValidatorTest {
class ContentSchemaValidatorTest {
@Test
void annotationCollection() throws JsonProcessingException {
String schemaData = "{\r\n"
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/networknt/schema/CustomMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.stream.Stream;

@DisplayName("Custom Messages")
public class CustomMessageTest extends AbstractJsonSchemaTestSuite {
class CustomMessageTest extends AbstractJsonSchemaTestSuite {

@TestFactory
@DisplayName("Draft 2019-09 - Custom Messages Enabled")
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/com/networknt/schema/CustomMetaSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.networknt.schema;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
Expand All @@ -29,7 +28,7 @@

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

public class CustomMetaSchemaTest {
class CustomMetaSchemaTest {

/**
* Introduces the keyword "enumNames".
Expand All @@ -41,7 +40,7 @@ public class CustomMetaSchemaTest {
*
* @author klaskalass
*/
public static class EnumNamesKeyword extends AbstractKeyword {
static class EnumNamesKeyword extends AbstractKeyword {

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


public EnumNamesKeyword() {
EnumNamesKeyword() {
super("enumNames");
}

Expand Down Expand Up @@ -115,7 +114,7 @@ private List<String> readStringList(JsonNode node) {
}

@Test
public void customMetaSchemaWithIgnoredKeyword() throws JsonProcessingException, IOException {
void customMetaSchemaWithIgnoredKeyword() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
final JsonMetaSchema metaSchema = JsonMetaSchema
.builder("https://github.com/networknt/json-schema-validator/tests/schemas/example01", JsonMetaSchema.getV4())
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/networknt/schema/CustomUriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class CustomUriTest {
class CustomUriTest {
@Test
public void customUri() throws Exception {
void customUri() throws Exception {
/* Given */
final JsonSchemaFactory factory = buildJsonSchemaFactory();
final JsonSchema schema = factory.getSchema(
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/networknt/schema/CyclicDependencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

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

public class CyclicDependencyTest {
class CyclicDependencyTest {

@Test
public void whenDependencyBetweenSchemaThenValidationSuccessful() throws Exception {
void whenDependencyBetweenSchemaThenValidationSuccessful() throws Exception {

JsonSchemaFactory schemaFactory = JsonSchemaFactory
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/networknt/schema/DateTimeDSTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.io.InputStream;
import java.util.Set;

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

@Test
public void shouldWorkV7() throws Exception {
void shouldWorkV7() throws Exception {
String schemaPath = "/schema/dateTimeArray.json";
String dataPath = "/data/dstTimes.json"; // Contains 2020 DST changes for various countries
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Tests for the non-standard DefaultJsonSchemaIdValidator.
*/
public class DefaultJsonSchemaIdValidatorTest {
class DefaultJsonSchemaIdValidatorTest {
@Test
void givenRelativeIdShouldThrowInvalidSchemaException() {
String schema = "{\r\n" + " \"$id\": \"0\",\r\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class DependentRequiredTest {

public static final String SCHEMA =
static final String SCHEMA =
"{ " +
" \"$schema\":\"https://json-schema.org/draft/2019-09/schema\"," +
" \"type\": \"object\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Test for discriminator.
*/
public class DiscriminatorValidatorTest {
class DiscriminatorValidatorTest {
/**
* Issue 609.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

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

public class DurationFormatValidatorTest {
class DurationFormatValidatorTest {

@Test
public void durationFormatValidatorTest() throws JsonProcessingException, IOException {
void durationFormatValidatorTest() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
final String schema = "{\"type\": \"string\", \"format\": \"duration\"}\n";
final JsonNode validTargetNode = objectMapper.readTree("\"P1D\"");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/networknt/schema/ExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import com.networknt.schema.SpecVersion.VersionFlag;

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

@Test
public void exampleClasspath() throws Exception {
void exampleClasspath() {
// This creates a schema factory that will use Draft 2012-12 as the default if $schema is not specified in the initial schema
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Test ExclusiveMinimumValidator validator.
*/
public class ExclusiveMinimumValidatorTest {
class ExclusiveMinimumValidatorTest {
@Test
void draftV4ShouldHaveExclusiveMinimum() {
String schemaData = "{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.networknt.schema.SpecVersion.VersionFlag;

public class FormatKeywordFactoryTest {
class FormatKeywordFactoryTest {

public static class CustomFormatKeyword extends FormatKeyword {
public CustomFormatKeyword(Map<String, Format> formats) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/networknt/schema/FormatValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Test for format validator.
*/
public class FormatValidatorTest {
class FormatValidatorTest {
@Test
void unknownFormatNoVocab() {
String schemaData = "{\r\n"
Expand Down Expand Up @@ -180,10 +180,10 @@ void patternFormatDeprecated() {
assertEquals(": does not match the custom pattern must be test", messages.iterator().next().getMessage());
}

public static class CustomNumberFormat implements Format {
static class CustomNumberFormat implements Format {
private final BigDecimal compare;

public CustomNumberFormat(BigDecimal compare) {
CustomNumberFormat(BigDecimal compare) {
this.compare = compare;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/networknt/schema/HTTPServiceSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

import static io.undertow.Handlers.*;

public abstract class HTTPServiceSupport {
abstract class HTTPServiceSupport {

protected static Undertow server = null;

@BeforeAll
public static void setUp() {
static void setUp() {
if (server == null) {
PathHandler pathHandler = path(resource(
new FileResourceManager(
Expand Down Expand Up @@ -70,7 +70,7 @@ public static void setUp() {
}

@AfterAll
public static void tearDown() throws Exception {
static void tearDown() throws Exception {
if (server != null) {
try {
Thread.sleep(100);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/networknt/schema/Issue1091Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.serialization.JsonMapperFactory;

public class Issue1091Test {
class Issue1091Test {
@Test
@Disabled // Disabled as this test takes quite long to run for ci
void testHasAdjacentKeywordInEvaluationPath() throws Exception {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/networknt/schema/Issue255Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.InputStream;
import java.util.Set;

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

@Test
public void shouldFailWhenRequiredPropertiesDoNotExistInReferencedSubSchema() throws Exception {
void shouldFailWhenRequiredPropertiesDoNotExistInReferencedSubSchema() throws Exception {
String schemaPath = "/draft2019-09/issue255.json";
String dataPath = "/data/issue255.json";
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
Expand Down
Loading

0 comments on commit d4d0bb3

Please sign in to comment.