11package com .fasterxml .jackson .dataformat .avro .schema ;
22
3+ import org .junit .jupiter .api .Test ;
4+
35import com .fasterxml .jackson .annotation .JsonSubTypes ;
4- import com .fasterxml .jackson .databind .JsonMappingException ;
56import com .fasterxml .jackson .dataformat .avro .AvroMapper ;
67import com .fasterxml .jackson .dataformat .avro .annotation .AvroNamespace ;
8+
79import org .apache .avro .Schema ;
810import org .apache .avro .reflect .Union ;
9- import org .junit .jupiter .api .Test ;
10-
11- import java .io .IOException ;
1211
1312import static org .assertj .core .api .Assertions .assertThat ;
1413
@@ -22,31 +21,31 @@ public class PolymorphicTypeAnnotationsTest {
2221 @ JsonSubTypes .Type (value = Cat .class ),
2322 @ JsonSubTypes .Type (value = Dog .class ),
2423 })
25- private interface AnimalInterface {
24+ interface AnimalInterface {
2625 }
2726
28- private static abstract class AbstractMammal implements AnimalInterface {
27+ static abstract class AbstractMammal implements AnimalInterface {
2928 public int legs ;
3029 }
3130
32- private static class Cat extends AbstractMammal {
31+ static class Cat extends AbstractMammal {
3332 public String color ;
3433 }
3534
36- private static class Dog extends AbstractMammal {
35+ static class Dog extends AbstractMammal {
3736 public int size ;
3837 }
3938
4039 @ Test
41- public void subclasses_of_interface_test () throws JsonMappingException {
40+ public void subclasses_of_interface_test () throws Exception {
4241 // GIVEN
4342 final Schema catSchema = MAPPER .schemaFor (Cat .class ).getAvroSchema ();
4443 final Schema dogSchema = MAPPER .schemaFor (Dog .class ).getAvroSchema ();
4544
4645 // WHEN
4746 Schema actualSchema = MAPPER .schemaFor (AnimalInterface .class ).getAvroSchema ();
4847
49- System .out .println ("Animal schema:\n " + actualSchema .toString (true ));
48+ // System.out.println("Animal schema:\n" + actualSchema.toString(true));
5049
5150 // THEN
5251 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -59,22 +58,22 @@ public void subclasses_of_interface_test() throws JsonMappingException {
5958 @ JsonSubTypes .Type (value = Pear .class ),
6059 })
6160 @ AvroNamespace (TEST_NAMESPACE ) // @AvroNamespace makes it easier to create schema string representation
62- private static class Fruit {
61+ static class Fruit {
6362 public boolean eatable ;
6463 }
6564
6665 private static final String FRUIT_ITSELF_SCHEMA_STR = "{\" type\" :\" record\" ,\" name\" :\" Fruit\" ,\" namespace\" :\" test\" ,\" fields\" :[{\" name\" :\" eatable\" ,\" type\" :\" boolean\" }]}" ;
6766
68- private static class Apple extends Fruit {
67+ static class Apple extends Fruit {
6968 public String color ;
7069 }
7170
72- private static class Pear extends Fruit {
71+ static class Pear extends Fruit {
7372 public int seeds ;
7473 }
7574
7675 @ Test
77- public void jsonSubTypes_on_concrete_class_test () throws IOException {
76+ public void jsonSubTypes_on_concrete_class_test () throws Exception {
7877 // GIVEN
7978 final Schema fruitItselfSchema = MAPPER .schemaFrom (FRUIT_ITSELF_SCHEMA_STR ).getAvroSchema ();
8079 final Schema appleSchema = MAPPER .schemaFor (Apple .class ).getAvroSchema ();
@@ -83,7 +82,7 @@ public void jsonSubTypes_on_concrete_class_test() throws IOException {
8382 // WHEN
8483 Schema actualSchema = MAPPER .schemaFor (Fruit .class ).getAvroSchema ();
8584
86- System .out .println ("Fruit schema:\n " + actualSchema .toString (true ));
85+ // System.out.println("Fruit schema:\n" + actualSchema.toString(true));
8786
8887 // THEN
8988 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -95,7 +94,7 @@ public void jsonSubTypes_on_concrete_class_test() throws IOException {
9594 @ JsonSubTypes .Type (value = AbstractWaterVehicle .class ),
9695 })
9796 @ AvroNamespace (TEST_NAMESPACE )
98- private static class Vehicle {
97+ static class Vehicle {
9998 }
10099
101100 private static final String VEHICLE_ITSELF_SCHEMA_STR = "{\" type\" :\" record\" ,\" name\" :\" Vehicle\" ,\" namespace\" :\" test\" ,\" fields\" :[]}" ;
@@ -105,33 +104,33 @@ private static class Vehicle {
105104 @ JsonSubTypes .Type (value = MotorCycle .class ),
106105 })
107106 @ AvroNamespace (TEST_NAMESPACE )
108- private static class LandVehicle extends Vehicle {
107+ static class LandVehicle extends Vehicle {
109108 }
110109
111110 private static final String LAND_VEHICLE_ITSELF_SCHEMA_STR = "{\" type\" :\" record\" ,\" name\" :\" LandVehicle\" ,\" namespace\" :\" test\" ,\" fields\" :[]}" ;
112111
113- private static class Car extends LandVehicle {
112+ static class Car extends LandVehicle {
114113 }
115114
116- private static class MotorCycle extends LandVehicle {
115+ static class MotorCycle extends LandVehicle {
117116 }
118117
119118 @ JsonSubTypes ({
120119 @ JsonSubTypes .Type (value = Boat .class ),
121120 @ JsonSubTypes .Type (value = Submarine .class ),
122121 })
123- private static abstract class AbstractWaterVehicle extends Vehicle {
122+ static abstract class AbstractWaterVehicle extends Vehicle {
124123 public int propellers ;
125124 }
126125
127- private static class Boat extends AbstractWaterVehicle {
126+ static class Boat extends AbstractWaterVehicle {
128127 }
129128
130- private static class Submarine extends AbstractWaterVehicle {
129+ static class Submarine extends AbstractWaterVehicle {
131130 }
132131
133132 @ Test
134- public void jsonSubTypes_of_jsonSubTypes_test () throws IOException {
133+ public void jsonSubTypes_of_jsonSubTypes_test () throws Exception {
135134 // GIVEN
136135 final Schema vehicleItselfSchema = MAPPER .schemaFrom (VEHICLE_ITSELF_SCHEMA_STR ).getAvroSchema ();
137136 final Schema landVehicleItselfSchema = MAPPER .schemaFrom (LAND_VEHICLE_ITSELF_SCHEMA_STR ).getAvroSchema ();
@@ -143,7 +142,7 @@ public void jsonSubTypes_of_jsonSubTypes_test() throws IOException {
143142 // WHEN
144143 Schema actualSchema = MAPPER .schemaFor (Vehicle .class ).getAvroSchema ();
145144
146- System .out .println ("Vehicle schema:\n " + actualSchema .toString (true ));
145+ // System.out.println("Vehicle schema:\n" + actualSchema.toString(true));
147146
148147 // THEN
149148 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -180,15 +179,15 @@ private static class Oxygen extends AbstractGas {
180179 }
181180
182181 @ Test
183- public void class_is_referenced_twice_in_hierarchy_test () throws JsonMappingException {
182+ public void class_is_referenced_twice_in_hierarchy_test () throws Exception {
184183 // GIVEN
185184 final Schema heliumSchema = MAPPER .schemaFor (Helium .class ).getAvroSchema ();
186185 final Schema oxygenSchema = MAPPER .schemaFor (Oxygen .class ).getAvroSchema ();
187186
188187 // WHEN
189188 Schema actualSchema = MAPPER .schemaFor (ElementInterface .class ).getAvroSchema ();
190189
191- System .out .println ("ElementInterface schema:\n " + actualSchema .toString (true ));
190+ // System.out.println("ElementInterface schema:\n" + actualSchema.toString(true));
192191
193192 // THEN
194193 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -203,19 +202,19 @@ public void class_is_referenced_twice_in_hierarchy_test() throws JsonMappingExce
203202 @ JsonSubTypes .Type (value = Png .class ),
204203 })
205204 @ AvroNamespace (TEST_NAMESPACE ) // @AvroNamespace makes it easier to create schema string representation
206- private static class Image {
205+ static class Image {
207206 }
208207
209208 private static final String IMAGE_ITSELF_SCHEMA_STR = "{\" type\" :\" record\" ,\" name\" :\" Image\" ,\" namespace\" :\" test\" ,\" fields\" :[]}" ;
210209
211- private static class Jpeg extends Image {
210+ static class Jpeg extends Image {
212211 }
213212
214- private static class Png extends Image {
213+ static class Png extends Image {
215214 }
216215
217216 @ Test
218- public void base_class_explicitly_in_JsonSubTypes_annotation_test () throws IOException {
217+ public void base_class_explicitly_in_JsonSubTypes_annotation_test () throws Exception {
219218 // GIVEN
220219 final Schema imageItselfSchema = MAPPER .schemaFrom (IMAGE_ITSELF_SCHEMA_STR ).getAvroSchema ();
221220 final Schema jpegSchema = MAPPER .schemaFor (Jpeg .class ).getAvroSchema ();
@@ -224,7 +223,7 @@ public void base_class_explicitly_in_JsonSubTypes_annotation_test() throws IOExc
224223 // WHEN
225224 Schema actualSchema = MAPPER .schemaFor (Image .class ).getAvroSchema ();
226225
227- System .out .println ("Image schema:\n " + actualSchema .toString (true ));
226+ // System.out.println("Image schema:\n" + actualSchema.toString(true));
228227
229228 // THEN
230229 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -236,19 +235,19 @@ public void base_class_explicitly_in_JsonSubTypes_annotation_test() throws IOExc
236235 Sport .class ,
237236 Football .class , Basketball .class })
238237 @ AvroNamespace (TEST_NAMESPACE ) // @AvroNamespace makes it easier to create schema string representation
239- private static class Sport {
238+ static class Sport {
240239 }
241240
242241 private static final String SPORT_ITSELF_SCHEMA_STR = "{\" type\" :\" record\" ,\" name\" :\" Sport\" ,\" namespace\" :\" test\" ,\" fields\" :[]}" ;
243242
244- private static class Football extends Sport {
243+ static class Football extends Sport {
245244 }
246245
247- private static class Basketball extends Sport {
246+ static class Basketball extends Sport {
248247 }
249248
250249 @ Test
251- public void base_class_explicitly_in_Union_annotation_test () throws IOException {
250+ public void base_class_explicitly_in_Union_annotation_test () throws Exception {
252251 // GIVEN
253252 final Schema sportItselfSchema = MAPPER .schemaFrom (SPORT_ITSELF_SCHEMA_STR ).getAvroSchema ();
254253 final Schema footballSchema = MAPPER .schemaFor (Football .class ).getAvroSchema ();
@@ -257,7 +256,7 @@ public void base_class_explicitly_in_Union_annotation_test() throws IOException
257256 // WHEN
258257 Schema actualSchema = MAPPER .schemaFor (Sport .class ).getAvroSchema ();
259258
260- System .out .println ("Sport schema:\n " + actualSchema .toString (true ));
259+ // System.out.println("Sport schema:\n" + actualSchema.toString(true));
261260
262261 // THEN
263262 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
@@ -268,29 +267,28 @@ public void base_class_explicitly_in_Union_annotation_test() throws IOException
268267 // Interface being explicitly in @Union led to StackOverflowError exception.
269268 DocumentInterface .class ,
270269 Word .class , Excel .class })
271- private interface DocumentInterface {
270+ interface DocumentInterface {
272271 }
273272
274- private static class Word implements DocumentInterface {
273+ static class Word implements DocumentInterface {
275274 }
276275
277- private static class Excel implements DocumentInterface {
276+ static class Excel implements DocumentInterface {
278277 }
279278
280279 @ Test
281- public void interface_explicitly_in_Union_annotation_test () throws IOException {
280+ public void interface_explicitly_in_Union_annotation_test () throws Exception {
282281 // GIVEN
283282 final Schema wordSchema = MAPPER .schemaFor (Word .class ).getAvroSchema ();
284283 final Schema excelSchema = MAPPER .schemaFor (Excel .class ).getAvroSchema ();
285284
286285 // WHEN
287286 Schema actualSchema = MAPPER .schemaFor (DocumentInterface .class ).getAvroSchema ();
288287
289- System .out .println ("Document schema:\n " + actualSchema .toString (true ));
288+ // System.out.println("Document schema:\n" + actualSchema.toString(true));
290289
291290 // THEN
292291 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
293292 assertThat (actualSchema .getTypes ()).containsExactlyInAnyOrder (wordSchema , excelSchema );
294293 }
295-
296294}
0 commit comments