aboutsummaryrefslogtreecommitdiffstats
path: root/testutil/src
diff options
context:
space:
mode:
authorVegard Sjonfjell <vegard@yahoo-inc.com>2016-10-05 15:30:57 +0200
committerVegard Sjonfjell <vegard@yahoo-inc.com>2016-10-05 15:30:57 +0200
commit23cd65bb2d4a25f2d52a70f573ce4a3e25ee6b8c (patch)
tree0f77181a8e2d36540a4ea00b456d00adbe91e607 /testutil/src
parent4ff27fe8063bbe8079d7ddcb49fb1cccaf6d633c (diff)
Move JsonTestHelper to testutil
Diffstat (limited to 'testutil/src')
-rw-r--r--testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java28
1 files changed, 28 insertions, 0 deletions
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..fee6cc2fef0
--- /dev/null
+++ b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
@@ -0,0 +1,28 @@
+// 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));
+ }
+}