summaryrefslogtreecommitdiffstats
path: root/testutil
diff options
context:
space:
mode:
authorVegard Sjonfjell <vegardsjo@gmail.com>2016-10-05 16:18:23 +0200
committerVegard Sjonfjell <vegardsjo@gmail.com>2016-10-07 12:50:54 +0200
commit7141a841b0bd85342732072a235c45b78d896fba (patch)
tree1981275dc938af38278b947531ede7bcf9646e0f /testutil
parent92fa424e133b6da2e9d3b49231abf92e3adaa762 (diff)
Revert "Revert "Voffeloff/constant tensor validation""
Diffstat (limited to 'testutil')
-rw-r--r--testutil/pom.xml10
-rw-r--r--testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java29
2 files changed, 39 insertions, 0 deletions
diff --git a/testutil/pom.xml b/testutil/pom.xml
index 0d2aa8a4dbf..bd46d2e4c16 100644
--- a/testutil/pom.xml
+++ b/testutil/pom.xml
@@ -15,6 +15,11 @@
<description>Library of useful Hamcrest matchers.</description>
<dependencies>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>compile</scope>
@@ -25,6 +30,11 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>uk.co.datumedge</groupId>
+ <artifactId>hamcrest-json</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
diff --git a/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
new file mode 100644
index 00000000000..a8e8e562b2d
--- /dev/null
+++ b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
@@ -0,0 +1,29 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.test.json;
+
+import com.google.common.base.Joiner;
+import org.hamcrest.MatcherAssert;
+
+import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
+
+/**
+ * @author Vegard Sjonfjell
+ */
+public class JsonTestHelper {
+
+ /**
+ * 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));
+ }
+}