From 56b38e771a08597b7440135879ad1630786b594c Mon Sep 17 00:00:00 2001 From: gjoranv Date: Wed, 20 Oct 2021 14:15:00 +0200 Subject: Remove duplicate test util class and dependency to hamcrest-json. --- vespa-http-client/pom.xml | 5 +- .../yahoo/vespa/http/client/JsonTestHelper.java | 61 ---------------------- .../vespa/http/client/runner/JsonReaderTest.java | 4 +- 3 files changed, 5 insertions(+), 65 deletions(-) delete mode 100644 vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java diff --git a/vespa-http-client/pom.xml b/vespa-http-client/pom.xml index 644ee38367e..7028b1802ed 100644 --- a/vespa-http-client/pom.xml +++ b/vespa-http-client/pom.xml @@ -100,8 +100,9 @@ test - uk.co.datumedge - hamcrest-json + com.yahoo.vespa + testutil + ${project.version} test diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java deleted file mode 100644 index b2c8e7c2f4f..00000000000 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/JsonTestHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.client; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.google.common.base.Joiner; -import org.hamcrest.MatcherAssert; - -import java.io.UncheckedIOException; - -import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; - -public class JsonTestHelper { - - private static final ObjectMapper mapper = createMapper(); - - private static ObjectMapper createMapper() { - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new Jdk8Module()); - mapper.registerModule(new JavaTimeModule()); - return mapper; - } - - /** - * Convenience method to input JSON without escaping double quotes and newlines - * Each parameter represents a line of JSON encoded data - * The lines are joined with newline and single quotes are replaced with double quotes - */ - public static String inputJson(String... lines) { - return Joiner.on("\n").join(lines).replaceAll("'", "\""); - } - - /** Structurally compare two JSON encoded strings */ - public static void assertJsonEquals(String inputJson, String expectedJson) { - MatcherAssert.assertThat(inputJson, sameJSONAs(expectedJson)); - } - - /** Structurally compare a {@link JsonNode} and a JSON string. */ - public static void assertJsonEquals(JsonNode left, String rightJson) { - try { - String leftJson = mapper.writeValueAsString(left); - assertJsonEquals(leftJson, rightJson); - } catch (JsonProcessingException e) { - throw new UncheckedIOException(e); - } - } - - /** Structurally compare two {@link JsonNode}s. */ - public static void assertJsonEquals(JsonNode left, JsonNode right) { - try { - String leftJson = mapper.writeValueAsString(left); - String rightJson = mapper.writeValueAsString(right); - assertJsonEquals(leftJson, rightJson); - } catch (JsonProcessingException e) { - throw new UncheckedIOException(e); - } - } -} diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java index 779e4713ce2..0a5b3771958 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/runner/JsonReaderTest.java @@ -12,9 +12,9 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import static com.yahoo.vespa.http.client.JsonTestHelper.inputJson; +import static com.yahoo.test.json.JsonTestHelper.inputJson; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; public class JsonReaderTest { -- cgit v1.2.3