Skip to content

Commit

Permalink
Fix a broken Avro unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 3, 2023
1 parent 59eba80 commit bef6905
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public byte[] apply(Schema schema, Object originalObject) throws IOException {
}
};

private static final AvroMapper MAPPER = new AvroMapper(new AvroModule());
private static final AvroMapper MAPPER = new AvroMapper();

/*
* Special subclass of ReflectData that knows how to resolve and bind generic types. This saves us much pain of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fasterxml.jackson.dataformat.avro.interop.annotations;

import java.io.IOException;

import org.apache.avro.reflect.AvroName;
import org.junit.Test;

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

@JsonProperty
public String otherField;
}

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

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

// @Test
@Test
public void testRecordWithNameCollision() throws Exception {
try {
schemaFunctor.apply(RecordWithNameCollision.class);
fail("Should not pass");
} catch (InvalidDefinitionException e) {
AvroTestBase.verifyException(e, "double field entry: otherField");
} catch (DatabindException e) {
// InvalidDefinitionException with Avro schema
// JsonMapping with Jackson Schema

final String msg = e.toString();

if (!msg.contains("double field entry: otherField")
&& !msg.contains("property \"otherField\"")) {
fail("Got exception but without matching message: "+msg);
}
}
}
}

0 comments on commit bef6905

Please sign in to comment.