|
23 | 23 | import co.elastic.clients.util.AllowForbiddenApis;
|
24 | 24 | import jakarta.json.JsonException;
|
25 | 25 | import jakarta.json.spi.JsonProvider;
|
26 |
| -import jakarta.json.stream.JsonGenerator; |
27 | 26 | import org.junit.Assert;
|
28 | 27 | import org.junit.Test;
|
29 | 28 |
|
30 |
| -import java.io.StringWriter; |
31 | 29 | import java.net.URL;
|
32 | 30 | import java.util.Collections;
|
33 | 31 | import java.util.Enumeration;
|
34 |
| -import java.util.function.Consumer; |
35 | 32 |
|
36 | 33 | public class JsonpUtilsTest extends Assert {
|
37 | 34 |
|
@@ -63,52 +60,4 @@ public Enumeration<URL> getResources(String name) {
|
63 | 60 | Thread.currentThread().setContextClassLoader(savedLoader);
|
64 | 61 | }
|
65 | 62 | }
|
66 |
| - |
67 |
| - @Test |
68 |
| - public void testSerializeDoubleOrNull() { |
69 |
| - // ---- Double values |
70 |
| - assertEquals("{\"a\":null}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, Double.NaN, Double.NaN))); |
71 |
| - assertEquals("{\"a\":1.0}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, 1.0, Double.NaN))); |
72 |
| - |
73 |
| - assertEquals("{\"a\":null}", |
74 |
| - orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY))); |
75 |
| - assertEquals("{\"a\":1.0}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, 1.0, Double.POSITIVE_INFINITY))); |
76 |
| - |
77 |
| - assertEquals("{\"a\":null}", |
78 |
| - orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY))); |
79 |
| - assertEquals("{\"a\":1.0}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, 1.0, Double.NEGATIVE_INFINITY))); |
80 |
| - |
81 |
| - assertEquals("{\"a\":null}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, Double.NaN, 0.0))); |
82 |
| - |
83 |
| - // Serialize defined default values |
84 |
| - assertEquals("{\"a\":0.0}", orNullHelper(g -> JsonpUtils.serializeDoubleOrNull(g, 0.0, 0.0))); |
85 |
| - |
86 |
| - } |
87 |
| - |
88 |
| - @Test |
89 |
| - public void testSerializeIntOrNull() { |
90 |
| - assertEquals("{\"a\":null}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, Integer.MAX_VALUE, Integer.MAX_VALUE))); |
91 |
| - assertEquals("{\"a\":1}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, 1, Integer.MAX_VALUE))); |
92 |
| - assertEquals("{\"a\":1}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, 1, 0))); |
93 |
| - |
94 |
| - // Integer.MAX_VALUE is valid if not the default value |
95 |
| - assertEquals("{\"a\":2147483647}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, Integer.MAX_VALUE, 0))); |
96 |
| - assertEquals("{\"a\":2147483647}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, Integer.MAX_VALUE, Integer.MIN_VALUE))); |
97 |
| - |
98 |
| - // Serialize non infinite default values |
99 |
| - assertEquals("{\"a\":0}", orNullHelper(g -> JsonpUtils.serializeIntOrNull(g, 0, 0))); |
100 |
| - } |
101 |
| - |
102 |
| - private static String orNullHelper(Consumer<JsonGenerator> c) { |
103 |
| - StringWriter sw = new StringWriter(); |
104 |
| - JsonGenerator generator = JsonpUtils.provider().createGenerator(sw); |
105 |
| - |
106 |
| - generator.writeStartObject(); |
107 |
| - generator.writeKey("a"); |
108 |
| - c.accept(generator); |
109 |
| - generator.writeEnd(); |
110 |
| - generator.close(); |
111 |
| - |
112 |
| - return sw.toString(); |
113 |
| - } |
114 | 63 | }
|
0 commit comments