Skip to content

Commit 35a9925

Browse files
authored
Fix broken Avro test #164 (#655)
1 parent 31ad679 commit 35a9925

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

avro/src/test/java/tools/jackson/dataformat/avro/tofix/POJOEvolution164Test.java renamed to avro/src/test/java/tools/jackson/dataformat/avro/schemaev/FieldRemoval164Test.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package tools.jackson.dataformat.avro.tofix;
1+
package tools.jackson.dataformat.avro.schemaev;
22

33
import org.junit.jupiter.api.Test;
44

55
import tools.jackson.dataformat.avro.*;
6-
import tools.jackson.dataformat.avro.testutil.failure.JacksonTestFailureExpected;
76

87
import static org.junit.jupiter.api.Assertions.assertEquals;
98

10-
public class POJOEvolution164Test extends AvroTestBase
9+
// [dataformats-binary#164]
10+
public class FieldRemoval164Test extends AvroTestBase
1111
{
1212
static class MyClass {
1313
public String stringField;
@@ -16,7 +16,7 @@ static class MyClass {
1616

1717
private final AvroMapper MAPPER = getMapper();
1818

19-
@JacksonTestFailureExpected
19+
// [dataformats-binary#164]
2020
@Test
2121
public void testSimpleFieldRemove() throws Exception
2222
{
@@ -46,8 +46,11 @@ public void testSimpleFieldRemove() throws Exception
4646
" ]\n" +
4747
"}";
4848

49-
final AvroSchema readerSchema = MAPPER.schemaFrom(READER_SCHEMA_SRC);
5049
final AvroSchema writerSchema = MAPPER.schemaFrom(WRITER_SCHEMA_SRC);
50+
final AvroSchema readerSchema = MAPPER.schemaFrom(READER_SCHEMA_SRC);
51+
// Must use combined schema that knows both writer (for data layout) and
52+
// reader (for desired output) schemas, to properly skip removed fields
53+
final AvroSchema combinedSchema = writerSchema.withReaderSchema(readerSchema);
5154

5255
MyClass aClass = new MyClass();
5356
aClass.stringField = "String value";
@@ -56,8 +59,8 @@ public void testSimpleFieldRemove() throws Exception
5659
.with(writerSchema)
5760
.writeValueAsBytes(aClass);
5861
MyClass result = MAPPER.readerFor(MyClass.class)
59-
.with(readerSchema)
62+
.with(combinedSchema)
6063
.readValue(avro);
6164
assertEquals(aClass.stringField, result.stringField);
62-
}
65+
}
6366
}

0 commit comments

Comments
 (0)