|
2 | 2 |
|
3 | 3 | import java.io.IOException;
|
4 | 4 | import java.util.Arrays;
|
| 5 | +import java.util.HashMap; |
5 | 6 | import java.util.List;
|
| 7 | +import java.util.Map; |
6 | 8 |
|
7 | 9 | import org.apache.avro.UnresolvedUnionException;
|
8 | 10 | import org.apache.avro.reflect.Nullable;
|
@@ -87,17 +89,21 @@ public boolean equals(Object o) {
|
87 | 89 | public static class PetShop {
|
88 | 90 | public List<Animal> pets;
|
89 | 91 |
|
| 92 | + public Map<String, Animal> specialPets; |
| 93 | + |
90 | 94 | protected PetShop() { }
|
91 | 95 | public PetShop(Animal... p) {
|
92 | 96 | pets = Arrays.asList(p);
|
| 97 | + specialPets = new HashMap<>(); |
93 | 98 | }
|
94 | 99 |
|
95 | 100 | @Override
|
96 | 101 | public boolean equals(Object o) {
|
97 | 102 | if (o.getClass() == getClass()) {
|
98 | 103 | PetShop other = (PetShop) o;
|
99 | 104 | if (pets == null) return other.pets == null;
|
100 |
| - else return pets.equals(other.pets); |
| 105 | + if (specialPets == null) return other.specialPets == null; |
| 106 | + else return pets.equals(other.pets) && specialPets.equals(other.specialPets); |
101 | 107 | }
|
102 | 108 | return false;
|
103 | 109 | }
|
@@ -142,4 +148,15 @@ public void testListWithInterfaceUnion() throws IOException {
|
142 | 148 | assertThat(result).isEqualTo(shop);
|
143 | 149 | }
|
144 | 150 |
|
| 151 | + @Test |
| 152 | + public void testMapWithInterfaceUnion() throws IOException { |
| 153 | + PetShop shop = new PetShop(new Cat("tabby"), new Dog(4), new Dog(5), new Cat("calico")); |
| 154 | + shop.specialPets.put("pet1", new Cat("siamese")); |
| 155 | + shop.specialPets.put("pet2", new Dog(6)); |
| 156 | + // |
| 157 | + PetShop result = roundTrip(shop); |
| 158 | + // |
| 159 | + assertThat(result).isEqualTo(shop); |
| 160 | + } |
| 161 | + |
145 | 162 | }
|
0 commit comments