Skip to content

Commit bef6905

Browse files
committed
Fix a broken Avro unit test
1 parent 59eba80 commit bef6905

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/ApacheAvroInteropUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public byte[] apply(Schema schema, Object originalObject) throws IOException {
8888
}
8989
};
9090

91-
private static final AvroMapper MAPPER = new AvroMapper(new AvroModule());
91+
private static final AvroMapper MAPPER = new AvroMapper();
9292

9393
/*
9494
* Special subclass of ReflectData that knows how to resolve and bind generic types. This saves us much pain of

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/interop/annotations/AvroNameTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.fasterxml.jackson.dataformat.avro.interop.annotations;
22

3-
import java.io.IOException;
4-
53
import org.apache.avro.reflect.AvroName;
64
import org.junit.Test;
75

6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.fasterxml.jackson.databind.DatabindException;
88
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
99
import com.fasterxml.jackson.dataformat.avro.AvroTestBase;
1010
import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase;
@@ -31,6 +31,7 @@ public static class RecordWithNameCollision {
3131
@AvroName("otherField")
3232
public String firstField;
3333

34+
@JsonProperty
3435
public String otherField;
3536
}
3637

@@ -42,16 +43,26 @@ public void testRecordWithRenamedField() throws Exception{
4243
assertThat(result).isEqualTo(original);
4344
}
4445

45-
// 02-Nov-2023, tatu: This test has been disabled for some reason, but
46-
// without commentary. Fixed it a bit but ultimately can't enable yet
46+
// 02-Nov-2023, tatu: This test had been disabled for long time:
47+
// "Jackson Schema" case did not consider conflict where it was
48+
// possible to select precedence... so needed to add another
49+
// annotation to force problem.
4750

48-
// @Test
51+
@Test
4952
public void testRecordWithNameCollision() throws Exception {
5053
try {
5154
schemaFunctor.apply(RecordWithNameCollision.class);
5255
fail("Should not pass");
53-
} catch (InvalidDefinitionException e) {
54-
AvroTestBase.verifyException(e, "double field entry: otherField");
56+
} catch (DatabindException e) {
57+
// InvalidDefinitionException with Avro schema
58+
// JsonMapping with Jackson Schema
59+
60+
final String msg = e.toString();
61+
62+
if (!msg.contains("double field entry: otherField")
63+
&& !msg.contains("property \"otherField\"")) {
64+
fail("Got exception but without matching message: "+msg);
65+
}
5566
}
5667
}
5768
}

0 commit comments

Comments
 (0)