diff --git a/core/pom.xml b/core/pom.xml index d13791909..edefe080f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -27,7 +27,7 @@ UTF-8 1.8 1.8 - 0.8.4 + 0.8.6 everit-org/json-schema https://github.com/everit-org/json-schema @@ -93,7 +93,7 @@ maven-surefire-plugin org.apache.maven.plugins - 2.20 + 2.22.2 ${surefireArgLine} @@ -228,9 +228,9 @@ test - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter + 5.7.0 test @@ -262,12 +262,6 @@ 3.0.3 test - - pl.pragmatists - JUnitParams - 1.1.0 - test - com.damnhandy handy-uri-templates @@ -278,6 +272,12 @@ re2j 1.3 + + org.hamcrest + hamcrest-core + 1.3 + test + diff --git a/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java b/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java index 47df2bede..c59a7222f 100644 --- a/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ArraySchemaTest.java @@ -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; @@ -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 diff --git a/core/src/test/java/org/everit/json/schema/BooleanSchemaTest.java b/core/src/test/java/org/everit/json/schema/BooleanSchemaTest.java index a239f66a3..94f5ed5d2 100644 --- a/core/src/test/java/org/everit/json/schema/BooleanSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/BooleanSchemaTest.java @@ -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 { @@ -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() { diff --git a/core/src/test/java/org/everit/json/schema/CollectingFailureReporterTest.java b/core/src/test/java/org/everit/json/schema/CollectingFailureReporterTest.java index 51686a929..39bb1a9f5 100644 --- a/core/src/test/java/org/everit/json/schema/CollectingFailureReporterTest.java +++ b/core/src/test/java/org/everit/json/schema/CollectingFailureReporterTest.java @@ -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 { @@ -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, () -> { + }); }); } diff --git a/core/src/test/java/org/everit/json/schema/CombinedSchemaTest.java b/core/src/test/java/org/everit/json/schema/CombinedSchemaTest.java index 296539ed3..0237a07c8 100644 --- a/core/src/test/java/org/everit/json/schema/CombinedSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/CombinedSchemaTest.java @@ -17,17 +17,16 @@ 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 { @@ -35,9 +34,11 @@ public class CombinedSchemaTest { 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 @@ -45,9 +46,11 @@ 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 @@ -55,12 +58,14 @@ 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 @@ -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 @@ -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()); } diff --git a/core/src/test/java/org/everit/json/schema/ConditionalSchemaEventsTest.java b/core/src/test/java/org/everit/json/schema/ConditionalSchemaEventsTest.java index 2bab98a02..fe3cac82f 100644 --- a/core/src/test/java/org/everit/json/schema/ConditionalSchemaEventsTest.java +++ b/core/src/test/java/org/everit/json/schema/ConditionalSchemaEventsTest.java @@ -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); } diff --git a/core/src/test/java/org/everit/json/schema/ConditionalSchemaTest.java b/core/src/test/java/org/everit/json/schema/ConditionalSchemaTest.java index 910898061..5be4adb8d 100644 --- a/core/src/test/java/org/everit/json/schema/ConditionalSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ConditionalSchemaTest.java @@ -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 { diff --git a/core/src/test/java/org/everit/json/schema/ConstSchemaTest.java b/core/src/test/java/org/everit/json/schema/ConstSchemaTest.java index 54a0ecce7..1275ac2ea 100644 --- a/core/src/test/java/org/everit/json/schema/ConstSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ConstSchemaTest.java @@ -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 { diff --git a/core/src/test/java/org/everit/json/schema/EarlyFailingFailureReporterTest.java b/core/src/test/java/org/everit/json/schema/EarlyFailingFailureReporterTest.java index 608f1b839..3869c7ad4 100644 --- a/core/src/test/java/org/everit/json/schema/EarlyFailingFailureReporterTest.java +++ b/core/src/test/java/org/everit/json/schema/EarlyFailingFailureReporterTest.java @@ -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 { diff --git a/core/src/test/java/org/everit/json/schema/EmptySchemaTest.java b/core/src/test/java/org/everit/json/schema/EmptySchemaTest.java index e293061c1..18ef805ec 100644 --- a/core/src/test/java/org/everit/json/schema/EmptySchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/EmptySchemaTest.java @@ -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 { diff --git a/core/src/test/java/org/everit/json/schema/EnumSchemaTest.java b/core/src/test/java/org/everit/json/schema/EnumSchemaTest.java index 0467a0c1e..6647087bd 100644 --- a/core/src/test/java/org/everit/json/schema/EnumSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/EnumSchemaTest.java @@ -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; @@ -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 possibleValues; - @Before + @BeforeEach public void before() { possibleValues = new ArrayList<>(); possibleValues.add(true); diff --git a/core/src/test/java/org/everit/json/schema/FalseSchemaTest.java b/core/src/test/java/org/everit/json/schema/FalseSchemaTest.java index ad972e299..4d10b2040 100644 --- a/core/src/test/java/org/everit/json/schema/FalseSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/FalseSchemaTest.java @@ -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 diff --git a/core/src/test/java/org/everit/json/schema/FormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/FormatValidatorTest.java index b85958926..a497ee322 100644 --- a/core/src/test/java/org/everit/json/schema/FormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/FormatValidatorTest.java @@ -15,42 +15,24 @@ */ package org.everit.json.schema; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import java.util.Arrays; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(Parameterized.class) public class FormatValidatorTest { - @Parameters(name = "{0}") - public static List params() { - return Arrays.asList( - new Object[] { "date-time" }, - new Object[] { "email" }, - new Object[] { "hostname" }, - new Object[] { "ipv6" }, - new Object[] { "ipv4" }, - new Object[] { "uri" } - ); - } - - private final String formatName; - - public FormatValidatorTest(final String formatName) { - this.formatName = formatName; - } - - @Test - public void check() { + @ParameterizedTest + @ValueSource(strings = {"date-time", "email", "hostname", "ipv6", "ipv4", "uri"}) + public void check(String formatName) { FormatValidator.forFormat(formatName); } - @Test(expected = NullPointerException.class) + @Test public void nullFormat() { - FormatValidator.forFormat(null); + assertThrows(NullPointerException.class, () -> { + FormatValidator.forFormat(null); + }); } } diff --git a/core/src/test/java/org/everit/json/schema/InternalValidationExceptionTest.java b/core/src/test/java/org/everit/json/schema/InternalValidationExceptionTest.java index dec5c767c..0b11c3469 100644 --- a/core/src/test/java/org/everit/json/schema/InternalValidationExceptionTest.java +++ b/core/src/test/java/org/everit/json/schema/InternalValidationExceptionTest.java @@ -1,8 +1,9 @@ package org.everit.json.schema; -import static org.junit.Assert.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class InternalValidationExceptionTest { diff --git a/core/src/test/java/org/everit/json/schema/JSONPointerTest.java b/core/src/test/java/org/everit/json/schema/JSONPointerTest.java index ca570f121..7a136159b 100644 --- a/core/src/test/java/org/everit/json/schema/JSONPointerTest.java +++ b/core/src/test/java/org/everit/json/schema/JSONPointerTest.java @@ -1,10 +1,5 @@ package org.everit.json.schema; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.io.InputStream; import org.json.JSONArray; @@ -12,8 +7,10 @@ import org.json.JSONPointer; import org.json.JSONPointerException; import org.json.JSONTokener; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /** * This class is ported from https://raw.githubusercontent.com/stleary/JSON-Java-unit-test/ @@ -40,9 +37,11 @@ public void emptyPointer() { assertSame(document, query("")); } - @Test(expected = NullPointerException.class) + @Test public void nullPointer() { - new JSONPointer((String) null); + assertThrows(NullPointerException.class, () -> { + new JSONPointer((String) null); + }); } @Test @@ -55,9 +54,11 @@ public void arrayIndexQuery() { assertSame(document.getJSONArray("foo").get(0), query("/foo/0")); } - @Test(expected = JSONPointerException.class) + @Test public void stringPropOfArrayFailure() { - query("/foo/bar"); + assertThrows(JSONPointerException.class, () -> { + query("/foo/bar"); + }); } @Test @@ -65,12 +66,12 @@ public void queryByEmptyKey() { assertSame(document.get(""), query("/")); } - @Test @Ignore + @Test @Disabled public void queryByEmptyKeySubObject() { assertSame(document.getJSONObject("obj").getJSONObject(""), query("/obj/")); } - @Test @Ignore + @Test @Disabled public void queryByEmptyKeySubObjectSubOject() { assertSame( document.getJSONObject("obj").getJSONObject("").get(""), @@ -129,19 +130,25 @@ public void uriFragmentPercentHandling() { assertSame(document.get("m~n"), query("#/m~0n")); } - @Test(expected = IllegalArgumentException.class) + @Test public void syntaxError() { - new JSONPointer("key"); + assertThrows(IllegalArgumentException.class, () -> { + new JSONPointer("key"); + }); } - @Test(expected = JSONPointerException.class) + @Test public void arrayIndexFailure() { - query("/foo/2"); + assertThrows(JSONPointerException.class, () -> { + query("/foo/2"); + }); } - @Test(expected = JSONPointerException.class) + @Test public void primitiveFailure() { - query("/obj/key/failure"); + assertThrows(JSONPointerException.class, () -> { + query("/obj/key/failure"); + }); } @Test @@ -154,9 +161,11 @@ public void builderTest() { assertEquals("val", pointer.queryFrom(document)); } - @Test(expected = NullPointerException.class) + @Test public void nullToken() { - JSONPointer.builder().append(null); + assertThrows(NullPointerException.class, () -> { + JSONPointer.builder().append(null); + }); } @Test @@ -209,18 +218,17 @@ public void queryFromJSONObject() { "}"; JSONObject jsonObject = new JSONObject(str); Object obj = jsonObject.query("/stringKey"); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonObject.query("/arrayKey/1"); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonObject.query("/objectKey/b"); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); try { obj = jsonObject.query("/a/b/c"); - assertTrue("Expected JSONPointerException", false); + assertTrue(false,"Expected JSONPointerException"); } catch (JSONPointerException e) { - assertTrue("Expected bad key/value exception", - "value [null] is not an array or object therefore its key b cannot be resolved". - equals(e.getMessage())); + assertTrue( "value [null] is not an array or object therefore its key b cannot be resolved". + equals(e.getMessage()), "Expected bad key/value exception"); } } @@ -239,18 +247,17 @@ public void queryFromJSONObjectUsingPointer() { "}"; JSONObject jsonObject = new JSONObject(str); Object obj = jsonObject.query(new JSONPointer("/stringKey")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonObject.query(new JSONPointer("/arrayKey/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonObject.query(new JSONPointer("/objectKey/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); try { obj = jsonObject.query(new JSONPointer("/a/b/c")); - assertTrue("Expected JSONPointerException", false); + assertTrue(false, "Expected JSONPointerException"); } catch (JSONPointerException e) { - assertTrue("Expected bad key/value exception", - "value [null] is not an array or object therefore its key b cannot be resolved". - equals(e.getMessage())); + assertTrue("value [null] is not an array or object therefore its key b cannot be resolved". + equals(e.getMessage()), "Expected bad key/value exception"); } } @@ -269,13 +276,13 @@ public void optQueryFromJSONObjectUsingPointer() { "}"; JSONObject jsonObject = new JSONObject(str); Object obj = jsonObject.optQuery(new JSONPointer("/stringKey")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonObject.optQuery(new JSONPointer("/arrayKey/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonObject.optQuery(new JSONPointer("/objectKey/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); obj = jsonObject.optQuery(new JSONPointer("/a/b/c")); - assertTrue("Expected null", obj == null); + assertTrue(obj == null, "Expected null"); } /** @@ -293,17 +300,16 @@ public void queryFromJSONArray() { "]"; JSONArray jsonArray = new JSONArray(str); Object obj = jsonArray.query("/0"); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonArray.query("/1/1"); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonArray.query("/2/b"); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); try { obj = jsonArray.query("/a/b/c"); - assertTrue("Expected JSONPointerException", false); + assertTrue(false, "Expected JSONPointerException"); } catch (JSONPointerException e) { - assertTrue("Expected bad index exception", - "a is not an array index".equals(e.getMessage())); + assertTrue("a is not an array index".equals(e.getMessage()), "Expected bad index exception"); } } @@ -322,17 +328,16 @@ public void queryFromJSONArrayUsingPointer() { "]"; JSONArray jsonArray = new JSONArray(str); Object obj = jsonArray.query(new JSONPointer("/0")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonArray.query(new JSONPointer("/1/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonArray.query(new JSONPointer("/2/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); try { obj = jsonArray.query(new JSONPointer("/a/b/c")); - assertTrue("Expected JSONPointerException", false); + assertTrue(false, "Expected JSONPointerException"); } catch (JSONPointerException e) { - assertTrue("Expected bad index exception", - "a is not an array index".equals(e.getMessage())); + assertTrue("a is not an array index".equals(e.getMessage()), "Expected bad index exception"); } } @@ -351,12 +356,12 @@ public void optQueryFromJSONArrayUsingPointer() { "]"; JSONArray jsonArray = new JSONArray(str); Object obj = jsonArray.optQuery(new JSONPointer("/0")); - assertTrue("Expected 'hello world!'", "hello world!".equals(obj)); + assertTrue("hello world!".equals(obj), "Expected 'hello world!'"); obj = jsonArray.optQuery(new JSONPointer("/1/1")); - assertTrue("Expected 1", Integer.valueOf(1).equals(obj)); + assertTrue(Integer.valueOf(1).equals(obj), "Expected 1"); obj = jsonArray.optQuery(new JSONPointer("/2/b")); - assertTrue("Expected bVal", "bVal".equals(obj)); + assertTrue("bVal".equals(obj), "Expected bVal"); obj = jsonArray.optQuery(new JSONPointer("/a/b/c")); - assertTrue("Expected null", obj == null); + assertTrue(obj == null, "Expected null"); } } diff --git a/core/src/test/java/org/everit/json/schema/NotSchemaTest.java b/core/src/test/java/org/everit/json/schema/NotSchemaTest.java index d016a8652..baa106dd8 100644 --- a/core/src/test/java/org/everit/json/schema/NotSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/NotSchemaTest.java @@ -18,14 +18,14 @@ 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; -import org.junit.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class NotSchemaTest { diff --git a/core/src/test/java/org/everit/json/schema/NullSchemaTest.java b/core/src/test/java/org/everit/json/schema/NullSchemaTest.java index 47a9d5043..4be6f097b 100644 --- a/core/src/test/java/org/everit/json/schema/NullSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/NullSchemaTest.java @@ -16,13 +16,13 @@ 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 nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class NullSchemaTest { diff --git a/core/src/test/java/org/everit/json/schema/NullableValidationTest.java b/core/src/test/java/org/everit/json/schema/NullableValidationTest.java index 1fce748cf..ee198506c 100644 --- a/core/src/test/java/org/everit/json/schema/NullableValidationTest.java +++ b/core/src/test/java/org/everit/json/schema/NullableValidationTest.java @@ -1,7 +1,7 @@ package org.everit.json.schema; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NullableValidationTest { diff --git a/core/src/test/java/org/everit/json/schema/NumberSchemaTest.java b/core/src/test/java/org/everit/json/schema/NumberSchemaTest.java index 1b5cbd242..b04196a46 100644 --- a/core/src/test/java/org/everit/json/schema/NumberSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/NumberSchemaTest.java @@ -18,17 +18,17 @@ import static org.everit.json.schema.JSONMatcher.sameJsonAs; import static org.everit.json.schema.TestSupport.buildWithLocation; import static org.everit.json.schema.TestSupport.loadAsV6; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.math.BigInteger; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.everit.json.schema.loader.SchemaLoader; +import org.hamcrest.MatcherAssert; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; @@ -182,7 +182,7 @@ public void equalsVerifier() { public void toStringTest() { JSONObject rawSchemaJson = loader.readObj("numberschema.json"); String actual = SchemaLoader.load(rawSchemaJson).toString(); - assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); + MatcherAssert.assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); } @Test @@ -191,7 +191,7 @@ public void toStringExclusiveLimits() { rawSchemaJson.put("exclusiveMinimum", 5); rawSchemaJson.put("exclusiveMaximum", 10); String actual = loadAsV6(rawSchemaJson).toString(); - assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); + MatcherAssert.assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); } @Test @@ -218,7 +218,7 @@ public void toStringNoExplicitType() { JSONObject rawSchemaJson = loader.readObj("numberschema.json"); rawSchemaJson.remove("type"); String actual = SchemaLoader.load(rawSchemaJson).toString(); - assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); + MatcherAssert.assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); } @Test @@ -226,7 +226,7 @@ public void toStringReqInteger() { JSONObject rawSchemaJson = loader.readObj("numberschema.json"); rawSchemaJson.put("type", "integer"); String actual = SchemaLoader.load(rawSchemaJson).toString(); - assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); + MatcherAssert.assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); } @Test diff --git a/core/src/test/java/org/everit/json/schema/ObjectComparatorTest.java b/core/src/test/java/org/everit/json/schema/ObjectComparatorTest.java index 8784152e8..7d0054bf5 100644 --- a/core/src/test/java/org/everit/json/schema/ObjectComparatorTest.java +++ b/core/src/test/java/org/everit/json/schema/ObjectComparatorTest.java @@ -1,36 +1,36 @@ package org.everit.json.schema; -import static org.junit.Assert.assertFalse; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import junitparams.naming.TestCaseName; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertFalse; -@RunWith(JUnitParamsRunner.class) public class ObjectComparatorTest { public static final JSONArray EMPTY_ARRAY = new JSONArray(); public static final JSONObject EMPTY_OBJECT = new JSONObject(); - private Object[][] failingCases() { - return new Object[][] { - { "array, null", EMPTY_ARRAY, null }, - { "array, object", EMPTY_ARRAY, EMPTY_OBJECT }, - { "object, null", EMPTY_OBJECT, null }, - { "arrays with different length", EMPTY_ARRAY, new JSONArray("[null]") }, - { "arrays with different elems", new JSONArray("[true, false]"), new JSONArray("[false, true]") }, - { "objects with different length", EMPTY_OBJECT, new JSONObject("{\"a\":true}") } - }; + private static List failingCases() { + return Stream.of( + Arguments.of("array, null", EMPTY_ARRAY, null), + Arguments.of("array, object", EMPTY_ARRAY, EMPTY_OBJECT), + Arguments.of("object, null", EMPTY_OBJECT, null), + Arguments.of("arrays with different length", EMPTY_ARRAY, new JSONArray("[null]")), + Arguments.of("arrays with different elems", new JSONArray("[true, false]"), new JSONArray("[false, true]")), + Arguments.of("objects with different length", EMPTY_OBJECT, new JSONObject("{\"a\":true}")) + ).collect(Collectors.toList()); } - @Test - @Parameters(method = "failingCases") - @TestCaseName("{0} (false)") + @ParameterizedTest + @MethodSource("failingCases") public void array_Null_failure(String testcaseName, Object arg1, Object arg2) { assertFalse(ObjectComparator.deepEquals(arg1, arg2)); assertFalse(ObjectComparator.deepEquals(arg2, arg1)); diff --git a/core/src/test/java/org/everit/json/schema/ObjectSchemaTest.java b/core/src/test/java/org/everit/json/schema/ObjectSchemaTest.java index 833097195..535705a17 100644 --- a/core/src/test/java/org/everit/json/schema/ObjectSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ObjectSchemaTest.java @@ -21,8 +21,7 @@ import static org.everit.json.schema.TestSupport.buildWithLocation; import static org.everit.json.schema.TestSupport.loadAsV6; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import java.util.AbstractMap; import java.util.HashMap; @@ -33,7 +32,7 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; import org.json.JSONPointer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.re2j.Pattern; @@ -348,10 +347,12 @@ public void schemaDepViolation() { OBJECTS.get("schemaDepViolation")); } - @Test(expected = SchemaException.class) + @Test public void schemaForNoAdditionalProperties() { - ObjectSchema.builder().additionalProperties(false) - .schemaOfAdditionalProperties(BooleanSchema.INSTANCE).build(); + assertThrows(SchemaException.class, () -> { + ObjectSchema.builder().additionalProperties(false) + .schemaOfAdditionalProperties(BooleanSchema.INSTANCE).build(); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/PointerBubblingTest.java b/core/src/test/java/org/everit/json/schema/PointerBubblingTest.java index 1dbb983b0..9ca2ebf82 100644 --- a/core/src/test/java/org/everit/json/schema/PointerBubblingTest.java +++ b/core/src/test/java/org/everit/json/schema/PointerBubblingTest.java @@ -17,8 +17,8 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PointerBubblingTest { @@ -36,12 +36,12 @@ public void rectangleMultipleFailures() { JSONObject input = testInputs.getJSONObject("rectangleMultipleFailures"); try { rectangleSchema.validate(input); - Assert.fail(); + Assertions.fail(); } catch (ValidationException e) { - Assert.assertEquals("#/rectangle", e.getPointerToViolation()); - Assert.assertEquals(2, e.getCausingExceptions().size()); - Assert.assertEquals(1, TestSupport.countCauseByJsonPointer(e, "#/rectangle/a")); - Assert.assertEquals(1, TestSupport.countCauseByJsonPointer(e, "#/rectangle/b")); + Assertions.assertEquals("#/rectangle", e.getPointerToViolation()); + Assertions.assertEquals(2, e.getCausingExceptions().size()); + Assertions.assertEquals(1, TestSupport.countCauseByJsonPointer(e, "#/rectangle/a")); + Assertions.assertEquals(1, TestSupport.countCauseByJsonPointer(e, "#/rectangle/b")); } } diff --git a/core/src/test/java/org/everit/json/schema/ReferenceSchemaTest.java b/core/src/test/java/org/everit/json/schema/ReferenceSchemaTest.java index 68456fd11..b95e6e4a6 100644 --- a/core/src/test/java/org/everit/json/schema/ReferenceSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/ReferenceSchemaTest.java @@ -17,19 +17,17 @@ import static java.util.Collections.emptyMap; import static org.everit.json.schema.TestSupport.buildWithLocation; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import org.everit.json.schema.ReferenceSchema.Builder; import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; import com.google.common.collect.ImmutableMap; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class ReferenceSchemaTest { @@ -38,14 +36,16 @@ public class ReferenceSchemaTest { @Test public void constructorMustRunOnlyOnce() { Builder builder = ReferenceSchema.builder(); - Assert.assertSame(builder.build(), builder.build()); + assertSame(builder.build(), builder.build()); } - @Test(expected = IllegalStateException.class) + @Test public void setterShouldWorkOnlyOnce() { - ReferenceSchema subject = ReferenceSchema.builder().build(); - subject.setReferredSchema(BooleanSchema.INSTANCE); - subject.setReferredSchema(BooleanSchema.INSTANCE); + assertThrows(IllegalStateException.class, () -> { + ReferenceSchema subject = ReferenceSchema.builder().build(); + subject.setReferredSchema(BooleanSchema.INSTANCE); + subject.setReferredSchema(BooleanSchema.INSTANCE); + }); } @Test @@ -60,16 +60,20 @@ public void validationShouldDelegateToReferredSchema() { .expect(); } - @Test(expected = IllegalStateException.class) + @Test public void validateThrowsExc_IfNoReferredSchemaIsSet() { - ReferenceSchema subject = ReferenceSchema.builder().build(); - subject.validate(null); + assertThrows(IllegalStateException.class, () -> { + ReferenceSchema subject = ReferenceSchema.builder().build(); + subject.validate(null); + }); } - @Test(expected = IllegalStateException.class) + @Test public void definesPropertyThrowsExc_IfNoReferredSchemaIsSet() { - ReferenceSchema subject = ReferenceSchema.builder().build(); - subject.definesProperty("propName"); + assertThrows(IllegalStateException.class, () -> { + ReferenceSchema subject = ReferenceSchema.builder().build(); + subject.definesProperty("propName"); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/SchemaExceptionTest.java b/core/src/test/java/org/everit/json/schema/SchemaExceptionTest.java index 175156a30..9f568daa7 100644 --- a/core/src/test/java/org/everit/json/schema/SchemaExceptionTest.java +++ b/core/src/test/java/org/everit/json/schema/SchemaExceptionTest.java @@ -1,14 +1,13 @@ package org.everit.json.schema; import org.json.JSONPointer; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.Map; import static org.everit.json.schema.SchemaException.buildMessage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author erosb @@ -17,9 +16,6 @@ public class SchemaExceptionTest { private static final Class INTEGER_CLASS = Integer.class; - @Rule - public final ExpectedException expExc = ExpectedException.none(); - @Test public void testBuildMessageSingleExcType() { String actual = buildMessage(JSONPointer.builder().build().toURIFragment(), INTEGER_CLASS, String.class); @@ -28,9 +24,10 @@ public void testBuildMessageSingleExcType() { @Test public void nullJSONPointer() { - expExc.expect(NullPointerException.class); - expExc.expectMessage("pointer cannot be null"); - buildMessage(null, INTEGER_CLASS, String.class); + NullPointerException thrown = assertThrows(NullPointerException.class, () -> { + buildMessage(null, INTEGER_CLASS, String.class); + }); + assertEquals("pointer cannot be null", thrown.getMessage()); } @Test diff --git a/core/src/test/java/org/everit/json/schema/SchemaLocationTest.java b/core/src/test/java/org/everit/json/schema/SchemaLocationTest.java index 2a0ccabaa..3d8e8521d 100644 --- a/core/src/test/java/org/everit/json/schema/SchemaLocationTest.java +++ b/core/src/test/java/org/everit/json/schema/SchemaLocationTest.java @@ -3,16 +3,17 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import org.junit.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class SchemaLocationTest { @@ -61,9 +62,11 @@ public void toString_uri_noPointer() { assertEquals("http://example.com/hello", underTest.toString()); } - @Test(expected = NullPointerException.class) + @Test public void parseURI_null() { - SchemaLocation.parseURI(null); + assertThrows(NullPointerException.class, () -> { + SchemaLocation.parseURI(null); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/StringSchemaTest.java b/core/src/test/java/org/everit/json/schema/StringSchemaTest.java index 9c70cb28a..d6eacdaf7 100644 --- a/core/src/test/java/org/everit/json/schema/StringSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/StringSchemaTest.java @@ -3,21 +3,19 @@ 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.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; import java.util.Optional; import org.everit.json.schema.loader.SchemaLoader; import org.everit.json.schema.regexp.RE2JRegexpFactory; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; import com.google.re2j.Pattern; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class StringSchemaTest { @@ -63,9 +61,9 @@ public void minLength() { public void multipleViolations() { try { StringSchema.builder().minLength(3).maxLength(1).pattern("^b.*").build().validate("ab"); - Assert.fail(); + fail(); } catch (ValidationException e) { - Assert.assertEquals(3, e.getCausingExceptions().size()); + assertEquals(3, e.getCausingExceptions().size()); } } @@ -98,9 +96,11 @@ public void typeFailure() { .expect(); } - @Test(expected = ValidationException.class) + @Test public void issue38Pattern() { - StringSchema.builder().requiresString(true).pattern("\\+?\\d+").build().validate("aaa"); + assertThrows(ValidationException.class, () -> { + StringSchema.builder().requiresString(true).pattern("\\+?\\d+").build().validate("aaa"); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/TestSupport.java b/core/src/test/java/org/everit/json/schema/TestSupport.java index 42274db23..96944b2a7 100644 --- a/core/src/test/java/org/everit/json/schema/TestSupport.java +++ b/core/src/test/java/org/everit/json/schema/TestSupport.java @@ -16,11 +16,11 @@ package org.everit.json.schema; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/core/src/test/java/org/everit/json/schema/ToStringTest.java b/core/src/test/java/org/everit/json/schema/ToStringTest.java index b4e2a0c5a..12f9d6406 100644 --- a/core/src/test/java/org/everit/json/schema/ToStringTest.java +++ b/core/src/test/java/org/everit/json/schema/ToStringTest.java @@ -2,17 +2,17 @@ import static org.everit.json.schema.FalseSchema.INSTANCE; 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.assertEquals; import java.io.StringWriter; import org.everit.json.schema.internal.JSONPrinter; import org.json.JSONObject; -import org.junit.Ignore; -import org.junit.Test; import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ToStringTest { @@ -75,7 +75,7 @@ public void testArraySchema() { } @Test - @Ignore("throws JSONException - bug in JSONWriter") + @Disabled("throws JSONException - bug in JSONWriter") public void testFalseSchema() { StringWriter w = new StringWriter(); JSONPrinter writer = new JSONPrinter(w); diff --git a/core/src/test/java/org/everit/json/schema/TrueSchemaTest.java b/core/src/test/java/org/everit/json/schema/TrueSchemaTest.java index 86b7e1f29..9e4aa3ca6 100644 --- a/core/src/test/java/org/everit/json/schema/TrueSchemaTest.java +++ b/core/src/test/java/org/everit/json/schema/TrueSchemaTest.java @@ -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 diff --git a/core/src/test/java/org/everit/json/schema/ValidatingVisitorTest.java b/core/src/test/java/org/everit/json/schema/ValidatingVisitorTest.java index 181b3a259..e58257c98 100644 --- a/core/src/test/java/org/everit/json/schema/ValidatingVisitorTest.java +++ b/core/src/test/java/org/everit/json/schema/ValidatingVisitorTest.java @@ -1,7 +1,6 @@ package org.everit.json.schema; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; @@ -15,19 +14,17 @@ import org.everit.json.schema.event.ValidationListener; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; - -@RunWith(JUnitParamsRunner.class) public class ValidatingVisitorTest { private ValidationFailureReporter reporter; - @Before + @BeforeEach public void before() { reporter = mock(ValidationFailureReporter.class); } @@ -81,40 +78,42 @@ public void passesTypeCheck_sameType() { verifyZeroInteractions(reporter); } - public Object[] permittedTypes() { - return new Object[] { - new Object[] { "str" }, - new Object[] { 1 }, - new Object[] { 1L }, - new Object[] { 1.0 }, - new Object[] { 1.0f }, - new Object[] { new BigInteger("42") }, - new Object[] { new BigDecimal("42.3") }, - new Object[] { true }, - new Object[] { null }, - new Object[] { JSONObject.NULL }, - new Object[] { new JSONObject("{}") }, - new Object[] { new JSONArray("[]") }, + public static Arguments[] permittedTypes() { + return new Arguments[] { + Arguments.of(new Object[]{"str"}), + Arguments.of(new Object[]{1}), + Arguments.of(new Object[]{1L}), + Arguments.of(new Object[]{1.0}), + Arguments.of(new Object[]{1.0f}), + Arguments.of(new Object[]{new BigInteger("42")}), + Arguments.of(new Object[]{new BigDecimal("42.3")}), + Arguments.of(new Object[]{true}), + Arguments.of(new Object[]{null}), + Arguments.of(new Object[]{JSONObject.NULL}), + Arguments.of(new Object[]{new JSONObject("{}")}), + Arguments.of(new Object[]{new JSONArray("[]")}) }; } - public Object[] notPermittedTypes() { - return new Object[] { - new Object[] { new ArrayList() }, - new Object[] { new RuntimeException() } + public static Arguments[] notPermittedTypes() { + return new Arguments[] { + Arguments.of(new Object[] { new ArrayList() }), + Arguments.of(new Object[] { new RuntimeException() }) }; } - @Test - @Parameters(method = "permittedTypes") + @ParameterizedTest + @MethodSource("permittedTypes") public void permittedTypeSuccess(Object subject) { new ValidatingVisitor(subject, reporter, ReadWriteValidator.NONE, null); } - @Test(expected = IllegalArgumentException.class) - @Parameters(method = "notPermittedTypes") + @ParameterizedTest + @MethodSource("notPermittedTypes") public void notPermittedTypeFailure(Object subject) { - new ValidatingVisitor(subject, reporter, ReadWriteValidator.NONE, null); + assertThrows(IllegalArgumentException.class, () -> { + new ValidatingVisitor(subject, reporter, ReadWriteValidator.NONE, null); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/ValidationExceptionTest.java b/core/src/test/java/org/everit/json/schema/ValidationExceptionTest.java index 3bab5e032..64db15226 100644 --- a/core/src/test/java/org/everit/json/schema/ValidationExceptionTest.java +++ b/core/src/test/java/org/everit/json/schema/ValidationExceptionTest.java @@ -18,15 +18,13 @@ import static java.util.Collections.emptyList; import static org.everit.json.schema.JSONMatcher.sameJsonAs; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ValidationExceptionTest { @@ -68,10 +66,12 @@ public void getMessageAfterPrepend() { assertEquals("#/obj/a: stuff went wrong", subject.getMessage()); } - @Test(expected = NullPointerException.class) + @Test public void nullPointerFragmentFailure() { - new ValidationException(BooleanSchema.INSTANCE, Boolean.class, 2).prepend(null, - NullSchema.INSTANCE); + assertThrows(NullPointerException.class, () -> { + new ValidationException(BooleanSchema.INSTANCE, Boolean.class, 2).prepend(null, + NullSchema.INSTANCE); + }); } @Test @@ -99,7 +99,7 @@ public void prependWithCausingExceptions() { ValidationException cause2 = createDummyException("#/b"); try { ValidationException.throwFor(rootSchema, Arrays.asList(cause1, cause2)); - Assert.fail(); + fail(); } catch (ValidationException e) { ValidationException actual = e.prepend("rectangle"); assertEquals("#/rectangle", actual.getPointerToViolation()); @@ -157,14 +157,14 @@ public void throwForMultipleFailures() { ValidationException input2 = new ValidationException(BooleanSchema.INSTANCE, "msg2"); try { ValidationException.throwFor(rootSchema, Arrays.asList(input1, input2)); - Assert.fail("did not throw exception for 2 input exceptions"); + fail("did not throw exception for 2 input exceptions"); } catch (ValidationException e) { - Assert.assertSame(rootSchema, e.getViolatedSchema()); + assertSame(rootSchema, e.getViolatedSchema()); assertEquals("#: 2 schema violations found", e.getMessage()); List causes = e.getCausingExceptions(); assertEquals(2, causes.size()); - Assert.assertSame(input1, causes.get(0)); - Assert.assertSame(input2, causes.get(1)); + assertSame(input1, causes.get(0)); + assertSame(input2, causes.get(1)); } } @@ -178,9 +178,9 @@ public void throwForSingleFailure() { ValidationException input = new ValidationException(NullSchema.INSTANCE, "msg"); try { ValidationException.throwFor(rootSchema, Arrays.asList(input)); - Assert.fail("did not throw exception for single failure"); + fail("did not throw exception for single failure"); } catch (ValidationException actual) { - Assert.assertSame(input, actual); + assertSame(input, actual); } } diff --git a/core/src/test/java/org/everit/json/schema/ValidatorTest.java b/core/src/test/java/org/everit/json/schema/ValidatorTest.java index 19606ea51..d22eb4fef 100644 --- a/core/src/test/java/org/everit/json/schema/ValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/ValidatorTest.java @@ -1,12 +1,12 @@ package org.everit.json.schema; import static org.everit.json.schema.TestSupport.loadAsV7; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ValidatorTest { @@ -34,7 +34,7 @@ public void testFailEarlyMode() { fail("did not throw exception"); } catch (ValidationException e) { assertEquals("#: required key [boolProp] not found", e.getMessage()); - assertTrue("no causing exceptions", e.getCausingExceptions().isEmpty()); + assertTrue(e.getCausingExceptions().isEmpty(),"no causing exceptions"); } } diff --git a/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMatchEventTest.java b/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMatchEventTest.java index 8d5d980b1..023d8a419 100644 --- a/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMatchEventTest.java +++ b/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMatchEventTest.java @@ -1,6 +1,6 @@ package org.everit.json.schema.event; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; diff --git a/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMismatchEventTest.java b/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMismatchEventTest.java index 480428eec..008f3a0a3 100644 --- a/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMismatchEventTest.java +++ b/core/src/test/java/org/everit/json/schema/event/CombinedSchemaMismatchEventTest.java @@ -3,7 +3,7 @@ import org.everit.json.schema.FalseSchema; import org.everit.json.schema.TrueSchema; import org.everit.json.schema.ValidationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; diff --git a/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMatchEventTest.java b/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMatchEventTest.java index e5c1e0fd3..7de4c37aa 100644 --- a/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMatchEventTest.java +++ b/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMatchEventTest.java @@ -1,6 +1,6 @@ package org.everit.json.schema.event; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; diff --git a/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMismatchEventTest.java b/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMismatchEventTest.java index c6f73babe..9eb8ffe45 100644 --- a/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMismatchEventTest.java +++ b/core/src/test/java/org/everit/json/schema/event/ConditionalSchemaMismatchEventTest.java @@ -3,7 +3,7 @@ import org.everit.json.schema.FalseSchema; import org.everit.json.schema.TrueSchema; import org.everit.json.schema.ValidationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; diff --git a/core/src/test/java/org/everit/json/schema/event/EventToStringTest.java b/core/src/test/java/org/everit/json/schema/event/EventToStringTest.java index a5a3994d9..a43ec370d 100644 --- a/core/src/test/java/org/everit/json/schema/event/EventToStringTest.java +++ b/core/src/test/java/org/everit/json/schema/event/EventToStringTest.java @@ -3,7 +3,7 @@ import static java.util.Arrays.asList; import static org.everit.json.schema.JSONMatcher.sameJsonAs; import static org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword.IF; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.everit.json.schema.CombinedSchema; import org.everit.json.schema.ConditionalSchema; @@ -15,7 +15,7 @@ import org.everit.json.schema.ValidationException; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EventToStringTest { diff --git a/core/src/test/java/org/everit/json/schema/event/SchemaReferencedEventTest.java b/core/src/test/java/org/everit/json/schema/event/SchemaReferencedEventTest.java index 96afc2851..79256b5c5 100644 --- a/core/src/test/java/org/everit/json/schema/event/SchemaReferencedEventTest.java +++ b/core/src/test/java/org/everit/json/schema/event/SchemaReferencedEventTest.java @@ -1,6 +1,6 @@ package org.everit.json.schema.event; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; diff --git a/core/src/test/java/org/everit/json/schema/internal/DefaultFormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/internal/DefaultFormatValidatorTest.java index f70aead47..5e32612a2 100644 --- a/core/src/test/java/org/everit/json/schema/internal/DefaultFormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/DefaultFormatValidatorTest.java @@ -16,7 +16,7 @@ package org.everit.json.schema.internal; import org.everit.json.schema.FormatValidator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Optional; diff --git a/core/src/test/java/org/everit/json/schema/internal/JSONPrinterTest.java b/core/src/test/java/org/everit/json/schema/internal/JSONPrinterTest.java index 20b224caa..5eca2f192 100644 --- a/core/src/test/java/org/everit/json/schema/internal/JSONPrinterTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/JSONPrinterTest.java @@ -1,7 +1,7 @@ package org.everit.json.schema.internal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.StringWriter; import java.util.HashMap; @@ -9,14 +9,14 @@ import org.everit.json.schema.NullSchema; import org.everit.json.schema.Schema; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class JSONPrinterTest { private StringWriter buffer; - @Before + @BeforeEach public void before() { buffer = new StringWriter(); } diff --git a/core/src/test/java/org/everit/json/schema/internal/JSONWriterTest.java b/core/src/test/java/org/everit/json/schema/internal/JSONWriterTest.java index 075f755ca..90f7cc38e 100644 --- a/core/src/test/java/org/everit/json/schema/internal/JSONWriterTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/JSONWriterTest.java @@ -1,10 +1,10 @@ package org.everit.json.schema.internal; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.json.JSONString; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JSONWriterTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/JsonPointerFormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/internal/JsonPointerFormatValidatorTest.java index 9d7defcbc..90883c000 100644 --- a/core/src/test/java/org/everit/json/schema/internal/JsonPointerFormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/JsonPointerFormatValidatorTest.java @@ -3,7 +3,7 @@ import static java.lang.String.format; import static org.everit.json.schema.internal.ValidatorTestSupport.assertSuccess; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JsonPointerFormatValidatorTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidatorTest.java index 158738ebf..68f97093a 100644 --- a/core/src/test/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidatorTest.java @@ -2,9 +2,9 @@ import static org.everit.json.schema.internal.ValidatorTestSupport.assertFailure; import static org.everit.json.schema.internal.ValidatorTestSupport.assertSuccess; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RelativeJsonPointerFormatValidatorTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/URIReferenceFormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/internal/URIReferenceFormatValidatorTest.java index 298cd82ef..7cb1029c9 100644 --- a/core/src/test/java/org/everit/json/schema/internal/URIReferenceFormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/URIReferenceFormatValidatorTest.java @@ -3,7 +3,7 @@ import static org.everit.json.schema.internal.ValidatorTestSupport.assertFailure; import static org.everit.json.schema.internal.ValidatorTestSupport.assertSuccess; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class URIReferenceFormatValidatorTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/URITemplateFormatTest.java b/core/src/test/java/org/everit/json/schema/internal/URITemplateFormatTest.java index 5c45a8b34..4f4131477 100644 --- a/core/src/test/java/org/everit/json/schema/internal/URITemplateFormatTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/URITemplateFormatTest.java @@ -3,7 +3,7 @@ import static org.everit.json.schema.internal.ValidatorTestSupport.assertFailure; import static org.everit.json.schema.internal.ValidatorTestSupport.assertSuccess; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class URITemplateFormatTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/URIV4FormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/internal/URIV4FormatValidatorTest.java index fdb455f9b..00b2aa08f 100644 --- a/core/src/test/java/org/everit/json/schema/internal/URIV4FormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/internal/URIV4FormatValidatorTest.java @@ -1,9 +1,9 @@ package org.everit.json.schema.internal; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class URIV4FormatValidatorTest { diff --git a/core/src/test/java/org/everit/json/schema/internal/ValidatorTestSupport.java b/core/src/test/java/org/everit/json/schema/internal/ValidatorTestSupport.java index d434b557e..59c236f39 100644 --- a/core/src/test/java/org/everit/json/schema/internal/ValidatorTestSupport.java +++ b/core/src/test/java/org/everit/json/schema/internal/ValidatorTestSupport.java @@ -1,25 +1,24 @@ package org.everit.json.schema.internal; -import static org.junit.Assert.assertTrue; - import java.util.Optional; import org.everit.json.schema.FormatValidator; -import org.junit.Assert; + +import static org.junit.jupiter.api.Assertions.*; public final class ValidatorTestSupport { static void assertSuccess(String subject, FormatValidator format) { Optional opt = format.validate(subject); - Assert.assertNotNull("the optional is not null", opt); - Assert.assertFalse("failure not exist", opt.isPresent()); + assertNotNull(opt, "the optional is not null"); + assertFalse(opt.isPresent(), "failure not exist"); } static void assertFailure(String subject, FormatValidator format, String expectedFailure) { Optional opt = format.validate(subject); - Assert.assertNotNull("the optional is not null", opt); - assertTrue("failure exists", opt.isPresent()); - Assert.assertEquals(expectedFailure, opt.get()); + assertNotNull(opt, "the optional is not null"); + assertTrue(opt.isPresent(), "failure exists"); + assertEquals(expectedFailure, opt.get()); } private ValidatorTestSupport() { diff --git a/core/src/test/java/org/everit/json/schema/loader/AdjacentSchemaExtractionStateTest.java b/core/src/test/java/org/everit/json/schema/loader/AdjacentSchemaExtractionStateTest.java index bf44308da..188f6a908 100644 --- a/core/src/test/java/org/everit/json/schema/loader/AdjacentSchemaExtractionStateTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/AdjacentSchemaExtractionStateTest.java @@ -2,10 +2,10 @@ import static java.util.Arrays.asList; import static java.util.Collections.singleton; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.everit.json.schema.ConstSchema; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableMap; diff --git a/core/src/test/java/org/everit/json/schema/loader/ArraySchemaLoaderTest.java b/core/src/test/java/org/everit/json/schema/loader/ArraySchemaLoaderTest.java index c5f3a0e11..611bca44d 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ArraySchemaLoaderTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ArraySchemaLoaderTest.java @@ -3,19 +3,18 @@ import org.everit.json.schema.ArraySchema; import org.everit.json.schema.NullSchema; import org.everit.json.schema.ResourceLoader; -import org.everit.json.schema.Schema; import org.everit.json.schema.SchemaException; import org.everit.json.schema.TrueSchema; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import static org.everit.json.schema.TestSupport.loadAsV6; -import static org.everit.json.schema.TestSupport.v6Loader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * @author erosb @@ -36,7 +35,7 @@ public void additionalItemSchema() { @Test public void arrayByAdditionalItems() { ArraySchema actual = (ArraySchema) SchemaLoader.load(get("arrayByAdditionalItems")); - Assert.assertFalse(actual.requiresArray()); + assertFalse(actual.requiresArray()); } @Test @@ -55,19 +54,25 @@ public void arraySchema() { assertEquals(NullSchema.INSTANCE, actual.getAllItemSchema()); } - @Test(expected = SchemaException.class) + @Test public void invalidAdditionalItems() { - SchemaLoader.load(get("invalidAdditionalItems")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidAdditionalItems")); + }); } - @Test(expected = SchemaException.class) + @Test public void invalidArrayItemSchema() { - SchemaLoader.load(get("invalidArrayItemSchema")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidArrayItemSchema")); + }); } - @Test(expected = SchemaException.class) + @Test public void invalidItemsArraySchema() { - SchemaLoader.load(get("invalidItemsArraySchema")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidItemsArraySchema")); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/ClassPathAwareSchemaClientTest.java b/core/src/test/java/org/everit/json/schema/loader/ClassPathAwareSchemaClientTest.java index 97d539b31..3872d73c3 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ClassPathAwareSchemaClientTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ClassPathAwareSchemaClientTest.java @@ -1,8 +1,8 @@ package org.everit.json.schema.loader; import static org.everit.json.schema.JSONMatcher.sameJsonAs; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -12,23 +12,19 @@ import org.everit.json.schema.ResourceLoader; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -@RunWith(JUnitParamsRunner.class) public class ClassPathAwareSchemaClientTest { private static final JSONObject EXPECTED = ResourceLoader.DEFAULT.readObj("constobject.json"); private SchemaClient fallbackClient; - @Before + @BeforeEach public void before() { fallbackClient = mock(SchemaClient.class); } @@ -42,24 +38,20 @@ public void delegatesUnhandledProtocolsToFallback() { assertSame(expected, actual); } - @Rule - public ExpectedException exception = ExpectedException.none(); @Test public void throwsErrorOnMissingClasspathResource() { - exception.expect(UncheckedIOException.class); - exception.expectMessage("Could not find"); - - String url = "classpath:/bogus.json"; - ClassPathAwareSchemaClient subject = new ClassPathAwareSchemaClient(fallbackClient); - subject.get(url); + UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> { + String url = "classpath:/bogus.json"; + ClassPathAwareSchemaClient subject = new ClassPathAwareSchemaClient(fallbackClient); + subject.get(url); + }); + assertEquals("java.io.IOException: Could not find classpath:/bogus.json", thrown.getMessage()); } - @Test - @Parameters({ - "classpath:/org/everit/jsonvalidator/constobject.json", + @ParameterizedTest + @ValueSource(strings = {"classpath:/org/everit/jsonvalidator/constobject.json", "classpath://org/everit/jsonvalidator/constobject.json", - "classpath:org/everit/jsonvalidator/constobject.json" - }) + "classpath:org/everit/jsonvalidator/constobject.json"}) public void success(String url) { ClassPathAwareSchemaClient subject = new ClassPathAwareSchemaClient(fallbackClient); JSONObject actual = new JSONObject(new JSONTokener(subject.get(url))); diff --git a/core/src/test/java/org/everit/json/schema/loader/CombinedSchemaLoaderTest.java b/core/src/test/java/org/everit/json/schema/loader/CombinedSchemaLoaderTest.java index d27f30c98..abe6026d7 100644 --- a/core/src/test/java/org/everit/json/schema/loader/CombinedSchemaLoaderTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/CombinedSchemaLoaderTest.java @@ -4,8 +4,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashSet; import java.util.Set; @@ -17,8 +16,7 @@ import org.everit.json.schema.SchemaLocation; import org.everit.json.schema.StringSchema; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author erosb @@ -34,7 +32,7 @@ private static JSONObject get(final String schemaName) { @Test public void combinedSchemaLoading() { CombinedSchema actual = (CombinedSchema) SchemaLoader.load(get("combinedSchema")); - Assert.assertNotNull(actual); + assertNotNull(actual); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/ConfigurationPropagationTest.java b/core/src/test/java/org/everit/json/schema/loader/ConfigurationPropagationTest.java index f70b25be7..32b13c5e3 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ConfigurationPropagationTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ConfigurationPropagationTest.java @@ -1,9 +1,9 @@ package org.everit.json.schema.loader; import static org.everit.json.schema.JSONMatcher.sameJsonAs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.net.URI; import java.net.URISyntaxException; @@ -12,7 +12,7 @@ import org.everit.json.schema.Schema; import org.everit.json.schema.ValidationException; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigurationPropagationTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/CustomFormatValidatorTest.java b/core/src/test/java/org/everit/json/schema/loader/CustomFormatValidatorTest.java index 229debf1c..35f0d3701 100644 --- a/core/src/test/java/org/everit/json/schema/loader/CustomFormatValidatorTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/CustomFormatValidatorTest.java @@ -19,13 +19,11 @@ import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.ValidationException; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Optional; -import static org.junit.Assert.assertEquals; - public class CustomFormatValidatorTest { private final ResourceLoader loader = ResourceLoader.DEFAULT; @@ -55,7 +53,7 @@ public void test() { .build(); try { schemaLoader.load().build().validate(loader.readObj("customformat-data.json")); - Assert.fail("did not throw exception"); + Assertions.fail("did not throw exception"); } catch (ValidationException ve) { } } @@ -70,7 +68,7 @@ public void nameOverride() { .addFormatValidator("somethingelse", new EvenCharNumValidator()) .build(); Object actual = fetchFormatValueFromOutputJson(schemaLoader); - assertEquals("somethingelse", actual); + Assertions.assertEquals("somethingelse", actual); } private Object fetchFormatValueFromOutputJson(SchemaLoader schemaLoader) { @@ -89,7 +87,7 @@ public void formatValidatorWithoutExplicitName() { .addFormatValidator(new EvenCharNumValidator()) .build(); Object actual = fetchFormatValueFromOutputJson(schemaLoader); - assertEquals("evenlength", actual); + Assertions.assertEquals("evenlength", actual); } } diff --git a/core/src/test/java/org/everit/json/schema/loader/DefinesPropertyTest.java b/core/src/test/java/org/everit/json/schema/loader/DefinesPropertyTest.java index e5f7e564f..1ed164ad0 100644 --- a/core/src/test/java/org/everit/json/schema/loader/DefinesPropertyTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/DefinesPropertyTest.java @@ -1,6 +1,7 @@ package org.everit.json.schema.loader; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.everit.json.schema.BooleanSchema; import org.everit.json.schema.CombinedSchema; @@ -9,8 +10,7 @@ import org.everit.json.schema.Schema; import org.everit.json.schema.ValidationException; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DefinesPropertyTest { @@ -23,9 +23,9 @@ private JSONObject get(final String schemaName) { @Test public void objectSchemaHasField() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("pointerResolution")); - Assert.assertTrue(actual.definesProperty("#/rectangle")); - Assert.assertTrue(actual.definesProperty("#/rectangle/a")); - Assert.assertTrue(actual.definesProperty("#/rectangle/b")); + assertTrue(actual.definesProperty("#/rectangle")); + assertTrue(actual.definesProperty("#/rectangle/a")); + assertTrue(actual.definesProperty("#/rectangle/b")); assertFalse(actual.definesProperty("#/rectangle/c")); assertFalse(actual.definesProperty("#/rectangle/")); @@ -39,20 +39,20 @@ public void objectSchemaHasField() { public void recursiveSchemaHasField() { Schema recursiveSchema = SchemaLoader.load(get("recursiveSchema")); - Assert.assertTrue(recursiveSchema.definesProperty("#/prop")); - Assert.assertTrue(recursiveSchema.definesProperty("#/prop/subprop")); - Assert.assertTrue(recursiveSchema.definesProperty("#/prop/subprop/subprop")); - Assert.assertTrue(recursiveSchema.definesProperty("#/prop/subprop/subprop/subprop")); + assertTrue(recursiveSchema.definesProperty("#/prop")); + assertTrue(recursiveSchema.definesProperty("#/prop/subprop")); + assertTrue(recursiveSchema.definesProperty("#/prop/subprop/subprop")); + assertTrue(recursiveSchema.definesProperty("#/prop/subprop/subprop/subprop")); } @Test public void patternPropertiesHasField() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("patternProperties")); - Assert.assertTrue(actual.definesProperty("#/a")); - Assert.assertTrue(actual.definesProperty("#/aa")); - Assert.assertTrue(actual.definesProperty("#/aaa")); - Assert.assertTrue(actual.definesProperty("#/aaaa")); - Assert.assertTrue(actual.definesProperty("#/aaaaa")); + assertTrue(actual.definesProperty("#/a")); + assertTrue(actual.definesProperty("#/aa")); + assertTrue(actual.definesProperty("#/aaa")); + assertTrue(actual.definesProperty("#/aaaa")); + assertTrue(actual.definesProperty("#/aaaaa")); assertFalse(actual.definesProperty("b")); } @@ -60,8 +60,8 @@ public void patternPropertiesHasField() { @Test public void objectWithSchemaDep() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("objectWithSchemaDep")); - Assert.assertTrue(actual.definesProperty("#/a")); - Assert.assertTrue(actual.definesProperty("#/b")); + assertTrue(actual.definesProperty("#/a")); + assertTrue(actual.definesProperty("#/b")); assertFalse(actual.definesProperty("#/c")); } @@ -69,9 +69,9 @@ public void objectWithSchemaDep() { @Test public void objectWithSchemaRectangleDep() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("objectWithSchemaRectangleDep")); - Assert.assertTrue(actual.definesProperty("#/d")); - Assert.assertTrue(actual.definesProperty("#/rectangle/a")); - Assert.assertTrue(actual.definesProperty("#/rectangle/b")); + assertTrue(actual.definesProperty("#/d")); + assertTrue(actual.definesProperty("#/rectangle/a")); + assertTrue(actual.definesProperty("#/rectangle/b")); assertFalse(actual.definesProperty("#/c")); assertFalse(actual.definesProperty("#/d/c")); @@ -81,8 +81,8 @@ public void objectWithSchemaRectangleDep() { @Test public void objectEscape() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("objectEscape")); - Assert.assertTrue(actual.definesProperty("#/a~0b")); - Assert.assertTrue(actual.definesProperty("#/a~0b/c~1d")); + assertTrue(actual.definesProperty("#/a~0b")); + assertTrue(actual.definesProperty("#/a~0b/c~1d")); assertFalse(actual.definesProperty("#/a~0b/c/d")); } @@ -116,7 +116,7 @@ public void patternPropsAndSchemaDefs() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("patternPropsAndSchemaDeps")); // Assert.assertTrue(actual.definesProperty("#/1stLevel")); // Assert.assertTrue(actual.definesProperty("#/1stLevel/2ndLevel")); - Assert.assertTrue(actual.definesProperty("#/1stLevel/2ndLevel/3rdLev")); + assertTrue(actual.definesProperty("#/1stLevel/2ndLevel/3rdLev")); // Assert.assertTrue(actual.definesProperty("#/1stLevel/2ndLevel/3rdLevel/4thLevel")); } diff --git a/core/src/test/java/org/everit/json/schema/loader/ExtendTest.java b/core/src/test/java/org/everit/json/schema/loader/ExtendTest.java index bc67cf0cc..989f11fc9 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ExtendTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ExtendTest.java @@ -20,7 +20,7 @@ import org.everit.json.schema.ResourceLoader; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ExtendTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/JsonArrayTest.java b/core/src/test/java/org/everit/json/schema/loader/JsonArrayTest.java index ddcd9480d..021adb557 100644 --- a/core/src/test/java/org/everit/json/schema/loader/JsonArrayTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/JsonArrayTest.java @@ -6,7 +6,7 @@ import static org.mockito.Mockito.verify; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author erosb diff --git a/core/src/test/java/org/everit/json/schema/loader/JsonObjectTest.java b/core/src/test/java/org/everit/json/schema/loader/JsonObjectTest.java index 3b3a703b3..a67face7c 100644 --- a/core/src/test/java/org/everit/json/schema/loader/JsonObjectTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/JsonObjectTest.java @@ -3,10 +3,7 @@ import static org.everit.json.schema.loader.JsonValueTest.asV6Value; import static org.everit.json.schema.loader.JsonValueTest.withLs; import static org.everit.json.schema.loader.OrgJsonUtil.toMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -22,9 +19,7 @@ import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.SchemaException; import org.json.JSONObject; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; /** * @author erosb @@ -47,9 +42,6 @@ private Map storage() { return rval; } - @Rule - public ExpectedException expExc = ExpectedException.none(); - @Test public void testHasKey() { assertTrue(subject().containsKey("a")); @@ -68,11 +60,12 @@ public void testRequireWithConsumer() { @Test public void testRequireWithConsumerFailure() { - expExc.expect(SchemaException.class); - expExc.expectMessage("#: required key [aaa] not found"); - Consumer consumer = mockConsumer(); - subject().require("aaa", consumer); - verify(consumer, never()).accept(any()); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + Consumer consumer = mockConsumer(); + subject().require("aaa", consumer); + verify(consumer, never()).accept(any()); + }); + assertEquals("#: required key [aaa] not found", thrown.getMessage()); } @Test @@ -83,9 +76,10 @@ public void testRequireWithFunction() { @Test public void testRequireWithFunctionFailure() { - expExc.expect(SchemaException.class); - expExc.expectMessage("#: required key [aaa] not found"); - subject().requireMapping("aaa", val -> false); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + subject().requireMapping("aaa", val -> false); + }); + assertEquals("#: required key [aaa] not found", thrown.getMessage()); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java b/core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java index b33c26287..5de9b5a32 100644 --- a/core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java @@ -5,10 +5,10 @@ import static org.everit.json.schema.JSONMatcher.sameJsonAs; import static org.everit.json.schema.TestSupport.asStream; import static org.everit.json.schema.loader.JsonValueTest.withLs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -21,7 +21,8 @@ import org.everit.json.schema.SchemaException; import org.everit.json.schema.SchemaLocation; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JsonPointerEvaluatorTest { @@ -31,7 +32,6 @@ public class JsonPointerEvaluatorTest { private static final ResourceLoader LOADER = ResourceLoader.DEFAULT; @Test - public void sameDocumentSuccess() { JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Bar"); JsonObject actual = pointer.query().getQueryResult().requireObject(); @@ -40,13 +40,15 @@ public void sameDocumentSuccess() { assertEquals(new SchemaLocation(asList("definitions", "Bar")), actual.ls.pointerToCurrentObj); } - @Test(expected = SchemaException.class) + @Test public void sameDocumentNotFound() { - JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/NotFound"); - JsonObject actual = pointer.query().getQueryResult().requireObject(); - assertEquals("dummy schema at #/definitions/Bar", actual.require("description").requireString()); - assertEquals("http://localhost:1234/folder/", actual.ls.id.toString()); - assertEquals(new SchemaLocation(asList("definitions", "Bar")), actual.ls.pointerToCurrentObj); + Assertions.assertThrows(SchemaException.class, () -> { + JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/NotFound"); + JsonObject actual = pointer.query().getQueryResult().requireObject(); + assertEquals("dummy schema at #/definitions/Bar", actual.require("description").requireString()); + assertEquals("http://localhost:1234/folder/", actual.ls.id.toString()); + assertEquals(new SchemaLocation(asList("definitions", "Bar")), actual.ls.pointerToCurrentObj); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/JsonValueTest.java b/core/src/test/java/org/everit/json/schema/loader/JsonValueTest.java index e5d312947..ef7bc39d0 100644 --- a/core/src/test/java/org/everit/json/schema/loader/JsonValueTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/JsonValueTest.java @@ -6,36 +6,35 @@ import static org.everit.json.schema.loader.JsonObjectTest.mockConsumer; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.everit.json.schema.SchemaException; import org.everit.json.schema.SchemaLocation; import org.everit.json.schema.loader.internal.DefaultSchemaClient; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; - -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * @author erosb */ -@RunWith(JUnitParamsRunner.class) public class JsonValueTest { static final JsonValue asV6Value(Object o) { @@ -68,14 +67,12 @@ static final JsonValue withLs(Object o) { }); } - @Rule - public ExpectedException exc = ExpectedException.none(); - @Test public void requireStringFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: String, found: Boolean"); - TRU.requireString(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + TRU.requireString(); + }); + assertEquals("#: expected type: String, found: Boolean", thrown.getMessage()); } @Test @@ -91,9 +88,10 @@ public void requireStringWithMapper() { @Test public void requireBooleanFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: Boolean, found: String"); - STR.requireBoolean(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + STR.requireBoolean(); + }); + assertEquals("#: expected type: Boolean, found: String", thrown.getMessage()); } @Test @@ -103,14 +101,15 @@ public void requireBooleanSuccess() { @Test public void requireBooleanWithMapper() { - assertTrue(FLS.requireBoolean(bool -> !bool)); + assertTrue(FLS.requireBoolean((Function) bool -> !bool)); } @Test public void requireNumberFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: Number, found: JsonObject"); - OBJ.requireNumber(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + OBJ.requireNumber(); + }); + assertEquals("#: expected type: Number, found: JsonObject", thrown.getMessage()); } @Test @@ -125,9 +124,10 @@ public void requireNumberWithMapping() { @Test public void requireIntegerFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: Integer, found: JsonArray"); - ARR.requireInteger(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + ARR.requireInteger(); + }); + assertEquals("#: expected type: Integer, found: JsonArray", thrown.getMessage()); } @Test @@ -142,9 +142,10 @@ public void requireIntegerWithMapper() { @Test public void requireObjectFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: JsonObject, found: String"); - STR.requireObject(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + STR.requireObject(); + }); + assertEquals("#: expected type: JsonObject, found: String", thrown.getMessage()); } @Test @@ -161,9 +162,10 @@ public void requireObjectWithMapping() { @Test public void requireArrayFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type: JsonArray, found: JsonObject"); - OBJ.requireArray(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + OBJ.requireArray(); + }); + assertEquals("#: expected type: JsonArray, found: JsonObject", thrown.getMessage()); } @Test @@ -172,22 +174,18 @@ public void requireArrayWithMapping() { assertEquals(2, actual.intValue()); } - private Object[] par(Object raw, Class expectedRetType) { - return new Object[] { raw, expectedRetType }; + private static List providerTestFactory() { + return Stream.of( + Arguments.of(null, JsonValue.class), + Arguments.of(emptyMap(), JsonObject.class), + Arguments.of(emptyList(), JsonArray.class), + Arguments.of(new JSONObject(), JsonObject.class), + Arguments.of(new JSONArray(), JsonArray.class) + ).collect(Collectors.toList()); } - private Object[] providerTestFactory() { - return new Object[] { - par(null, JsonValue.class), - par(emptyMap(), JsonObject.class), - par(emptyList(), JsonArray.class), - par(new JSONObject(), JsonObject.class), - par(new JSONArray(), JsonArray.class) - }; - } - - @Test - @Parameters(method = "providerTestFactory") + @ParameterizedTest + @MethodSource("providerTestFactory") public void testFactory(Object raw, Class expectedRetType) { assertThat(JsonValue.of(raw), is(instanceOf(expectedRetType))); } @@ -222,24 +220,26 @@ public void multiplexerWithPrimitives() { @Test public void multiplexerFailure() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type is one of Boolean or String, found: Integer"); - INT.canBe(String.class, str -> { - }) - .or(Boolean.class, bool -> { - }) - .requireAny(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + INT.canBe(String.class, str -> { + }) + .or(Boolean.class, bool -> { + }) + .requireAny(); + }); + assertEquals("#: expected type is one of Boolean or String, found: Integer", thrown.getMessage()); } @Test public void multiplexFailureForNullValue() { - exc.expect(SchemaException.class); - exc.expectMessage("#: expected type is one of Boolean or String, found: null"); - withLs(JsonValue.of(null)).canBe(String.class, s -> { - }) - .or(Boolean.class, b -> { - }) - .requireAny(); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + withLs(JsonValue.of(null)).canBe(String.class, s -> { + }) + .or(Boolean.class, b -> { + }) + .requireAny(); + }); + assertEquals("#: expected type is one of Boolean or String, found: null", thrown.getMessage()); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/LoadingStateTest.java b/core/src/test/java/org/everit/json/schema/loader/LoadingStateTest.java index 221377cb8..c229d3a1c 100644 --- a/core/src/test/java/org/everit/json/schema/loader/LoadingStateTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/LoadingStateTest.java @@ -3,22 +3,21 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; import static org.everit.json.schema.loader.JsonValueTest.withLs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashMap; import java.util.Map; import org.everit.json.schema.ResourceLoader; -import org.everit.json.schema.Schema; import org.everit.json.schema.SchemaException; import org.everit.json.schema.SchemaLocation; import org.everit.json.schema.loader.internal.DefaultSchemaClient; import org.json.JSONPointer; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author erosb diff --git a/core/src/test/java/org/everit/json/schema/loader/NumberSchemaLoadingTest.java b/core/src/test/java/org/everit/json/schema/loader/NumberSchemaLoadingTest.java index 67422ea7a..077a176f6 100644 --- a/core/src/test/java/org/everit/json/schema/loader/NumberSchemaLoadingTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/NumberSchemaLoadingTest.java @@ -4,10 +4,10 @@ import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.TestSupport; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.everit.json.schema.TestSupport.loadAsV6; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class NumberSchemaLoadingTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/ObjectSchemaLoaderTest.java b/core/src/test/java/org/everit/json/schema/loader/ObjectSchemaLoaderTest.java index a421fc281..df773a278 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ObjectSchemaLoaderTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ObjectSchemaLoaderTest.java @@ -2,17 +2,11 @@ import org.everit.json.schema.*; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * @author erosb @@ -25,9 +19,6 @@ private static JSONObject get(final String schemaName) { return ALL_SCHEMAS.getJSONObject(schemaName); } - @Rule - public ExpectedException expExc = ExpectedException.none(); - @Test public void objectSchema() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("objectSchema")); @@ -35,15 +26,17 @@ public void objectSchema() { Map propertySchemas = actual.getPropertySchemas(); assertEquals(2, propertySchemas.size()); assertEquals(BooleanSchema.INSTANCE, propertySchemas.get("boolProp")); - Assert.assertFalse(actual.permitsAdditionalProperties()); + assertFalse(actual.permitsAdditionalProperties()); assertEquals(2, actual.getRequiredProperties().size()); assertEquals(2, actual.getMinProperties().intValue()); assertEquals(3, actual.getMaxProperties().intValue()); } - @Test(expected = SchemaException.class) + @Test public void objectInvalidAdditionalProperties() { - SchemaLoader.load(get("objectInvalidAdditionalProperties")); + assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("objectInvalidAdditionalProperties")); + }); } @Test @@ -71,9 +64,11 @@ public void patternProperties() { assertEquals(2, actual.getPatternProperties().size()); } - @Test(expected = SchemaException.class) + @Test public void invalidDependency() { - SchemaLoader.load(get("invalidDependency")); + assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidDependency")); + }); } @Test @@ -83,9 +78,10 @@ public void emptyDependencyList() { @Test public void invalidRequired() { - expExc.expect(SchemaException.class); - expExc.expectMessage("#/required/1: expected type: String, found: JsonArray"); - SchemaLoader.load(get("invalidRequired")); + SchemaException thrown = assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidRequired")); + }); + assertEquals("#/required/1: expected type: String, found: JsonArray", thrown.getMessage()); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/ProjectedJsonObjectTest.java b/core/src/test/java/org/everit/json/schema/loader/ProjectedJsonObjectTest.java index 33d0c2cdd..71204f92d 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ProjectedJsonObjectTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ProjectedJsonObjectTest.java @@ -3,9 +3,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; import static java.util.Collections.singleton; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -19,9 +17,9 @@ import org.everit.json.schema.SchemaException; import org.everit.json.schema.SchemaLocation; -import org.junit.Test; import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; public class ProjectedJsonObjectTest { @@ -66,10 +64,12 @@ public void requireWithConsumerSucceeds() { verify(consumer).accept(JsonValue.of(original.get("not"))); } - @Test(expected = SchemaException.class) + @Test public void requireWithConsumerHidesKeys() { - Consumer consumer = mock(Consumer.class); - createSubject().require("minimum", consumer); + assertThrows(SchemaException.class, () -> { + Consumer consumer = mock(Consumer.class); + createSubject().require("minimum", consumer); + }); } @Test @@ -78,9 +78,11 @@ public void requireSucceeds() { assertEquals(JsonValue.of(original.get("not")), actual); } - @Test(expected = SchemaException.class) + @Test public void requireHidesKeys() { - createSubject().require("minimum"); + assertThrows(SchemaException.class, () -> { + createSubject().require("minimum"); + }); } @Test @@ -89,9 +91,11 @@ public void requireMappingSucceeds() { assertTrue(actual); } - @Test(expected = SchemaException.class) + @Test public void requireMappingFailsForHiddenKey() { - createSubject().requireMapping("minimum", val -> true); + assertThrows(SchemaException.class, () -> { + createSubject().requireMapping("minimum", val -> true); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/ReadWriteContextLoadingTest.java b/core/src/test/java/org/everit/json/schema/loader/ReadWriteContextLoadingTest.java index 7dee58f74..e36ed5ed1 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ReadWriteContextLoadingTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ReadWriteContextLoadingTest.java @@ -2,13 +2,13 @@ import static org.everit.json.schema.TestSupport.loadAsV6; import static org.everit.json.schema.TestSupport.loadAsV7; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.everit.json.schema.ObjectSchema; import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.Schema; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ReadWriteContextLoadingTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/ReferenceLookupTest.java b/core/src/test/java/org/everit/json/schema/loader/ReferenceLookupTest.java index 40dbc6454..338b6781f 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ReferenceLookupTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ReferenceLookupTest.java @@ -2,10 +2,7 @@ import static java.util.Collections.emptyMap; import static org.everit.json.schema.TestSupport.asStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -19,10 +16,10 @@ import org.everit.json.schema.Schema; import org.everit.json.schema.SchemaLocation; import org.json.JSONObject; -import org.junit.Before; -import org.junit.Test; import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ReferenceLookupTest { @@ -32,7 +29,7 @@ public class ReferenceLookupTest { private SchemaClient schemaClient; - @Before + @BeforeEach public void before() { schemaClient = mock(SchemaClient.class); } diff --git a/core/src/test/java/org/everit/json/schema/loader/RegisteredURIResolutionTest.java b/core/src/test/java/org/everit/json/schema/loader/RegisteredURIResolutionTest.java index 25114c6fd..e4b027bd9 100644 --- a/core/src/test/java/org/everit/json/schema/loader/RegisteredURIResolutionTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/RegisteredURIResolutionTest.java @@ -1,6 +1,6 @@ package org.everit.json.schema.loader; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -9,7 +9,7 @@ import org.everit.json.schema.ReferenceSchema; import org.everit.json.schema.ResourceLoader; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RegisteredURIResolutionTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/ResolutionScopeTest.java b/core/src/test/java/org/everit/json/schema/loader/ResolutionScopeTest.java index e97f8cf16..fee235b5e 100644 --- a/core/src/test/java/org/everit/json/schema/loader/ResolutionScopeTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/ResolutionScopeTest.java @@ -18,7 +18,7 @@ import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.loader.internal.DefaultSchemaClient; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.InputStream; diff --git a/core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java b/core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java index 0828568f0..407ea7832 100644 --- a/core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java @@ -9,13 +9,8 @@ import static org.everit.json.schema.TestSupport.loadAsV7; import static org.everit.json.schema.TestSupport.v6Loader; import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_6; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -59,11 +54,11 @@ import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONPointer; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class SchemaLoaderTest { @@ -171,33 +166,33 @@ public void integerSchema() { @Test public void conditionalSchemaIf() { ConditionalSchema actual = (ConditionalSchema) loadAsV7(get("conditionalSchemaIf")); - Assert.assertTrue(actual.getIfSchema().isPresent()); - Assert.assertFalse(actual.getThenSchema().isPresent()); - Assert.assertFalse(actual.getElseSchema().isPresent()); + assertTrue(actual.getIfSchema().isPresent()); + assertFalse(actual.getThenSchema().isPresent()); + assertFalse(actual.getElseSchema().isPresent()); } @Test public void conditionalSchemaThen() { ConditionalSchema actual = (ConditionalSchema) loadAsV7(get("conditionalSchemaThen")); - Assert.assertFalse(actual.getIfSchema().isPresent()); - Assert.assertTrue(actual.getThenSchema().isPresent()); - Assert.assertFalse(actual.getElseSchema().isPresent()); + assertFalse(actual.getIfSchema().isPresent()); + assertTrue(actual.getThenSchema().isPresent()); + assertFalse(actual.getElseSchema().isPresent()); } @Test public void conditionalSchemaElse() { ConditionalSchema actual = (ConditionalSchema) loadAsV7(get("conditionalSchemaElse")); - Assert.assertFalse(actual.getIfSchema().isPresent()); - Assert.assertFalse(actual.getThenSchema().isPresent()); - Assert.assertTrue(actual.getElseSchema().isPresent()); + assertFalse(actual.getIfSchema().isPresent()); + assertFalse(actual.getThenSchema().isPresent()); + assertTrue(actual.getElseSchema().isPresent()); } @Test public void conditionalSchemaIfThenElse() { ConditionalSchema actual = (ConditionalSchema) loadAsV7(get("conditionalSchemaIfThenElse")); - Assert.assertTrue(actual.getIfSchema().isPresent()); - Assert.assertTrue(actual.getThenSchema().isPresent()); - Assert.assertTrue(actual.getElseSchema().isPresent()); + assertTrue(actual.getIfSchema().isPresent()); + assertTrue(actual.getThenSchema().isPresent()); + assertTrue(actual.getElseSchema().isPresent()); } @Test @@ -215,31 +210,39 @@ public void conditionalSchemaLoadingV6() { @Test public void conditionalSchemaIfSubSchemaTrue() { ConditionalSchema actual = (ConditionalSchema) loadAsV7(get("conditionalSchemaIfSubSchemaTrue")); - Assert.assertTrue(actual.getIfSchema().isPresent()); - Assert.assertFalse(actual.getThenSchema().isPresent()); - Assert.assertFalse(actual.getElseSchema().isPresent()); + assertTrue(actual.getIfSchema().isPresent()); + assertFalse(actual.getThenSchema().isPresent()); + assertFalse(actual.getElseSchema().isPresent()); assertTrue(actual.getIfSchema().get() instanceof TrueSchema); } - @Test(expected = SchemaException.class) + @Test public void invalidExclusiveMinimum() { - SchemaLoader.load(get("invalidExclusiveMinimum")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidExclusiveMinimum")); + }); } - @Test(expected = SchemaException.class) + @Test public void invalidIntegerSchema() { - JSONObject input = get("invalidIntegerSchema"); - SchemaLoader.load(input); + Assertions.assertThrows(SchemaException.class, () -> { + JSONObject input = get("invalidIntegerSchema"); + SchemaLoader.load(input); + }); } - @Test(expected = SchemaException.class) + @Test public void invalidStringSchema() { - SchemaLoader.load(get("invalidStringSchema")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidStringSchema")); + }); } - @Test(expected = SchemaException.class) + @Test public void invalidType() { - SchemaLoader.load(get("invalidType")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("invalidType")); + }); } @Test @@ -323,17 +326,21 @@ public void sameDocumentReferenceResolution() { v6Loader().schemaJson(get("v6SameDocumentRef")).build().load().build(); } - @Test(expected = SchemaException.class) + @Test public void pointerResolutionFailure() { - SchemaLoader.load(get("pointerResolutionFailure")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("pointerResolutionFailure")); + }); } - @Test(expected = SchemaException.class) + @Test public void pointerResolutionQueryFailure() { - SchemaLoader.load(get("pointerResolutionQueryFailure")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("pointerResolutionQueryFailure")); + }); } - @Test @Ignore + @Test @Disabled public void propsAroundRefExtendTheReferredSchema() { ObjectSchema actual = (ObjectSchema) SchemaLoader .load(get("propsAroundRefExtendTheReferredSchema")); @@ -441,9 +448,11 @@ public void tupleSchema() { assertEquals(NullSchema.INSTANCE, actual.getItemSchemas().get(1)); } - @Test(expected = SchemaException.class) + @Test public void unknownSchema() { - SchemaLoader.load(get("unknown")); + Assertions.assertThrows(SchemaException.class, () -> { + SchemaLoader.load(get("unknown")); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/loader/SpecVersionDeductionTest.java b/core/src/test/java/org/everit/json/schema/loader/SpecVersionDeductionTest.java index 59ca4b539..1b87122bb 100644 --- a/core/src/test/java/org/everit/json/schema/loader/SpecVersionDeductionTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/SpecVersionDeductionTest.java @@ -2,14 +2,12 @@ import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_4; import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_6; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.SchemaException; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SpecVersionDeductionTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/SpecificationVersionTest.java b/core/src/test/java/org/everit/json/schema/loader/SpecificationVersionTest.java index dd008fd03..fd5b61a68 100644 --- a/core/src/test/java/org/everit/json/schema/loader/SpecificationVersionTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/SpecificationVersionTest.java @@ -4,15 +4,15 @@ import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_4; import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_6; import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_7; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; import java.util.Set; import org.everit.json.schema.FormatValidator; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SpecificationVersionTest { @@ -38,17 +38,17 @@ public void v6MapMatchesFormatNames() { @Test public void isAtLeastTrue() { - assertTrue(DRAFT_7.isAtLeast(DRAFT_6)); + Assertions.assertTrue(DRAFT_7.isAtLeast(DRAFT_6)); } @Test public void isAtLeast_False() { - assertFalse(DRAFT_6.isAtLeast(DRAFT_7)); + Assertions.assertFalse(DRAFT_6.isAtLeast(DRAFT_7)); } @Test public void isAtLeast_equal() { - assertTrue(DRAFT_6.isAtLeast(DRAFT_6)); + Assertions.assertTrue(DRAFT_6.isAtLeast(DRAFT_6)); } } diff --git a/core/src/test/java/org/everit/json/schema/loader/SubschemaRegistryTest.java b/core/src/test/java/org/everit/json/schema/loader/SubschemaRegistryTest.java index 594ef632b..420b8a147 100644 --- a/core/src/test/java/org/everit/json/schema/loader/SubschemaRegistryTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/SubschemaRegistryTest.java @@ -1,13 +1,13 @@ package org.everit.json.schema.loader; import static java.util.Collections.emptyMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import org.everit.json.schema.ResourceLoader; import org.everit.json.schema.SchemaLocation; import org.everit.json.schema.loader.internal.DefaultSchemaClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SubschemaRegistryTest { diff --git a/core/src/test/java/org/everit/json/schema/loader/internal/ReferenceResolverTest.java b/core/src/test/java/org/everit/json/schema/loader/internal/ReferenceResolverTest.java index a7b87bd88..b92a75cd9 100644 --- a/core/src/test/java/org/everit/json/schema/loader/internal/ReferenceResolverTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/internal/ReferenceResolverTest.java @@ -16,70 +16,52 @@ package org.everit.json.schema.loader.internal; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; import java.net.URISyntaxException; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class ReferenceResolverTest { - @Parameters(name = "{0}") - public static List params() { + public static List params() { return asList( - parList("fragment id", "http://x.y.z/root.json#foo", "http://x.y.z/root.json", "#foo"), - parList("rel path", "http://example.org/foo", "http://example.org/bar", "foo"), - parList("file name change", "http://x.y.z/schema/child.json", + Arguments.of("fragment id", "http://x.y.z/root.json#foo", "http://x.y.z/root.json", "#foo"), + Arguments.of("rel path", "http://example.org/foo", "http://example.org/bar", "foo"), + Arguments.of("file name change", "http://x.y.z/schema/child.json", "http://x.y.z/schema/parent.json", "child.json"), - parList("file name after folder path", "http://x.y.z/schema/child.json", + Arguments.of("file name after folder path", "http://x.y.z/schema/child.json", "http://x.y.z/schema/", "child.json"), - parList("new root", "http://bserver.com", "http://aserver.com/", + Arguments.of("new root", "http://bserver.com", "http://aserver.com/", "http://bserver.com"), - parList("null parent", "http://a.b.c", null, "http://a.b.c"), - parList("classpath single-slash", + Arguments.of("null parent", "http://a.b.c", null, "http://a.b.c"), + Arguments.of("classpath single-slash", "classpath:/hello/world.json/definitions/A", "classpath:/hello/world.json/", "definitions/A" ), - parList("classpath double-slash", + Arguments.of("classpath double-slash", "classpath://hello/world.json#/definitions/A", "classpath://hello/world.json", "#/definitions/A" )); } - private static Object[] parList(String... params) { - return params; - } - - private final String expectedOutput; - - private final String parentScope; - - private final String encounteredSegment; - - public ReferenceResolverTest(String testcaseName, String expectedOutput, - final String parentScope, - final String encounteredSegment) { - this.expectedOutput = expectedOutput; - this.parentScope = parentScope; - this.encounteredSegment = encounteredSegment; - } - - @Test - public void test() { + @ParameterizedTest + @MethodSource("params") + public void test(String testcaseName, String expectedOutput, String parentScope, String encounteredSegment) { String actual = ReferenceResolver.resolve(parentScope, encounteredSegment); assertEquals(expectedOutput, actual); } - @Test - public void testURI() { + @ParameterizedTest + @MethodSource("params") + public void testURI(String testcaseName, String expectedOutput, String parentScope, String encounteredSegment) { URI parentScopeURI; try { parentScopeURI = new URI(parentScope); diff --git a/core/src/test/java/org/everit/json/schema/loader/internal/TypeBasedMultiplexerTest.java b/core/src/test/java/org/everit/json/schema/loader/internal/TypeBasedMultiplexerTest.java index 24cb8cefe..88103d31f 100644 --- a/core/src/test/java/org/everit/json/schema/loader/internal/TypeBasedMultiplexerTest.java +++ b/core/src/test/java/org/everit/json/schema/loader/internal/TypeBasedMultiplexerTest.java @@ -21,7 +21,8 @@ import org.hamcrest.TypeSafeMatcher; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.net.URI; @@ -141,14 +142,16 @@ public void relpathWithFragment() { "http://x.y.z:8080/rootschema.json"); } - @Test(expected = SchemaException.class) + @Test public void typeBasedMultiplexerFailure() { - new TypeBasedMultiplexer("foo") - .ifObject().then(o -> { - }) - .ifIs(JSONArray.class).then(o -> { - }) - .requireAny(); + Assertions.assertThrows(SchemaException.class, () -> { + new TypeBasedMultiplexer("foo") + .ifObject().then(o -> { + }) + .ifIs(JSONArray.class).then(o -> { + }) + .requireAny(); + }); } @Test diff --git a/core/src/test/java/org/everit/json/schema/regexp/JavaUtilRegexpTest.java b/core/src/test/java/org/everit/json/schema/regexp/JavaUtilRegexpTest.java index da085a4d3..d2ec93954 100644 --- a/core/src/test/java/org/everit/json/schema/regexp/JavaUtilRegexpTest.java +++ b/core/src/test/java/org/everit/json/schema/regexp/JavaUtilRegexpTest.java @@ -1,17 +1,17 @@ package org.everit.json.schema.regexp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.regex.Pattern; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + public class JavaUtilRegexpTest { static final String PATTERN = "^aa.*b$"; diff --git a/core/src/test/java/org/everit/json/schema/regexp/RE2JRegexpTest.java b/core/src/test/java/org/everit/json/schema/regexp/RE2JRegexpTest.java index 974756232..39d8c69c1 100644 --- a/core/src/test/java/org/everit/json/schema/regexp/RE2JRegexpTest.java +++ b/core/src/test/java/org/everit/json/schema/regexp/RE2JRegexpTest.java @@ -1,16 +1,15 @@ package org.everit.json.schema.regexp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import java.util.Optional; -import org.junit.Test; - import com.google.re2j.Pattern; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +import org.junit.jupiter.api.Test; public class RE2JRegexpTest { diff --git a/tests/android/pom.xml b/tests/android/pom.xml index 314308a98..5d709408f 100644 --- a/tests/android/pom.xml +++ b/tests/android/pom.xml @@ -59,9 +59,9 @@ - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-engine + 5.7.0 test diff --git a/tests/vanilla/pom.xml b/tests/vanilla/pom.xml index 7329edcbc..636d87d90 100644 --- a/tests/vanilla/pom.xml +++ b/tests/vanilla/pom.xml @@ -44,9 +44,9 @@ 2.6 - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter + 5.7.0 org.reflections diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/EmptyObjectTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/EmptyObjectTest.java index c59e1286d..8a8498dbd 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/EmptyObjectTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/EmptyObjectTest.java @@ -7,7 +7,7 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class EmptyObjectTest { diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/InvalidObjectInArrayTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/InvalidObjectInArrayTest.java index feb719812..32e8576cf 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/InvalidObjectInArrayTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/InvalidObjectInArrayTest.java @@ -8,8 +8,8 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class InvalidObjectInArrayTest { @@ -28,9 +28,9 @@ public void test() { Object subject = readObject("subject.json"); try { schema.validate(subject); - Assert.fail("did not throw exception"); + Assertions.fail("did not throw exception"); } catch (ValidationException e) { - Assert.assertEquals("#/notification/target/apps/0/id", e.getPointerToViolation()); + Assertions.assertEquals("#/notification/target/apps/0/id", e.getPointerToViolation()); } } diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/IssueTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/IssueTest.java index 22ad2314b..682a8ae69 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/IssueTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/IssueTest.java @@ -3,7 +3,7 @@ import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; import static org.everit.json.schema.loader.OrgJsonUtil.toMap; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.InputStream; @@ -29,34 +29,29 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Assume; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; -@RunWith(Parameterized.class) public class IssueTest { - @Parameters(name = "{1}") - public static List params() { - List rval = new ArrayList<>(); + public static List params() { + List rval = new ArrayList<>(); Reflections refs = new Reflections("org.everit.json.schema.issues", new ResourcesScanner()); Set paths = refs.getResources(Pattern.compile("schema.json")) .stream().map(path -> path.substring(0, path.lastIndexOf('/'))) .collect(Collectors.toSet()); for (String path : paths) { - rval.add(new Object[] { path, path.substring(path.lastIndexOf('/') + 1) }); + rval.add(Arguments.of(path, path.substring(path.lastIndexOf('/') + 1))); } return rval; } - private final String issueDir; - - private final String testCaseName; + private String issueDir; private JettyWrapper servletSupport; @@ -68,11 +63,6 @@ public static List params() { private Validator.ValidatorBuilder validatorBuilder = Validator.builder(); - public IssueTest(String issueDir, String testCaseName) { - this.issueDir = "/" + requireNonNull(issueDir, "issueDir cannot be null"); - this.testCaseName = testCaseName; - } - private Optional fileByName(final String fileName) { return Optional.ofNullable(getClass().getResourceAsStream(issueDir + "/" + fileName)); } @@ -171,9 +161,11 @@ private void stopJetty() { } } - @Test - public void test() { - Assume.assumeFalse("issue dir starts with 'x' - ignoring", testCaseName.startsWith("x")); + @ParameterizedTest + @MethodSource("params") + public void test(String issueDir, String testCaseName) { + this.issueDir = "/" + requireNonNull(issueDir, "issueDir cannot be null"); + Assumptions.assumeFalse(testCaseName.startsWith("x"), "issue dir starts with 'x' - ignoring"); fileByName("remotes").ifPresent(unused -> initJetty()); try { Schema schema = loadSchema(); diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/MetaSchemaTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/MetaSchemaTest.java index 6c411586d..45f1ae419 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/MetaSchemaTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/MetaSchemaTest.java @@ -7,7 +7,7 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MetaSchemaTest { diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/RelativeURITest.java b/tests/vanilla/src/main/java/org/everit/json/schema/RelativeURITest.java index 2ee937b7e..7b07b2e22 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/RelativeURITest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/RelativeURITest.java @@ -4,7 +4,7 @@ import org.everit.json.schema.loader.SchemaLoader; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RelativeURITest { diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/TestCase.java b/tests/vanilla/src/main/java/org/everit/json/schema/TestCase.java index db8dd92c8..856e5eac5 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/TestCase.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/TestCase.java @@ -1,7 +1,5 @@ package org.everit.json.schema; -import static org.junit.Assert.assertNotEquals; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -18,9 +16,12 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; +import org.junit.jupiter.params.provider.Arguments; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + /** * @author erosb */ @@ -34,8 +35,8 @@ private static JSONArray loadTests(InputStream input) { } } - static List loadAsParamsFromPackage(String packageName) { - List rval = new ArrayList<>(); + static List loadAsParamsFromPackage(String packageName) { + List rval = new ArrayList<>(); Reflections refs = new Reflections(packageName, new ResourcesScanner()); Set paths = refs.getResources(Pattern.compile(".*\\.json")); @@ -51,7 +52,7 @@ static List loadAsParamsFromPackage(String packageName) { for (int j = 0; j < testcaseInputs.length(); ++j) { JSONObject input = testcaseInputs.getJSONObject(j); TestCase testcase = new TestCase(input, schemaTest, fileName); - rval.add(new Object[] { testcase, testcase.schemaDescription }); + rval.add(Arguments.of(testcase, testcase.schemaDescription )); } } } diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/TestSuiteTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/TestSuiteTest.java index 587d93cdb..8a5f9860f 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/TestSuiteTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/TestSuiteTest.java @@ -3,47 +3,42 @@ import java.util.List; import org.everit.json.schema.loader.SchemaLoader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + public class TestSuiteTest { private static JettyWrapper server; - @Parameters(name = "{1}") - public static List params() { + public static List params() { return TestCase.loadAsParamsFromPackage("org.everit.json.schema.draft4"); } - @BeforeClass + @BeforeAll public static void startJetty() throws Exception { (server = new JettyWrapper("/org/everit/json/schema/remotes")).start(); } - @AfterClass + @AfterAll public static void stopJetty() throws Exception { server.stop(); } - private TestCase tc; - - public TestSuiteTest(TestCase testcase, String descr) { - this.tc = testcase; + @ParameterizedTest + @MethodSource("params") + public void testInCollectingMode(TestCase tc) { tc.loadSchema(SchemaLoader.builder()); - } - - @Test - public void testInCollectingMode() { tc.runTestInCollectingMode(); } - @Test - public void testInEarlyFailingMode() { + @ParameterizedTest + @MethodSource("params") + public void testInEarlyFailingMode(TestCase tc) { + tc.loadSchema(SchemaLoader.builder()); tc.runTestInEarlyFailureMode(); } diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/V6TestSuiteTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/V6TestSuiteTest.java index 70aaabd2c..7a9cd160b 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/V6TestSuiteTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/V6TestSuiteTest.java @@ -3,49 +3,45 @@ import java.util.List; import org.everit.json.schema.loader.SchemaLoader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * @author erosb */ -@RunWith(Parameterized.class) public class V6TestSuiteTest { private static JettyWrapper server; - @Parameterized.Parameters(name = "{1}") - public static List params() { + public static List params() { return TestCase.loadAsParamsFromPackage("org.everit.json.schema.draft6"); } - @BeforeClass + @BeforeAll public static void startJetty() throws Exception { (server = new JettyWrapper("/org/everit/json/schema/remotes")).start(); } - @AfterClass + @AfterAll public static void stopJetty() throws Exception { server.stop(); } - private TestCase tc; - - public V6TestSuiteTest(TestCase testcase, String descr) { - this.tc = testcase; + @ParameterizedTest + @MethodSource("params") + public void testInCollectingMode(TestCase tc) { tc.loadSchema(SchemaLoader.builder().draftV6Support()); - } - - @Test - public void testInCollectingMode() { tc.runTestInCollectingMode(); } - @Test - public void testInEarlyFailingMode() { + @ParameterizedTest + @MethodSource("params") + public void testInEarlyFailingMode(TestCase tc) { + tc.loadSchema(SchemaLoader.builder().draftV6Support()); tc.runTestInEarlyFailureMode(); } diff --git a/tests/vanilla/src/main/java/org/everit/json/schema/V7TestSuiteTest.java b/tests/vanilla/src/main/java/org/everit/json/schema/V7TestSuiteTest.java index a37335036..cca1131f0 100644 --- a/tests/vanilla/src/main/java/org/everit/json/schema/V7TestSuiteTest.java +++ b/tests/vanilla/src/main/java/org/everit/json/schema/V7TestSuiteTest.java @@ -3,49 +3,45 @@ import java.util.List; import org.everit.json.schema.loader.SchemaLoader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * @author erosb */ -@RunWith(Parameterized.class) public class V7TestSuiteTest { private static JettyWrapper server; - @Parameterized.Parameters(name = "{1}") - public static List params() { + public static List params() { return TestCase.loadAsParamsFromPackage("org.everit.json.schema.draft7"); } - @BeforeClass + @BeforeAll public static void startJetty() throws Exception { (server = new JettyWrapper("/org/everit/json/schema/remotes")).start(); } - @AfterClass + @AfterAll public static void stopJetty() throws Exception { server.stop(); } - private TestCase tc; - - public V7TestSuiteTest(TestCase testcase, String descr) { - this.tc = testcase; + @ParameterizedTest + @MethodSource("params") + public void testInCollectingMode(TestCase tc) { tc.loadSchema(SchemaLoader.builder().draftV7Support()); - } - - @Test - public void testInCollectingMode() { tc.runTestInCollectingMode(); } - @Test - public void testInEarlyFailingMode() { + @ParameterizedTest + @MethodSource("params") + public void testInEarlyFailingMode(TestCase tc) { + tc.loadSchema(SchemaLoader.builder().draftV7Support()); tc.runTestInEarlyFailureMode(); } }