@@ -254,9 +254,17 @@ public void base_class_explicitly_in_Union_annotation_test() throws Exception {
254254 }
255255
256256 @ Union ({
257- // Interface being explicitly in @Union led to StackOverflowError exception.
258- DocumentInterface .class ,
259- Word .class , Excel .class })
257+ // Interface being explicitly in @Union led to StackOverflowError exception.
258+ DocumentInterface .class ,
259+ // We added a bunch of implementations to test deterministic ordering of the schemas' subtypes ordering.
260+ Word .class ,
261+ Excel .class ,
262+ Pdf .class ,
263+ PowerPoint .class ,
264+ TextDocument .class ,
265+ Markdown .class ,
266+ HtmlDocument .class
267+ })
260268 interface DocumentInterface {
261269 }
262270
@@ -266,11 +274,32 @@ static class Word implements DocumentInterface {
266274 static class Excel implements DocumentInterface {
267275 }
268276
277+ static class Pdf implements DocumentInterface {
278+ }
279+
280+ static class PowerPoint implements DocumentInterface {
281+ }
282+
283+ static class TextDocument implements DocumentInterface {
284+ }
285+
286+ static class Markdown implements DocumentInterface {
287+ }
288+
289+ static class HtmlDocument implements DocumentInterface {
290+ }
291+
292+
269293 @ Test
270294 public void interface_explicitly_in_Union_annotation_test () throws Exception {
271295 // GIVEN
272296 final Schema wordSchema = MAPPER .schemaFor (Word .class ).getAvroSchema ();
273297 final Schema excelSchema = MAPPER .schemaFor (Excel .class ).getAvroSchema ();
298+ final Schema pdfSchema = MAPPER .schemaFor (Pdf .class ).getAvroSchema ();
299+ final Schema powerPointSchema = MAPPER .schemaFor (PowerPoint .class ).getAvroSchema ();
300+ final Schema textSchema = MAPPER .schemaFor (TextDocument .class ).getAvroSchema ();
301+ final Schema markdownSchema = MAPPER .schemaFor (Markdown .class ).getAvroSchema ();
302+ final Schema htmlSchema = MAPPER .schemaFor (HtmlDocument .class ).getAvroSchema ();
274303
275304 // WHEN
276305 Schema actualSchema = MAPPER .schemaFor (DocumentInterface .class ).getAvroSchema ();
@@ -279,6 +308,16 @@ public void interface_explicitly_in_Union_annotation_test() throws Exception {
279308
280309 // THEN
281310 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
282- assertThat (actualSchema .getTypes ()).containsExactlyInAnyOrder (wordSchema , excelSchema );
311+
312+ // Deterministic order: exactly as declared in @Union (excluding the interface).
313+ assertThat (actualSchema .getTypes ()).containsExactly (
314+ wordSchema ,
315+ excelSchema ,
316+ pdfSchema ,
317+ powerPointSchema ,
318+ textSchema ,
319+ markdownSchema ,
320+ htmlSchema
321+ );
283322 }
284323}
0 commit comments