Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to junit-jupiter #993

Merged
merged 1 commit into from Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 12 additions & 16 deletions build.gradle
Expand Up @@ -13,21 +13,20 @@ buildscript {

ext {
libs = [
jsonSmart: 'net.minidev:json-smart:2.5.0',
slf4jApi: 'org.slf4j:slf4j-api:2.0.11',
gson: 'com.google.code.gson:gson:2.10.1',
hamcrest: 'org.hamcrest:hamcrest:2.2',
jsonSmart : 'net.minidev:json-smart:2.5.0',
slf4jApi : 'org.slf4j:slf4j-api:2.0.11',
gson : 'com.google.code.gson:gson:2.10.1',
hamcrest : 'org.hamcrest:hamcrest:2.2',
jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.16.1',
jettison: 'org.codehaus.jettison:jettison:1.5.4',
jsonOrg: 'org.json:json:20231013',
tapestryJson: 'org.apache.tapestry:tapestry-json:5.8.3',
jakartaJsonP: 'jakarta.json:jakarta.json-api:2.0.2',
jakartaJsonB: 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',
jettison : 'org.codehaus.jettison:jettison:1.5.4',
jsonOrg : 'org.json:json:20231013',
tapestryJson : 'org.apache.tapestry:tapestry-json:5.8.3',
jakartaJsonP : 'jakarta.json:jakarta.json-api:2.0.2',
jakartaJsonB : 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',

test: [
test : [
'commons-io:commons-io:2.15.0',
'junit:junit:4.13.+',
'org.junit.vintage:junit-vintage-engine:5.10.+',
'org.junit.jupiter:junit-jupiter:5.10.1',
'org.assertj:assertj-core:3.25.1',
'org.hamcrest:hamcrest:2.2',
'org.glassfish:jakarta.json:2.0.1',
Expand Down Expand Up @@ -80,9 +79,6 @@ subprojects {

test {
useJUnitPlatform()

systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")

testLogging {
events "passed", "skipped", "failed"
}
Expand All @@ -98,7 +94,7 @@ subprojects {
options.addStringOption('Xdoclint:none', '-quiet')
}

if(JavaVersion.current().isJava9Compatible()) {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
Expand Down
6 changes: 2 additions & 4 deletions json-path-assert/build.gradle
@@ -1,10 +1,9 @@

description = "Assertions on Json using JsonPath"

jar {
baseName 'json-path-assert'
bnd (
'Implementation-Title': 'json-path-assert', 'Implementation-Version': archiveVersion
bnd(
'Implementation-Title': 'json-path-assert', 'Implementation-Version': archiveVersion
)
}

Expand All @@ -15,5 +14,4 @@ dependencies {

testImplementation libs.jsonSmart
testImplementation libs.test
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
@@ -1,11 +1,12 @@
package com.jayway.jsonassert;

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

import java.io.InputStream;

import static com.jayway.jsonassert.JsonAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class JsonAssertTest {

Expand Down Expand Up @@ -52,10 +53,10 @@ public void invalid_path() throws Exception {
}


@Test(expected = AssertionError.class)
@Test
public void has_path() throws Exception {

with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]");
assertThrows(AssertionError.class, () -> with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]"));
}

@Test
Expand All @@ -66,10 +67,10 @@ public void assert_gears() throws Exception {
with(JSON).assertThat("$.store.bicycle[?(@.escape == 'Esc\\b\\f\\n\\r\\t\\u002A')]", is(collectionWithSize(equalTo(1))));
}

@Test(expected = AssertionError.class)
@Test
public void failed_error_message() throws Exception {

with(JSON).assertThat("$.store.book[0].category", endsWith("foobar"));
assertThrows(AssertionError.class, () -> with(JSON).assertThat("$.store.book[0].category", endsWith("foobar")));
}

@Test
Expand Down Expand Up @@ -168,25 +169,26 @@ public void testNotDefined() throws Exception {
}


@Test(expected = AssertionError.class)
@Test
public void assert_that_invalid_path_is_thrown() {

JsonAsserter asserter = JsonAssert.with("{\"foo\":\"bar\"}");
asserter.assertEquals("$foo", "bar");
assertThrows(AssertionError.class, () -> asserter.assertEquals("$foo", "bar"));
}

@Test
public void testAssertEqualsInteger() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 23);
}

@Test(expected = AssertionError.class)
@Test
public void testAssertEqualsIntegerInvalidExpected() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 24);
assertThrows(AssertionError.class, () -> with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 24));
}

@Test(expected = AssertionError.class)
@Test
public void testAssertEqualsIntegerInvalidField() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId1", 24);
assertThrows(AssertionError.class, () -> with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId1", 24));
}

private InputStream getResourceAsStream(String resourceName) {
Expand Down
@@ -1,17 +1,17 @@
package com.jayway.jsonpath.matchers;

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

import java.io.File;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

@Ignore
@Disabled
public class DemoTest {
@Test
public void shouldFailOnJsonString() {
Expand Down
@@ -1,10 +1,10 @@
package com.jayway.jsonpath.matchers;

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

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class HasNoJsonPathTest {
private static final String JSON_STRING = "{" +
Expand Down
Expand Up @@ -5,28 +5,28 @@
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class IsJsonFileTest {
private static final File BOOKS_JSON = resourceAsFile("books.json");
private static final File INVALID_JSON = resourceAsFile("invalid.json");

@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}

@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}
Expand Down
Expand Up @@ -5,25 +5,25 @@
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class IsJsonStringTest {
private static final String BOOKS_JSON = resource("books.json");

@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}

@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}
Expand Down
Expand Up @@ -6,18 +6,18 @@
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.withPathEvaluatedTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class IsJsonTest {
private static final String VALID_JSON = resource("example.json");
Expand All @@ -26,12 +26,12 @@ public class IsJsonTest {
private static final File BOOKS_JSON_FILE = resourceAsFile("books.json");
private static final Object BOOKS_JSON_PARSED = parseJson(BOOKS_JSON_STRING);

@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}

@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}
Expand Down
Expand Up @@ -4,9 +4,9 @@
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.matchers.helpers.StrictParsingConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.List;
Expand All @@ -15,21 +15,21 @@
import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class JsonPathMatchersTest {
private static final String BOOKS_JSON = resource("books.json");
private static final String INVALID_JSON = "{ invalid-json }";
private static final File BOOKS_JSON_FILE = resourceAsFile("books.json");

@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
// NOTE: Evaluation depends on the default configuration of JsonPath
Configuration.setDefaults(new StrictParsingConfiguration());
}

@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}
Expand Down
Expand Up @@ -6,16 +6,17 @@
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.List;

import static com.jayway.jsonpath.JsonPath.compile;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class WithJsonPathTest {
private static final ReadContext BOOKS_JSON = JsonPath.parse(resource("books.json"));
Expand Down Expand Up @@ -82,9 +83,9 @@ public void shouldMatchJsonPathEvaluatedToCollectionValue() {
assertThat(BOOKS_JSON, withJsonPath("$..book[2].title", hasItem("Moby Dick")));
}

@Test(expected = InvalidPathException.class)
@Test
public void shouldFailOnInvalidJsonPath() {
withJsonPath("$[}");
assertThrows(InvalidPathException.class, () -> withJsonPath("$[}"));
}

@Test
Expand Down
Expand Up @@ -2,12 +2,12 @@

import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static com.jayway.jsonpath.JsonPath.compile;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withoutJsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class WithoutJsonPathTest {
private static final String JSON_STRING = "{" +
Expand Down
12 changes: 5 additions & 7 deletions json-path/build.gradle
@@ -1,13 +1,12 @@

description = "Java port of Stefan Goessner JsonPath."

jar {
baseName 'json-path'
bnd (
'Automatic-Module-Name': 'json.path',
'Implementation-Title': 'json-path', 'Implementation-Version': archiveVersion,
'Import-Package': 'org.json.*;resolution:=optional, com.google.gson.*;resolution:=optional, com.fasterxml.jackson.*;resolution:=optional, org.apache.tapestry5.json.*;resolution:=optional, org.codehaus.jettison.*;resolution:=optional, jakarta.json.*;resolution:=optional, *',
'Export-Package': 'com.jayway.jsonpath,com.jayway.jsonpath.spi,com.jayway.jsonpath.spi.cache,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper'
bnd(
'Automatic-Module-Name': 'json.path',
'Implementation-Title': 'json-path', 'Implementation-Version': archiveVersion,
'Import-Package': 'org.json.*;resolution:=optional, com.google.gson.*;resolution:=optional, com.fasterxml.jackson.*;resolution:=optional, org.apache.tapestry5.json.*;resolution:=optional, org.codehaus.jettison.*;resolution:=optional, jakarta.json.*;resolution:=optional, *',
'Export-Package': 'com.jayway.jsonpath,com.jayway.jsonpath.spi,com.jayway.jsonpath.spi.cache,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper'
)
}

Expand All @@ -23,5 +22,4 @@ dependencies {
compileOnly libs.jakartaJsonB// , optional

testImplementation libs.test
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}