aboutsummaryrefslogtreecommitdiffstats
path: root/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
blob: a8e8e562b2d8899708199dc0dfeea815e208a60e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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));
    }
}