|
1 | 1 | package com.fasterxml.jackson.dataformat.avro.interop.annotations; |
2 | 2 |
|
3 | 3 | import java.io.IOException; |
| 4 | +import java.lang.reflect.Type; |
4 | 5 | import java.nio.ByteBuffer; |
5 | 6 | import java.util.*; |
6 | 7 |
|
| 8 | +import org.apache.avro.Schema; |
7 | 9 | import org.apache.avro.SchemaBuilder; |
8 | 10 | import org.apache.avro.io.Decoder; |
9 | 11 | import org.apache.avro.io.Encoder; |
10 | 12 | import org.apache.avro.reflect.*; |
11 | 13 | import org.junit.jupiter.api.BeforeEach; |
12 | 14 | import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.params.ParameterizedTest; |
| 16 | +import org.junit.jupiter.params.provider.MethodSource; |
13 | 17 |
|
14 | 18 | import com.fasterxml.jackson.dataformat.avro.interop.ApacheAvroInteropUtil; |
15 | 19 | import com.fasterxml.jackson.dataformat.avro.interop.InteropTestBase; |
| 20 | +import com.fasterxml.jackson.dataformat.avro.testsupport.BiFunction; |
| 21 | +import com.fasterxml.jackson.dataformat.avro.testsupport.Function; |
16 | 22 |
|
17 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
18 | 24 |
|
@@ -162,47 +168,109 @@ public void setup() throws IOException { |
162 | 168 | cc.stringValue = "Nested Hello World!"; |
163 | 169 | cc.uuidValue = UUID.randomUUID(); |
164 | 170 | wrapper.component.nestedRecordValue = cc; |
165 | | - // |
166 | | - result = roundTrip(wrapper); |
167 | 171 | } |
168 | 172 |
|
169 | | - @Test |
170 | | - public void testByteValue() { |
| 173 | + @MethodSource("getParameters") |
| 174 | + @ParameterizedTest(name = "{3}") |
| 175 | + public void testByteValue( |
| 176 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 177 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 178 | + throws IOException |
| 179 | + { |
| 180 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 181 | + |
| 182 | + result = roundTrip(wrapper); |
171 | 183 | assertThat(result.component.byteValue).isEqualTo(wrapper.component.byteValue); |
172 | 184 | } |
173 | 185 |
|
174 | | - @Test |
175 | | - public void testShortValue() { |
| 186 | + @MethodSource("getParameters") |
| 187 | + @ParameterizedTest(name = "{3}") |
| 188 | + public void testShortValue( |
| 189 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 190 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 191 | + throws IOException |
| 192 | + { |
| 193 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 194 | + result = roundTrip(wrapper); |
| 195 | + |
176 | 196 | assertThat(result.component.shortValue).isEqualTo(wrapper.component.shortValue); |
177 | 197 | } |
178 | 198 |
|
179 | | - @Test |
180 | | - public void testStringValue() { |
| 199 | + @MethodSource("getParameters") |
| 200 | + @ParameterizedTest(name = "{3}") |
| 201 | + public void testStringValue( |
| 202 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 203 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 204 | + throws IOException |
| 205 | + { |
| 206 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 207 | + result = roundTrip(wrapper); |
| 208 | + |
181 | 209 | assertThat(result.component.stringValue).isEqualTo(wrapper.component.stringValue); |
182 | 210 | } |
183 | 211 |
|
184 | | - @Test |
185 | | - public void testDoubleValue() { |
| 212 | + @MethodSource("getParameters") |
| 213 | + @ParameterizedTest(name = "{3}") |
| 214 | + public void testDoubleValue( |
| 215 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 216 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 217 | + throws IOException |
| 218 | + { |
| 219 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 220 | + result = roundTrip(wrapper); |
| 221 | + |
186 | 222 | assertThat(result.component.doubleValue).isEqualTo(wrapper.component.doubleValue); |
187 | 223 | } |
188 | 224 |
|
189 | | - @Test |
190 | | - public void testLongValue() { |
| 225 | + @MethodSource("getParameters") |
| 226 | + @ParameterizedTest(name = "{3}") |
| 227 | + public void testLongValue( |
| 228 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 229 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 230 | + throws IOException |
| 231 | + { |
| 232 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 233 | + result = roundTrip(wrapper); |
| 234 | + |
191 | 235 | assertThat(result.component.longValue).isEqualTo(wrapper.component.longValue); |
192 | 236 | } |
193 | 237 |
|
194 | | - @Test |
195 | | - public void testIntegerValue() { |
| 238 | + @MethodSource("getParameters") |
| 239 | + @ParameterizedTest(name = "{3}") |
| 240 | + public void testIntegerValue( |
| 241 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 242 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 243 | + throws IOException |
| 244 | + { |
| 245 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 246 | + result = roundTrip(wrapper); |
| 247 | + |
196 | 248 | assertThat(result.component.intValue).isEqualTo(wrapper.component.intValue); |
197 | 249 | } |
198 | 250 |
|
199 | | - @Test |
200 | | - public void testNestedUuidValue() { |
| 251 | + @MethodSource("getParameters") |
| 252 | + @ParameterizedTest(name = "{3}") |
| 253 | + public void testNestedUuidValue( |
| 254 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 255 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 256 | + throws IOException |
| 257 | + { |
| 258 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 259 | + result = roundTrip(wrapper); |
| 260 | + |
201 | 261 | assertThat(result.component.nestedRecordValue.uuidValue).isEqualTo(wrapper.component.nestedRecordValue.uuidValue); |
202 | 262 | } |
203 | 263 |
|
204 | | - @Test |
205 | | - public void testUuidValue() { |
| 264 | + @MethodSource("getParameters") |
| 265 | + @ParameterizedTest(name = "{3}") |
| 266 | + public void testUuidValue( |
| 267 | + Function<Type, Schema> schemaFunctor, BiFunction<Schema, Object, byte[]> serializeFunctor, |
| 268 | + BiFunction<Schema, byte[], Object> deserializeFunctor, String combinationName) |
| 269 | + throws IOException |
| 270 | + { |
| 271 | + useParameters(schemaFunctor, serializeFunctor, deserializeFunctor); |
| 272 | + result = roundTrip(wrapper); |
| 273 | + |
206 | 274 | assertThat(result.component.uuidValue).isEqualTo(wrapper.component.uuidValue); |
207 | 275 | } |
208 | 276 | } |
0 commit comments