aboutsummaryrefslogtreecommitdiffstats
path: root/testutil/src/test/java/com/yahoo/test/json/JsonTestHelperTest.java
blob: f4887e22bd6c74032bf340c19d24abf03f7ea9b1 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.test.json;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @author hakonhall
 */
public class JsonTestHelperTest {
    @Test
    public void normalize() {
        verifyNormalization("""
                            {"a": 1, "c": 2,
                              "b": [ {"n": 3, "m": 4}, 5 ]
                            }
                            """,
                            """
                            {
                              "a": 1,
                              "b": [
                                {
                                  "m": 4,
                                  "n": 3
                                },
                                5
                              ],
                              "c": 2
                            }""");

        verifyNormalization("[1,2]", """
                                     [
                                       1,
                                       2
                                     ]""");

        verifyNormalization("null", "null");
        verifyNormalization("{ \n}", "{}");
    }

    private static void verifyNormalization(String json, String normalizedJson) {
        assertEquals(normalizedJson, JsonTestHelper.normalize(json));
    }
}