Mercurial > dive4elements > framework
annotate artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java @ 584:efbdaf72aafe 3.2.x
JSON is not restricted to ASCII
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 02 Nov 2023 17:41:10 +0100 |
parents | 0135bf3bd92b |
children |
rev | line source |
---|---|
583
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 package org.dive4elements.artifacts.common.utils; |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 import static org.junit.Assert.assertEquals; |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 import java.util.HashMap; |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 import java.util.Map; |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 import org.junit.Test; |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 public class JSONTest { |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 @Test |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 public void toJSONString() { |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 final Map<String, Object> json = new HashMap<>(); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 json.put("number", 0); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 json.put("boolean", true); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 json.put("string", "test"); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 final Map<String, Object> object = new HashMap<>(); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
18 object.put("test", "test"); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 json.put("object", object); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 assertEquals("{" |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 + "\"number\":0," |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 + "\"boolean\":true," |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 + "\"string\":\"test\"," |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 + "\"object\":{\"test\":\"test\"}" |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 + "}", |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 JSON.toJSONString(json)); |
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 } |
584
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
29 |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
30 @Test |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
31 public void toNonASCIIJSONString() { |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
32 final Map<String, Object> json = new HashMap<>(); |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
33 json.put("täst", "täst"); |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
34 |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
35 assertEquals("{\"täst\":\"täst\"}", JSON.toJSONString(json)); |
efbdaf72aafe
JSON is not restricted to ASCII
Tom Gottfried <tom@intevation.de>
parents:
583
diff
changeset
|
36 } |
583
0135bf3bd92b
Add minimal test for JSON utility class
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 } |