Skip to content

Commit fc55b4d

Browse files
committed
Streamline test a bit
1 parent 7553e76 commit fc55b4d

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/AvroTestBase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ protected AvroSchema getStringMapSchema() throws IOException {
282282
return getMapper().schemaFrom(STRING_MAP_SCHEMA_JSON);
283283
}
284284

285+
protected AvroSchema parseSchema(String schemaAsJson) {
286+
return parseSchema(getMapper(), schemaAsJson);
287+
}
288+
289+
protected AvroSchema parseSchema(AvroMapper mapper, String schemaAsJson) {
290+
try {
291+
return getMapper().schemaFrom(aposToQuotes(schemaAsJson));
292+
} catch (IOException e) {
293+
fail("Could not parse Avro Schema from: "+schemaAsJson+", problem: "+e);
294+
return null;
295+
}
296+
}
297+
285298
protected AvroMapper getMapper() {
286299
if (_sharedMapper == null) {
287300
_sharedMapper = newMapper();

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/EmptyRecordRead177Test.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.fasterxml.jackson.dataformat.avro.failing;
22

3-
import org.apache.avro.Schema;
4-
import org.apache.avro.SchemaBuilder;
5-
63
import com.fasterxml.jackson.annotation.JsonAutoDetect;
74

85
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
@@ -13,11 +10,8 @@ public class EmptyRecordRead177Test extends AvroTestBase
1310
{
1411
private final AvroMapper MAPPER = getMapper();
1512

16-
private Schema SCHEMA = SchemaBuilder
17-
.builder(EmptyRecordRead177Test.class.getName() + "$")
18-
.record(Empty.class.getSimpleName())
19-
.fields()
20-
.endRecord();
13+
private final AvroSchema SCHEMA = parseSchema(MAPPER,
14+
"{'type':'record', 'name':'Empty','namespace':'something','fields':[]}");
2115

2216
@JsonAutoDetect // just a marker to avoid "no properties found" exception
2317
static final class Empty {
@@ -29,11 +23,11 @@ public boolean equals(Object o) {
2923

3024
public void testEmptyRecord() throws Exception {
3125
final Empty empty = new Empty();
32-
33-
byte[] ser = MAPPER.writer().with(new AvroSchema(SCHEMA)).writeValueAsBytes(empty);
26+
27+
byte[] ser = MAPPER.writer().with(SCHEMA).writeValueAsBytes(empty);
3428

3529
final Empty result = MAPPER.readerFor(Empty.class)
36-
.with(new AvroSchema(SCHEMA))
30+
.with(SCHEMA)
3731
.readValue(ser);
3832

3933
assertEquals(empty, result);

0 commit comments

Comments
 (0)