Skip to content

Commit

Permalink
Merge pull request everit-org#385 from gstoupis/feat/issue-349
Browse files Browse the repository at this point in the history
feat: migrate unit tests to JUnit 5 everit-org#349
  • Loading branch information
erosb authored Oct 8, 2020
2 parents 786e04e + 0c067a6 commit 5f2e54c
Show file tree
Hide file tree
Showing 86 changed files with 723 additions and 770 deletions.
22 changes: 11 additions & 11 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jacoco.version>0.8.4</jacoco.version>
<jacoco.version>0.8.6</jacoco.version>
</properties>
<name>everit-org/json-schema</name>
<url>https://github.com/everit-org/json-schema</url>
Expand Down Expand Up @@ -93,7 +93,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.20</version>
<version>2.22.2</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
</configuration>
Expand Down Expand Up @@ -228,9 +228,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -262,12 +262,6 @@
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.damnhandy</groupId>
<artifactId>handy-uri-templates</artifactId>
Expand All @@ -278,6 +272,12 @@
<artifactId>re2j</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
13 changes: 8 additions & 5 deletions core/src/test/java/org/everit/json/schema/ArraySchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import static org.everit.json.schema.JSONMatcher.sameJsonAs;
import static org.everit.json.schema.TestSupport.buildWithLocation;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
Expand Down Expand Up @@ -125,10 +126,12 @@ public void nonUniqueArrayOfArrays() {
.expect();
}

@Test(expected = SchemaException.class)
@Test
public void tupleAndListFailure() {
ArraySchema.builder().addItemSchema(BooleanSchema.INSTANCE).allItemSchema(NullSchema.INSTANCE)
.build();
assertThrows(SchemaException.class, () -> {
ArraySchema.builder().addItemSchema(BooleanSchema.INSTANCE).allItemSchema(NullSchema.INSTANCE)
.build();
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BooleanSchemaTest {

Expand All @@ -37,7 +37,7 @@ public void success() {

@Test
public void toStringTest() {
Assert.assertEquals("{\"type\":\"boolean\"}", BooleanSchema.INSTANCE.toString());
Assertions.assertEquals("{\"type\":\"boolean\"}", BooleanSchema.INSTANCE.toString());
}

public void equalsVerifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import static java.util.Arrays.asList;
import static org.everit.json.schema.ValidationException.createWrappingException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.*;

import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CollectingFailureReporterTest {

Expand All @@ -20,9 +18,11 @@ public void noNewExceptions_returnsNull() {
assertNull(actual);
}

@Test(expected = NullPointerException.class)
@Test
public void subSchemaIsNull() {
createSubject().inContextOfSchema(null, () -> {
assertThrows(NullPointerException.class, () -> {
createSubject().inContextOfSchema(null, () -> {
});
});
}

Expand Down
39 changes: 23 additions & 16 deletions core/src/test/java/org/everit/json/schema/CombinedSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,55 @@

import static java.util.Arrays.asList;
import static org.everit.json.schema.JSONMatcher.sameJsonAs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.jupiter.api.Test;

public class CombinedSchemaTest {

private static final List<Schema> SUBSCHEMAS = asList(
NumberSchema.builder().multipleOf(10).build(),
NumberSchema.builder().multipleOf(3).build());

@Test(expected = ValidationException.class)
@Test
public void allCriterionFailure() {
CombinedSchema.ALL_CRITERION.validate(10, 1);
assertThrows(ValidationException.class, () -> {
CombinedSchema.ALL_CRITERION.validate(10, 1);
});
}

@Test
public void allCriterionSuccess() {
CombinedSchema.ALL_CRITERION.validate(10, 10);
}

@Test(expected = ValidationException.class)
@Test
public void anyCriterionFailure() {
CombinedSchema.ANY_CRITERION.validate(10, 0);
assertThrows(ValidationException.class, () -> {
CombinedSchema.ANY_CRITERION.validate(10, 0);
});
}

@Test
public void anyCriterionSuccess() {
CombinedSchema.ANY_CRITERION.validate(10, 1);
}

@Test(expected = ValidationException.class)
@Test
public void anyOfInvalid() {
CombinedSchema.anyOf(asList(
StringSchema.builder().maxLength(2).build(),
StringSchema.builder().minLength(4).build()))
.build().validate("foo");
assertThrows(ValidationException.class, () -> {
CombinedSchema.anyOf(asList(
StringSchema.builder().maxLength(2).build(),
StringSchema.builder().minLength(4).build()))
.build().validate("foo");
});
}

@Test
Expand All @@ -70,9 +75,11 @@ public void factories() {
CombinedSchema.oneOf(asList(BooleanSchema.INSTANCE));
}

@Test(expected = ValidationException.class)
@Test
public void oneCriterionFailure() {
CombinedSchema.ONE_CRITERION.validate(10, 2);
assertThrows(ValidationException.class, () -> {
CombinedSchema.ONE_CRITERION.validate(10, 2);
});
}

@Test
Expand Down Expand Up @@ -108,7 +115,7 @@ public void validateOne() {
public void reportCauses() {
try {
CombinedSchema.allOf(SUBSCHEMAS).build().validate(24);
Assert.fail("did not throw exception");
fail("did not throw exception");
} catch (ValidationException e) {
assertEquals(1, e.getCausingExceptions().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@
import static org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword.ELSE;
import static org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword.IF;
import static org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword.THEN;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.*;

import org.everit.json.schema.event.ConditionalSchemaMatchEvent;
import org.everit.json.schema.event.ConditionalSchemaMismatchEvent;
import org.everit.json.schema.event.ValidationListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@RunWith(MockitoJUnitRunner.class)
public class ConditionalSchemaEventsTest {

private ConditionalSchema schema = ConditionalSchema.builder().ifSchema(PATTERN_STRING_SCHEMA)
.thenSchema(MIN_LENGTH_STRING_SCHEMA)
.elseSchema(MAX_LENGTH_STRING_SCHEMA).schemaLocation("#").build();

@Mock
ValidationListener listener;
ValidationListener listener = mock(ValidationListener.class);

private ValidationFailureReporter reporter;

@Before public void before() {
@BeforeEach
public void before() {
reporter = new CollectingFailureReporter(schema);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.everit.json.schema;

import static org.everit.json.schema.JSONMatcher.sameJsonAs;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConditionalSchemaTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.everit.json.schema;

import static org.everit.json.schema.TestSupport.loadAsV6;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConstSchemaTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.everit.json.schema;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;

public class EarlyFailingFailureReporterTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package org.everit.json.schema;

import static org.junit.Assert.assertEquals;

import org.json.JSONObject;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.jupiter.api.Test;

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

public class EmptySchemaTest {

Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/org/everit/json/schema/EnumSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.everit.json.schema;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -28,17 +28,17 @@
import org.everit.json.schema.internal.JSONPrinter;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EnumSchemaTest {

private List<Object> possibleValues;

@Before
@BeforeEach
public void before() {
possibleValues = new ArrayList<>();
possibleValues.add(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.everit.json.schema;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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

/**
* @author erosb
Expand Down
Loading

0 comments on commit 5f2e54c

Please sign in to comment.