@@ -264,9 +264,17 @@ public void base_class_explicitly_in_Union_annotation_test() throws Exception {
264264 }
265265
266266 @ Union ({
267- // Interface being explicitly in @Union led to StackOverflowError exception.
268- DocumentInterface .class ,
269- Word .class , Excel .class })
267+ // Interface being explicitly in @Union led to StackOverflowError exception.
268+ DocumentInterface .class ,
269+ // We added a bunch of implementations to test deterministic ordering of the schemas' subtypes ordering.
270+ Word .class ,
271+ Excel .class ,
272+ Pdf .class ,
273+ PowerPoint .class ,
274+ TextDocument .class ,
275+ Markdown .class ,
276+ HtmlDocument .class
277+ })
270278 interface DocumentInterface {
271279 }
272280
@@ -276,11 +284,32 @@ static class Word implements DocumentInterface {
276284 static class Excel implements DocumentInterface {
277285 }
278286
287+ static class Pdf implements DocumentInterface {
288+ }
289+
290+ static class PowerPoint implements DocumentInterface {
291+ }
292+
293+ static class TextDocument implements DocumentInterface {
294+ }
295+
296+ static class Markdown implements DocumentInterface {
297+ }
298+
299+ static class HtmlDocument implements DocumentInterface {
300+ }
301+
302+
279303 @ Test
280304 public void interface_explicitly_in_Union_annotation_test () throws Exception {
281305 // GIVEN
282306 final Schema wordSchema = MAPPER .schemaFor (Word .class ).getAvroSchema ();
283307 final Schema excelSchema = MAPPER .schemaFor (Excel .class ).getAvroSchema ();
308+ final Schema pdfSchema = MAPPER .schemaFor (Pdf .class ).getAvroSchema ();
309+ final Schema powerPointSchema = MAPPER .schemaFor (PowerPoint .class ).getAvroSchema ();
310+ final Schema textSchema = MAPPER .schemaFor (TextDocument .class ).getAvroSchema ();
311+ final Schema markdownSchema = MAPPER .schemaFor (Markdown .class ).getAvroSchema ();
312+ final Schema htmlSchema = MAPPER .schemaFor (HtmlDocument .class ).getAvroSchema ();
284313
285314 // WHEN
286315 Schema actualSchema = MAPPER .schemaFor (DocumentInterface .class ).getAvroSchema ();
@@ -289,6 +318,16 @@ public void interface_explicitly_in_Union_annotation_test() throws Exception {
289318
290319 // THEN
291320 assertThat (actualSchema .getType ()).isEqualTo (Schema .Type .UNION );
292- assertThat (actualSchema .getTypes ()).containsExactlyInAnyOrder (wordSchema , excelSchema );
321+
322+ // Deterministic order: exactly as declared in @Union (excluding the interface).
323+ assertThat (actualSchema .getTypes ()).containsExactly (
324+ wordSchema ,
325+ excelSchema ,
326+ pdfSchema ,
327+ powerPointSchema ,
328+ textSchema ,
329+ markdownSchema ,
330+ htmlSchema
331+ );
293332 }
294333}
0 commit comments