Skip to content

Commit 4b62834

Browse files
committed
Move new Enum-related test into EnumTest
1 parent d4c828e commit 4b62834

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

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

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

3+
import java.util.stream.Collectors;
4+
import java.util.stream.Stream;
5+
6+
import org.apache.avro.Schema;
7+
import org.apache.avro.Schema.Type;
8+
9+
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
10+
311
public class EnumTest extends AvroTestBase
412
{
513
// gender as Avro enum
@@ -118,4 +126,34 @@ public void test_avroSchemaWithString_fromStringValueToEnumValue() throws Except
118126
assertEquals(Gender.F, output.gender);
119127
}
120128

129+
// [dataformats-binary#388]: Default value for enums with class
130+
public void testClassEnumWithDefault() throws Exception
131+
{
132+
AvroSchemaGenerator gen = new AvroSchemaGenerator();
133+
134+
MAPPER.acceptJsonFormatVisitor(ABCDefaultClass.class, gen);
135+
AvroSchema schema = gen.getGeneratedSchema();
136+
assertNotNull(schema);
137+
138+
String json = schema.getAvroSchema().toString(true);
139+
assertNotNull(json);
140+
141+
// And read it back too just for fun
142+
AvroSchema s2 = MAPPER.schemaFrom(json);
143+
assertNotNull(s2);
144+
145+
Schema avroSchema = s2.getAvroSchema();
146+
147+
// String name, int value
148+
assertEquals(Type.RECORD, avroSchema.getType());
149+
Schema.Field f = avroSchema.getField("abc");
150+
assertNotNull(f);
151+
assertEquals("abc", f.name());
152+
153+
assertEquals(Type.ENUM, f.schema().getType());
154+
assertEquals(ABC.C.toString(), f.schema().getEnumDefault());
155+
assertEquals(Stream.of(ABC.values())
156+
.map(ABC::name)
157+
.collect(Collectors.toList()), f.schema().getEnumSymbols());
158+
}
121159
}

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaGenerationTest.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.nio.ByteBuffer;
44
import java.util.*;
5-
import java.util.stream.Collectors;
6-
import java.util.stream.Stream;
75

86
import com.fasterxml.jackson.annotation.JsonAlias;
97
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -13,7 +11,6 @@
1311
import com.fasterxml.jackson.dataformat.avro.*;
1412

1513
import org.apache.avro.Schema;
16-
import org.apache.avro.Schema.Type;
1714

1815
public class AvroSchemaGenerationTest extends AvroTestBase
1916
{
@@ -172,38 +169,4 @@ public void testSchemaForUntypedMap() throws Exception
172169
verifyException(e, "Maps with non-stringable keys are not supported (yet?)");
173170
}
174171
}
175-
176-
// Issue 388 Default value for enums with class
177-
public void testClassEnumWithDefault() throws Exception
178-
{
179-
AvroSchemaGenerator gen = new AvroSchemaGenerator();
180-
181-
MAPPER.acceptJsonFormatVisitor(ABCDefaultClass.class, gen);
182-
AvroSchema schema = gen.getGeneratedSchema();
183-
assertNotNull(schema);
184-
185-
String json = schema.getAvroSchema().toString(true);
186-
assertNotNull(json);
187-
188-
189-
// And read it back too just for fun
190-
AvroSchema s2 = MAPPER.schemaFrom(json);
191-
assertNotNull(s2);
192-
193-
Schema avroSchema = s2.getAvroSchema();
194-
195-
// String name, int value
196-
assertEquals(Type.RECORD, avroSchema.getType());
197-
Schema.Field f = avroSchema.getField("abc");
198-
assertNotNull(f);
199-
assertEquals("abc", f.name());
200-
201-
assertEquals(Type.ENUM, f.schema().getType());
202-
assertEquals(ABC.C.toString(), f.schema().getEnumDefault());
203-
assertEquals(Stream.of(ABC.values())
204-
.map(ABC::name)
205-
.collect(Collectors.toList()), f.schema().getEnumSymbols());
206-
207-
208-
}
209172
}

0 commit comments

Comments
 (0)