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.junit.jupiter.params.*;
23 import org.junit.jupiter.params.provider.*;
24
25
26
27
28
29 class BeanInheritance_RoundTripTest extends RoundTripTest_Base {
30
31
32
33
34
35 @ParameterizedTest
36 @MethodSource("testers")
37 void a01_beanInheritance(RoundTrip_Tester t) throws Exception {
38
39
40 if (t.returnOriginalObject)
41 return;
42
43 var t1 = new A2().init();
44 var t2 = t.roundTrip(t1, A2.class);
45 assertEquals(json(t2), json(t1));
46
47 var t3 = new A3().init();
48 t.roundTrip(t3, A3.class);
49 }
50
51 public abstract static class A1 {
52 protected String x;
53 protected String y;
54 protected String z;
55
56 public A1() {
57 this.x = null;
58 this.y = null;
59 this.z = null;
60 }
61
62 public A1(String x, String y, String z) {
63 this.x = x;
64 this.y = y;
65 this.z = z;
66 }
67
68 public void setX(String v) { x = v; }
69
70 public void setY(String v) { y = v; }
71
72 public void setZ(String v) { z = v; }
73
74 @Override
75 public String toString() {
76 return ("A1(x: " + x + ", y: " + y + ", z: " + z + ")");
77 }
78
79 public A1 init() {
80 x = null;
81 y = "";
82 z = "z";
83 return this;
84 }
85 }
86
87 public static class A2 extends A1 {
88 public A2() {}
89
90 public A2(String x, String y, String z) {
91 super(x, y, z);
92 }
93
94 public String getX() { return x; }
95
96 public String getY() { return y; }
97
98 public String getZ() { return z; }
99 }
100
101
102 public static class A3 extends A1 {
103 public A3() {
104 }
105
106 public A3(String x, String y, String z) {
107 super(x, y, z);
108 }
109
110 public String isX() {
111 throw new IllegalCallerException("Should not be called!");
112 }
113
114 public String isY() {
115 throw new IllegalCallerException("Should not be called!");
116 }
117
118 public String isZ() {
119 throw new IllegalCallerException("Should not be called!");
120 }
121 }
122
123
124
125
126
127 @ParameterizedTest
128 @MethodSource("testers")
129 void a02_beanInheritance(RoundTrip_Tester t) throws Exception {
130 var t1 = new B1().init();
131 var t2 = t. roundTrip(t1, B1.class);
132 assertEquals(json(t2), json(t1));
133 }
134
135 public static class B1 extends B2 {
136 private A2 f4;
137
138 public A2 getF4() { return f4; }
139 public void setF4(A2 v) { f4 = v; }
140
141 @Override
142 public String toString() {
143 return super.toString() + " / " + f4;
144 }
145
146 public B1 init() {
147 setF1("A1");
148 setF2(101);
149 setF3(false);
150 setF4((A2)new A2().init());
151 return this;
152 }
153 }
154
155 public static class B2 {
156 private String f1;
157 private int f2 = -1;
158 private boolean f3;
159
160 public String getF1() { return f1; }
161 public void setF1(String v) { f1 = v; }
162
163 public int getF2() { return f2; }
164 public void setF2(int v) { f2 = v; }
165
166 public boolean isF3() { return f3; }
167 public void setF3(boolean v) { f3 = v; }
168
169 @Override
170 public String toString() {
171 return ("B2(f1: " + getF1() + ", f2: " + getF2() + ")");
172 }
173 }
174 }