1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.a.rttests;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import org.apache.juneau.collections.*;
23 import org.apache.juneau.parser.*;
24 import org.apache.juneau.serializer.*;
25 import org.junit.jupiter.params.*;
26 import org.junit.jupiter.params.provider.*;
27
28
29
30
31 class TrimStrings_RoundTripTest extends RoundTripTest_Base {
32
33
34
35
36
37 @ParameterizedTest
38 @MethodSource("testers")
39 void a01_basic(RoundTrip_Tester t) throws Exception {
40 if (t.isValidationOnly())
41 return;
42 var s = t.getSerializer();
43 var p = t.getParser();
44
45 var s2 = s.copy().trimStrings().build();
46 var p2 = p.copy().trimStrings().build();
47
48 var in = (Object)" foo bar ";
49 var e = (Object)"foo bar";
50 var a = (Object)p.parse(s2.serialize(in), String.class);
51 assertEquals(json(a), json(e));
52 a = p2.parse(s.serialize(in), String.class);
53 assertEquals(json(a), json(e));
54
55 in = JsonMap.ofJson("{' foo ': ' bar '}");
56 e = JsonMap.ofJson("{foo:'bar'}");
57 a = p.parse(s2.serialize(in), JsonMap.class);
58 assertEquals(json(a), json(e));
59 a = p2.parse(s.serialize(in), JsonMap.class);
60 assertEquals(json(a), json(e));
61
62 in = new JsonList("[' foo ', {' foo ': ' bar '}]");
63 e = new JsonList("['foo',{foo:'bar'}]");
64 a = p.parse(s2.serialize(in), JsonList.class);
65 assertEquals(json(a), json(e));
66 a = p2.parse(s.serialize(in), JsonList.class);
67 assertEquals(json(a), json(e));
68
69 in = new A().init1();
70 e = new A().init2();
71 a = p.parse(s2.serialize(in), A.class);
72 assertEquals(json(a), json(e));
73 a = p2.parse(s.serialize(in), A.class);
74 assertEquals(json(a), json(e));
75 }
76
77 public static class A {
78 public String f1;
79 public String[] f2;
80 public JsonList f3;
81 public JsonMap f4;
82
83 public A init1() throws Exception {
84 f1 = " f1 ";
85 f2 = new String[]{" f2a ", " f2b "};
86 f3 = JsonList.ofJson("[' f3a ',' f3b ']");
87 f4 = JsonMap.ofJson("{' foo ':' bar '}");
88 return this;
89 }
90
91 public A init2() throws Exception {
92 f1 = "f1";
93 f2 = new String[]{"f2a", "f2b"};
94 f3 = JsonList.ofJson("['f3a','f3b']");
95 f4 = JsonMap.ofJson("{'foo':'bar'}");
96 return this;
97 }
98 }
99 }