From 8571eb3579b70e687101cc4f5f90977e69853516 Mon Sep 17 00:00:00 2001 From: Oscar Westra van Holthe - Kind Date: Tue, 20 Feb 2024 11:46:30 +0100 Subject: [PATCH] Upgrade to JUnit 5 and remove Mockito The choice to remove Mockito is because it was only used in one test. --- pom.xml | 12 -- .../java/opwvhk/avro/io/AsAvroParserBase.java | 9 +- .../opwvhk/avro/io/DelegatingResolver.java | 9 -- .../opwvhk/avro/SchemaManipulatorTest.java | 20 +-- .../opwvhk/avro/io/AsAvroParserBaseTest.java | 22 +-- .../avro/io/DelegatingResolverTest.java | 116 +++++++++++----- .../avro/json/JsonAsAvroParserTest.java | 20 +-- .../opwvhk/avro/json/SchemaAnalyzerTest.java | 18 +-- .../opwvhk/avro/util/AvroConversionsTest.java | 12 +- .../opwvhk/avro/util/AvroSchemaUtilsTest.java | 18 +-- .../opwvhk/avro/util/DecimalRangeTest.java | 14 +- .../java/opwvhk/avro/util/IdlUtilsTest.java | 38 ++--- src/test/java/opwvhk/avro/util/UtilsTest.java | 16 +-- .../opwvhk/avro/xml/BasicXmlParsingTest.java | 22 +-- .../java/opwvhk/avro/xml/DataRecordsTest.java | 8 +- .../opwvhk/avro/xml/XmlResolvingTest.java | 30 ++-- .../java/opwvhk/avro/xml/XsdAnalyzerTest.java | 131 +++++++++--------- .../avro/xml/datamodel/TypeStructureTest.java | 16 +-- 18 files changed, 278 insertions(+), 253 deletions(-) diff --git a/pom.xml b/pom.xml index 37d0233..b4e8677 100644 --- a/pom.xml +++ b/pom.xml @@ -148,24 +148,12 @@ - - junit - junit - 4.13.2 - test - org.assertj assertj-core 3.25.3 test - - org.mockito - mockito-core - 5.10.0 - test - org.jetbrains annotations diff --git a/src/main/java/opwvhk/avro/io/AsAvroParserBase.java b/src/main/java/opwvhk/avro/io/AsAvroParserBase.java index 58e6180..57ecbb2 100644 --- a/src/main/java/opwvhk/avro/io/AsAvroParserBase.java +++ b/src/main/java/opwvhk/avro/io/AsAvroParserBase.java @@ -299,7 +299,7 @@ protected List> createResolveRules() { private static final ThreadLocal> SEEN = ThreadLocal.withInitial(HashMap::new); /** - *

Create a {@code ValueResolver} that can resolve written values int the write schema into parsed values in the read schema.

+ *

Create a {@code ValueResolver} that can resolve written values in the write schema into parsed values in the read schema.

* *

This method uses the rules returned by {@link #createResolveRules()}. Please note that these rules are explicitly encouraged to use this method to * resolve elements of composite types. This method guards against infinite recursion, by using a delegating {@code ValueResolver} that receives a delegate @@ -321,12 +321,17 @@ protected ValueResolver createResolver(WriteSchema writeSchema, Schema readSchem } if (resolveRules == null) { + // This method might (but should not) cause recursive calls to the current method. resolveRules = createResolveRules(); } for (ResolveRule rule : resolveRules) { if (rule.test(writeSchema, readSchema)) { + // This method will (but may not) cause recursive calls to the current method. ValueResolver resolver = requireNonNull(rule.createResolver(writeSchema, readSchema)); - // the map contains the DelegatingResolver we put in above: if there's a different resolver for the schemaPair, we exit the method above. + + // The map contains the DelegatingResolver we put in above (otherwise the method would have exited directly after that). + // Now we replace the DelegatingResolver with the created resolver, but we set it in the DelegatingResolver in case that was + // used due to recursion. DelegatingResolver delegatingResolver = requireNonNull((DelegatingResolver) resolversForSeenSchemas.put(schemaPair, resolver)); delegatingResolver.setDelegate(resolver); return resolver; diff --git a/src/main/java/opwvhk/avro/io/DelegatingResolver.java b/src/main/java/opwvhk/avro/io/DelegatingResolver.java index fe6690d..8416572 100644 --- a/src/main/java/opwvhk/avro/io/DelegatingResolver.java +++ b/src/main/java/opwvhk/avro/io/DelegatingResolver.java @@ -6,15 +6,6 @@ public class DelegatingResolver extends ValueResolver { private ValueResolver delegate; - /** - * Tell whether this resolver has a delegate to delegate method calls to. - * - * @return {@code true} if this resolver has a delegate, {@code false} otherwise - */ - public boolean hasDelegate() { - return delegate != null; - } - /** * Set the delegate for this resolver. * diff --git a/src/test/java/opwvhk/avro/SchemaManipulatorTest.java b/src/test/java/opwvhk/avro/SchemaManipulatorTest.java index 4deabc0..2c5a487 100644 --- a/src/test/java/opwvhk/avro/SchemaManipulatorTest.java +++ b/src/test/java/opwvhk/avro/SchemaManipulatorTest.java @@ -7,14 +7,14 @@ import net.jimblackler.jsonschemafriend.GenerationException; import org.apache.avro.Schema; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; -public class SchemaManipulatorTest { +class SchemaManipulatorTest { @Test - public void testSortedDocumentationViaXsd() throws IOException { + void testSortedDocumentationViaXsd() throws IOException { StringBuilder markdown = new StringBuilder(); URL xsdLocation = getClass().getResource("xml/payload.xsd"); @@ -48,7 +48,7 @@ public void testSortedDocumentationViaXsd() throws IOException { } @Test - public void testSortedDocumentationViaJsonSchema() throws GenerationException, URISyntaxException, IOException { + void testSortedDocumentationViaJsonSchema() throws GenerationException, URISyntaxException, IOException { StringBuilder markdown = new StringBuilder(); URL schemaLocation = getClass().getResource("json/TestRecord.schema.json"); @@ -87,7 +87,7 @@ public void testSortedDocumentationViaJsonSchema() throws GenerationException, U } @Test - public void testDocumentationViaAvro() throws IOException { + void testDocumentationViaAvro() throws IOException { URL avroLocation = getClass().getResource("xml/envelope.avsc"); String markDownTable = SchemaManipulator.startFromAvro(avroLocation).asMarkdownTable(); @@ -104,7 +104,7 @@ public void testDocumentationViaAvro() throws IOException { } @Test - public void testManipulationsWithAliases() { + void testManipulationsWithAliases() { // Note: manipulating by schema (and field name) also matches on aliases Schema schema = SchemaManipulator.startFromAvro(SOURCE_SCHEMA) .renameSchema("ns.envelope", "ns.satchel") @@ -121,7 +121,7 @@ public void testManipulationsWithAliases() { } @Test - public void testManipulationsWithoutAliasesByPath() { + void testManipulationsWithoutAliasesByPath() { // Note: manipulating by path cannot match on aliases Schema schema = SchemaManipulator.startFromAvro(SOURCE_SCHEMA) .renameWithoutAliases() @@ -138,7 +138,7 @@ public void testManipulationsWithoutAliasesByPath() { } @Test - public void testUnwrappingArrays1() { + void testUnwrappingArrays1() { Schema schema = SchemaManipulator.startFromAvro(SOURCE_SCHEMA_WITH_ARRAYS) .unwrapArrayAtPath("matchByPath") .unwrapArrays(3) @@ -149,7 +149,7 @@ public void testUnwrappingArrays1() { } @Test - public void testUnwrappingArrays2() { + void testUnwrappingArrays2() { Schema schema = SchemaManipulator.startFromAvro(SOURCE_SCHEMA_WITH_ARRAYS) .unwrapArray("ns.WithArrays", "matchByName") .unwrapArrays(3) @@ -160,7 +160,7 @@ public void testUnwrappingArrays2() { } @Test - public void testManipulatingRecursiveSchemas() { + void testManipulatingRecursiveSchemas() { // Note: manipulating by schema (and field name) also matches on aliases Schema schema = SchemaManipulator.startFromAvro(SOURCE_RECURSIVE_SCHEMA) .renameField("ns.recursive", "rabbitHole", "droste") diff --git a/src/test/java/opwvhk/avro/io/AsAvroParserBaseTest.java b/src/test/java/opwvhk/avro/io/AsAvroParserBaseTest.java index 2c78e18..6f32439 100644 --- a/src/test/java/opwvhk/avro/io/AsAvroParserBaseTest.java +++ b/src/test/java/opwvhk/avro/io/AsAvroParserBaseTest.java @@ -9,19 +9,19 @@ import opwvhk.avro.ResolvingFailure; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.time.ZoneOffset.UTC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class AsAvroParserBaseTest { +class AsAvroParserBaseTest { /* NOTE: This test class is terribly incomplete, as the resolvers it creates cannot be tested without parsing (which this test doesn't cover). */ @Test - public void testTimeZoneOffsetDetermination() { + void testTimeZoneOffsetDetermination() { Clock fixedClock = Clock.fixed(Instant.ofEpochMilli(1681720200000L), UTC); // 2023-04-17T08:30:00.000000000Z assertThat(AsAvroParserBase.asOffset(UTC, fixedClock)).isEqualTo(ZoneOffset.ofHours(0)); @@ -30,7 +30,7 @@ public void testTimeZoneOffsetDetermination() { } @Test - public void testResolvingAllTypes() { + void testResolvingAllTypes() { Schema schema = new Schema.Parser().parse(""" {"type": "record", "name": "AllTypes", "fields": [ {"name": "optionalBoolean", "type": ["null", "boolean"], "aliases": ["bool"]}, @@ -114,7 +114,7 @@ private Object resolveScalar(ValueResolver resolver, Object collector, String pr } @Test - public void testFailuresForUnmatchedBinaryData() { + void testFailuresForUnmatchedBinaryData() { Schema bytesSchema = Schema.create(Schema.Type.BYTES); AsAvroParserBase parserBase = new AsAvroParserBase<>(GenericData.get()) {}; @@ -122,7 +122,7 @@ public void testFailuresForUnmatchedBinaryData() { } @Test - public void testParsingInvalidEnum() { + void testParsingInvalidEnum() { AsAvroParserBase parserBase = new AsAvroParserBase<>(GenericData.get()) {}; Schema enumWithDefault = Schema.createEnum("choice", null, null, List.of("maybe", "yes", "no"), "maybe"); @@ -137,13 +137,13 @@ public void testParsingInvalidEnum() { } @Test - public void coverMethodThatCannotBeCalled() { + void coverMethodThatCannotBeCalled() { // There is no code path that actively causes this failure (that would mean a bug in building resolvers). assertThatThrownBy(() -> new ValueResolver() {}.addContent(null, null)).isInstanceOf(IllegalStateException.class); } @Test - public void testRecordImplicitArrayFields() { + void testRecordImplicitArrayFields() { ValueResolver sr = new ScalarValueResolver(s -> s); Schema.Field f = new Schema.Field("texts", Schema.createArray(Schema.create(Schema.Type.STRING))); RecordResolver rr = new RecordResolver(GenericData.get(), Schema.createRecord("Record", null, null, false, List.of(f))); @@ -157,7 +157,7 @@ public void testRecordImplicitArrayFields() { } @Test - public void testRecordFieldDefaultValues() { + void testRecordFieldDefaultValues() { ValueResolver sr = new ScalarValueResolver(s -> s); Schema optionalString = Schema.createUnion(Schema.create(Schema.Type.STRING), Schema.create(Schema.Type.NULL)); Schema.Field f = new Schema.Field("value", optionalString, null, "missing"); @@ -176,7 +176,7 @@ public void testRecordFieldDefaultValues() { } @Test - public void testRecordContentField() { + void testRecordContentField() { ValueResolver sr = new ScalarValueResolver(s -> s); Schema.Field f = new Schema.Field("value", Schema.create(Schema.Type.STRING), null, "missing"); RecordResolver rr = new RecordResolver(GenericData.get(), Schema.createRecord("Record", null, null, false, List.of(f))); @@ -189,7 +189,7 @@ public void testRecordContentField() { } @Test - public void testValueResolverContentParseFlag() { + void testValueResolverContentParseFlag() { ValueResolver resolver = new ValueResolver(){}; assertThat(resolver.parseContent()).isTrue(); resolver.doNotParseContent(); diff --git a/src/test/java/opwvhk/avro/io/DelegatingResolverTest.java b/src/test/java/opwvhk/avro/io/DelegatingResolverTest.java index 9233a1a..df6ff2c 100644 --- a/src/test/java/opwvhk/avro/io/DelegatingResolverTest.java +++ b/src/test/java/opwvhk/avro/io/DelegatingResolverTest.java @@ -1,53 +1,95 @@ package opwvhk.avro.io; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import java.util.ArrayList; +import java.util.List; -public class DelegatingResolverTest { +import static org.assertj.core.api.Assertions.assertThat; - @Test - public void validateDelegation() { - ValueResolver delegate = mock(ValueResolver.class); - DelegatingResolver resolver = new DelegatingResolver(); +class DelegatingResolverTest { - Object collector = new Object(); - Object value = new Object(); + @Test + void validateDelegation() { + DelegatingResolver resolver = new DelegatingResolver(); - assertThat(resolver.hasDelegate()).isFalse(); + MockResolver delegate = new MockResolver(); + resolver.setDelegate(delegate); - resolver.setDelegate(delegate); - assertThat(resolver.hasDelegate()).isTrue(); + Object collector = new Object(); + Object value = new Object(); - resolver.doNotParseContent(); - verify(delegate).doNotParseContent(); - verifyNoMoreInteractions(delegate); + resolver.doNotParseContent(); + assertThat(delegate.calls()).containsExactly("doNotParseContent()"); - resolver.resolve("name"); - verify(delegate).resolve("name"); - verifyNoMoreInteractions(delegate); + resolver.resolve("name"); + assertThat(delegate.calls()).containsExactly("resolve(name)"); - resolver.createCollector(); - verify(delegate).createCollector(); - verifyNoMoreInteractions(delegate); + resolver.createCollector(); + assertThat(delegate.calls()).containsExactly("createCollector()"); - resolver.addProperty(collector, "name", value); - verify(delegate).addProperty(collector, "name", value); - verifyNoMoreInteractions(delegate); + resolver.addProperty(collector, "name", value); + assertThat(delegate.calls()).containsExactly("addProperty(" + collector + ", name, " + value + ")"); - resolver.addContent(collector, "text"); - verify(delegate).addContent(collector, "text"); - verifyNoMoreInteractions(delegate); + resolver.addContent(collector, "text"); + assertThat(delegate.calls()).containsExactly("addContent(" + collector + ", text)"); - resolver.complete(collector); - verify(delegate).complete(collector); - verifyNoMoreInteractions(delegate); + resolver.complete(collector); + assertThat(delegate.calls()).containsExactly("complete(" + collector + ")"); - resolver.parseContent(); - verify(delegate).parseContent(); - verifyNoMoreInteractions(delegate); - } + resolver.parseContent(); + assertThat(delegate.calls()).containsExactly("parseContent()"); + } + + private static class MockResolver extends ValueResolver { + private List calls = new ArrayList<>(); + + @Override + public void doNotParseContent() { + calls.add("doNotParseContent()"); + super.doNotParseContent(); + } + + @Override + public ValueResolver resolve(String name) { + calls.add("resolve(%s)".formatted(name)); + return super.resolve(name); + } + + @Override + public Object createCollector() { + calls.add("createCollector()"); + return super.createCollector(); + } + + @Override + public Object addProperty(Object collector, String name, Object value) { + calls.add("addProperty(%s, %s, %s)".formatted(collector, name, value)); + return collector; + } + + @Override + public Object addContent(Object collector, String content) { + calls.add("addContent(%s, %s)".formatted(collector, content)); + return collector; + } + + @Override + public Object complete(Object collector) { + calls.add("complete(%s)".formatted(collector)); + return super.complete(collector); + } + + @Override + public boolean parseContent() { + calls.add("parseContent()"); + return super.parseContent(); + } + + private List calls() { + List result = calls; + calls = new ArrayList<>(); + return result; + } + } } diff --git a/src/test/java/opwvhk/avro/json/JsonAsAvroParserTest.java b/src/test/java/opwvhk/avro/json/JsonAsAvroParserTest.java index 3024b15..6e806f0 100644 --- a/src/test/java/opwvhk/avro/json/JsonAsAvroParserTest.java +++ b/src/test/java/opwvhk/avro/json/JsonAsAvroParserTest.java @@ -11,14 +11,14 @@ import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class JsonAsAvroParserTest { +class JsonAsAvroParserTest { @Test - public void testMostTypesWithJsonSchema() throws IOException, GenerationException, URISyntaxException { + void testMostTypesWithJsonSchema() throws IOException, GenerationException, URISyntaxException { Schema readSchema = avroSchema("TestRecord.avsc"); JsonAsAvroParser parser = new JsonAsAvroParser(resourceUri("TestRecord.schema.json"), readSchema, GenericData.get()); @@ -34,7 +34,7 @@ public void testMostTypesWithJsonSchema() throws IOException, GenerationExceptio } @Test - public void testParsingDatesAndTimesWithJsonSchema() throws IOException, URISyntaxException, GenerationException { + void testParsingDatesAndTimesWithJsonSchema() throws IOException, URISyntaxException, GenerationException { Schema readSchema = avroSchema("DatesAndTimes.avsc"); JsonAsAvroParser parser = new JsonAsAvroParser(resourceUri("DatesAndTimes.schema.json"), readSchema, GenericData.get()); @@ -51,7 +51,7 @@ public void testParsingDatesAndTimesWithJsonSchema() throws IOException, URISynt } @Test - public void testParsingEnumDifferentlyThanJsonSchema() throws IOException, URISyntaxException, GenerationException { + void testParsingEnumDifferentlyThanJsonSchema() throws IOException, URISyntaxException, GenerationException { URI jsonSchema = resourceUri("TestRecord.schema.json"); JsonAsAvroParser parser; GenericRecord record; @@ -72,7 +72,7 @@ record = parser.parse(""" } @Test - public void testResolveFailuresWithJsonSchema() throws URISyntaxException { + void testResolveFailuresWithJsonSchema() throws URISyntaxException { URI jsonSchema = resourceUri("TestRecord.schema.json"); GenericData model = GenericData.get(); @@ -87,7 +87,7 @@ public void testResolveFailuresWithJsonSchema() throws URISyntaxException { } @Test - public void testMostTypesFromAvroSchema() throws IOException { + void testMostTypesFromAvroSchema() throws IOException { Schema readSchema = avroSchema("TestRecordProjection.avsc"); JsonAsAvroParser parser = new JsonAsAvroParser(readSchema, GenericData.get()); @@ -102,7 +102,7 @@ public void testMostTypesFromAvroSchema() throws IOException { } @Test - public void testMinimalRecordFromAvroSchema() throws IOException { + void testMinimalRecordFromAvroSchema() throws IOException { Schema readSchema = avroSchema("TestRecordProjection.avsc"); JsonAsAvroParser parser = new JsonAsAvroParser(readSchema, GenericData.get()); @@ -124,7 +124,7 @@ public void testMinimalRecordFromAvroSchema() throws IOException { } @Test - public void testParsingDatesAndTimesFromAvro() throws IOException { + void testParsingDatesAndTimesFromAvro() throws IOException { Schema readSchema = avroSchema("DatesAndTimes.avsc"); JsonAsAvroParser parser = new JsonAsAvroParser(readSchema, GenericData.get()); @@ -141,7 +141,7 @@ public void testParsingDatesAndTimesFromAvro() throws IOException { } @Test - public void testParsingObjectsAndArraysForScalarsFails() { + void testParsingObjectsAndArraysForScalarsFails() { Schema readSchema = new Schema.Parser().parse(""" {"type": "record", "name": "Oops", "fields": [ {"name": "text", "type": "string"} diff --git a/src/test/java/opwvhk/avro/json/SchemaAnalyzerTest.java b/src/test/java/opwvhk/avro/json/SchemaAnalyzerTest.java index 7798db5..85c37d9 100644 --- a/src/test/java/opwvhk/avro/json/SchemaAnalyzerTest.java +++ b/src/test/java/opwvhk/avro/json/SchemaAnalyzerTest.java @@ -8,15 +8,15 @@ import net.jimblackler.jsonschemafriend.GenerationException; import org.apache.avro.Schema; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Objects.requireNonNull; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class SchemaAnalyzerTest { +class SchemaAnalyzerTest { @Test - public void testSchemaVersionDraft4() throws URISyntaxException, GenerationException { + void testSchemaVersionDraft4() throws URISyntaxException, GenerationException { SchemaProperties schemaProperties = parseSchemaResource("draft4-schema.json"); // * range of "number" is not an integer range: type "integer" is NOT inferred because bounds have a fraction // * number range has boolean properties for exclusive bounds @@ -35,7 +35,7 @@ public void testSchemaVersionDraft4() throws URISyntaxException, GenerationExcep } @Test - public void testSchemaVersionDraft6() throws GenerationException, URISyntaxException { + void testSchemaVersionDraft6() throws GenerationException, URISyntaxException { SchemaProperties schemaProperties = parseSchemaResource("draft6-schema.json"); // * range of "number" is an integer range: type "integer" is inferred as no bounds have a non-zero fraction // * number range has separate number properties for exclusive bounds @@ -53,7 +53,7 @@ public void testSchemaVersionDraft6() throws GenerationException, URISyntaxExcep } @Test - public void testSchemaVersionDraft7() throws GenerationException, URISyntaxException { + void testSchemaVersionDraft7() throws GenerationException, URISyntaxException { SchemaProperties schemaProperties = parseSchemaResource("draft7-schema.json"); // * 'contentEncoding', 'if', 'then', 'else' are now applied assertThat(schemaString(schemaProperties)).isEqualTo( @@ -66,7 +66,7 @@ public void testSchemaVersionDraft7() throws GenerationException, URISyntaxExcep } @Test - public void testUnknownSchemaVersion() throws GenerationException, URISyntaxException { + void testUnknownSchemaVersion() throws GenerationException, URISyntaxException { SchemaProperties schemaProperties = parseSchemaResource("unspecified-schema.json"); // Unknown schema causes no references to be resolved by the underlying library assertThat(schemaString(schemaProperties)).isEqualTo( @@ -75,7 +75,7 @@ public void testUnknownSchemaVersion() throws GenerationException, URISyntaxExce } @Test - public void testSchemaVersionDraft2020() throws GenerationException, URISyntaxException { + void testSchemaVersionDraft2020() throws GenerationException, URISyntaxException { SchemaProperties schemaProperties = parseSchemaResource("draft2020-12-schema.json"); // * arrays are defined using 'prefixItems' (an array) & 'items'; 'contains' remains valid, also use 'unevaluatedItems' // * additional structures to test all code paths missed so far @@ -109,7 +109,7 @@ private String schemaString(SchemaProperties schemaProperties) { } @Test - public void verifyTypesFromSchemaProperties() { + void verifyTypesFromSchemaProperties() { SchemaProperties schemaProperties = new SchemaProperties(false); assertThat(schemaProperties) .hasFieldOrPropertyWithValue("nullable", false) @@ -133,7 +133,7 @@ public void verifyTypesFromSchemaProperties() { } @Test - public void testAvroSchemaConversion() throws URISyntaxException, GenerationException, IOException { + void testAvroSchemaConversion() throws URISyntaxException, GenerationException, IOException { assertThatThrownBy(() -> parseSchemaResourceAsAvro("null.schema.json")).isInstanceOf(IllegalArgumentException.class); Schema avroSchema = parseSchemaResourceAsAvro("TestRecord.schema.json"); diff --git a/src/test/java/opwvhk/avro/util/AvroConversionsTest.java b/src/test/java/opwvhk/avro/util/AvroConversionsTest.java index 313a7e1..e360332 100644 --- a/src/test/java/opwvhk/avro/util/AvroConversionsTest.java +++ b/src/test/java/opwvhk/avro/util/AvroConversionsTest.java @@ -11,14 +11,14 @@ import org.apache.avro.LogicalTypes; import org.apache.avro.Schema; import org.apache.avro.data.TimeConversions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.time.ZoneOffset.UTC; import static org.assertj.core.api.Assertions.*; -public class AvroConversionsTest { +class AvroConversionsTest { @Test - public void testTimeMillisBasics() { + void testTimeMillisBasics() { Conversion localTimeConversion = new TimeConversions.TimeMillisConversion(); Conversion offsetTimeConversion = new AvroConversions.OffsetTimeMillisConversion(); assertThat(offsetTimeConversion.getLogicalTypeName()).isEqualTo(localTimeConversion.getLogicalTypeName()); @@ -31,7 +31,7 @@ public void testTimeMillisBasics() { } @Test - public void testTimeMillisConversion() { + void testTimeMillisConversion() { Conversion localTimeConversion = new TimeConversions.TimeMillisConversion(); Conversion offsetTimeConversion = new AvroConversions.OffsetTimeMillisConversion(); @@ -53,7 +53,7 @@ public void testTimeMillisConversion() { } @Test - public void testTimeMicrosBasics() { + void testTimeMicrosBasics() { Conversion localTimeConversion = new TimeConversions.TimeMicrosConversion(); Conversion offsetTimeConversion = new AvroConversions.OffsetTimeMicrosConversion(); assertThat(offsetTimeConversion.getLogicalTypeName()).isEqualTo(localTimeConversion.getLogicalTypeName()); @@ -66,7 +66,7 @@ public void testTimeMicrosBasics() { } @Test - public void testTimeMicrosConversion() { + void testTimeMicrosConversion() { Conversion localTimeConversion = new TimeConversions.TimeMicrosConversion(); Conversion offsetTimeConversion = new AvroConversions.OffsetTimeMicrosConversion(); diff --git a/src/test/java/opwvhk/avro/util/AvroSchemaUtilsTest.java b/src/test/java/opwvhk/avro/util/AvroSchemaUtilsTest.java index 11d2ca5..2ff39de 100644 --- a/src/test/java/opwvhk/avro/util/AvroSchemaUtilsTest.java +++ b/src/test/java/opwvhk/avro/util/AvroSchemaUtilsTest.java @@ -7,15 +7,15 @@ import org.apache.avro.Schema; import org.apache.avro.compiler.idl.Idl; import org.apache.avro.compiler.idl.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.catchThrowable; -public class AvroSchemaUtilsTest { +class AvroSchemaUtilsTest { @Test - public void testMarkdownTable() + void testMarkdownTable() throws ParseException { //language=Avro IDL String idlSchema = """ @@ -90,7 +90,7 @@ record Transaction { } @Test - public void checkDocumentationNewlinesAreHtml() { + void checkDocumentationNewlinesAreHtml() { String textWithNewlines = "Line 1\nLine 2\nLine 3"; AvroSchemaUtils.Entry entry = new AvroSchemaUtils.Entry("path.to.entry", "test", textWithNewlines); assertThat(entry.documentation()).isEqualTo(textWithNewlines); @@ -98,7 +98,7 @@ public void checkDocumentationNewlinesAreHtml() { } @Test - public void testDuplicateNameDetection() throws ParseException { + void testDuplicateNameDetection() throws ParseException { String idlSchema = """ @namespace("ns") protocol dummy { @@ -109,11 +109,11 @@ record WithDuplicates { Good @aliases(["good_field"]) third; string fourth; } - + enum one {on, off} - + fixed two(16); - + record Good { string description; Good rabbitHole; @@ -138,7 +138,7 @@ record Good { } @Test - public void testUnwrappingNullableUnion() { + void testUnwrappingNullableUnion() { Schema nonUnionSchema = Schema.create(Schema.Type.STRING); assertThat(AvroSchemaUtils.nonNullableSchemaOf(nonUnionSchema)).isSameAs(nonUnionSchema); diff --git a/src/test/java/opwvhk/avro/util/DecimalRangeTest.java b/src/test/java/opwvhk/avro/util/DecimalRangeTest.java index 87a5927..8fc7f70 100644 --- a/src/test/java/opwvhk/avro/util/DecimalRangeTest.java +++ b/src/test/java/opwvhk/avro/util/DecimalRangeTest.java @@ -2,19 +2,19 @@ import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.math.BigDecimal.ONE; import static java.math.BigDecimal.ZERO; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class DecimalRangeTest { +class DecimalRangeTest { private static final BigDecimal ONE_AND_A_HALF = new BigDecimal("1.5"); private static final BigDecimal TWO = new BigDecimal("2.0"); @Test - public void testRangeConstruction() { + void testRangeConstruction() { DecimalRange decimalRange = new DecimalRange(bd(1), null, bd(2), null); assertThat(decimalRange.lowerBound()).isEqualTo(ONE); assertThat(decimalRange.lowerBoundInclusive()).isTrue(); @@ -40,7 +40,7 @@ public void testRangeConstruction() { } @Test - public void testRangeInspection() { + void testRangeInspection() { assertThat(new DecimalRange(ZERO, true, ONE_AND_A_HALF, true).isIntegerRange(false)).isFalse(); assertThat(new DecimalRange(ZERO, true, TWO, true).isIntegerRange(false)).isFalse(); assertThat(new DecimalRange(ZERO, true, ONE, true).isIntegerRange(false)).isTrue(); @@ -78,7 +78,7 @@ public void testRangeInspection() { } @Test - public void testRangesAsStrings () { + void testRangesAsStrings() { assertThat(openOpen(null, null).toString()).isEqualTo("(-inf, inf)"); assertThat(closedOpen(bd(1), bd(2, 10)).toString()).isEqualTo("[1, 2.10)"); assertThat(openClosed(null, bd(2, 10)).toString()).isEqualTo("(-inf, 2.10]"); @@ -86,7 +86,7 @@ public void testRangesAsStrings () { } @Test - public void verifyRangeExtension() { + void verifyRangeExtension() { // All tests are double: extendsWith should be commutative // infinity always wins @@ -116,7 +116,7 @@ public void verifyRangeExtension() { } @Test - public void verifyRangeRestriction() { + void verifyRangeRestriction() { // All tests are double: extendsWith should be commutative // infinity never wins diff --git a/src/test/java/opwvhk/avro/util/IdlUtilsTest.java b/src/test/java/opwvhk/avro/util/IdlUtilsTest.java index 689e8b3..5e1d9f9 100644 --- a/src/test/java/opwvhk/avro/util/IdlUtilsTest.java +++ b/src/test/java/opwvhk/avro/util/IdlUtilsTest.java @@ -7,7 +7,7 @@ import org.apache.avro.Schema; import org.apache.avro.compiler.idl.Idl; import org.apache.avro.compiler.idl.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.*; import java.nio.charset.StandardCharsets; @@ -21,9 +21,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class IdlUtilsTest { +class IdlUtilsTest { @Test - public void idlUtilsUtilitiesThrowRuntimeExceptions() { + void idlUtilsUtilitiesThrowRuntimeExceptions() { assertThatThrownBy(() -> IdlUtils.getField(Object.class, "noSuchField")) .isInstanceOf(IllegalStateException.class).hasMessage("Programmer error"); assertThatThrownBy(() -> IdlUtils.getFieldValue(String.class.getDeclaredField("value"), "anything")) @@ -38,7 +38,7 @@ public void idlUtilsUtilitiesThrowRuntimeExceptions() { } @Test - public void validateHappyFlow() throws ParseException, IOException { + void validateHappyFlow() throws ParseException, IOException { StringWriter schemaBuffer = new StringWriter(); try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(getClass().getResourceAsStream("schema.avdl")))) { char[] buf = new char[1024]; @@ -61,19 +61,19 @@ public void validateHappyFlow() throws ParseException, IOException { } @Test - public void cannotWriteUnnamedTypes() { + void cannotWriteUnnamedTypes() { assertThatThrownBy(() -> IdlUtils.writeIdlProtocol("naming", "Error", new StringWriter(), Schema.create(Schema.Type.STRING))).isInstanceOf(AvroRuntimeException.class); } @Test - public void cannotWriteEmptyEnums() { + void cannotWriteEmptyEnums() { assertThatThrownBy(() -> IdlUtils.writeIdlProtocol("naming", "Error", new StringWriter(), Schema.createEnum("Single", null, "naming", emptyList()))).isInstanceOf(IllegalStateException.class); } @Test - public void cannotWriteEmptyUnionTypes() { + void cannotWriteEmptyUnionTypes() { assertThatThrownBy(() -> IdlUtils.writeIdlProtocol("naming", "Error", new StringWriter(), Schema.createRecord("Single", null, "naming", false, singletonList( new Schema.Field("field", Schema.createUnion()) @@ -81,12 +81,12 @@ public void cannotWriteEmptyUnionTypes() { } @Test - public void validateNullToJson() throws IOException { + void validateNullToJson() throws IOException { assertThat(callToJson(JsonProperties.NULL_VALUE)).isEqualTo("null"); } @Test - public void validateMapToJson() throws IOException { + void validateMapToJson() throws IOException { Map data = new LinkedHashMap<>(); data.put("key", "name"); data.put("value", 81763); @@ -94,52 +94,52 @@ public void validateMapToJson() throws IOException { } @Test - public void validateCollectionToJson() throws IOException { + void validateCollectionToJson() throws IOException { assertThat(callToJson(Arrays.asList(123, "abc"))).isEqualTo("[123,\"abc\"]"); } @Test - public void validateBytesToJson() throws IOException { + void validateBytesToJson() throws IOException { assertThat(callToJson("getalletjes".getBytes(StandardCharsets.US_ASCII))).isEqualTo("\"getalletjes\""); } @Test - public void validateStringToJson() throws IOException { + void validateStringToJson() throws IOException { assertThat(callToJson("foo")).isEqualTo("\"foo\""); } @Test - public void validateEnumToJson() throws IOException { + void validateEnumToJson() throws IOException { assertThat(callToJson(SingleValue.FILE_NOT_FOUND)).isEqualTo("\"FILE_NOT_FOUND\""); } @Test - public void validateDoubleToJson() throws IOException { + void validateDoubleToJson() throws IOException { assertThat(callToJson(25_000.025)).isEqualTo("25000.025"); } @Test - public void validateFloatToJson() throws IOException { + void validateFloatToJson() throws IOException { assertThat(callToJson(15_000.002f)).isEqualTo("15000.002"); } @Test - public void validateLongToJson() throws IOException { + void validateLongToJson() throws IOException { assertThat(callToJson(7254378234L)).isEqualTo("7254378234"); } @Test - public void validateIntegerToJson() throws IOException { + void validateIntegerToJson() throws IOException { assertThat(callToJson(123)).isEqualTo("123"); } @Test - public void validateBooleanToJson() throws IOException { + void validateBooleanToJson() throws IOException { assertThat(callToJson(true)).isEqualTo("true"); } @Test - public void validateUnknownCannotBeWrittenAsJson() { + void validateUnknownCannotBeWrittenAsJson() { assertThatThrownBy(() -> callToJson(new Object())).isInstanceOf(AvroRuntimeException.class); } diff --git a/src/test/java/opwvhk/avro/util/UtilsTest.java b/src/test/java/opwvhk/avro/util/UtilsTest.java index cb62d2d..569ea4b 100644 --- a/src/test/java/opwvhk/avro/util/UtilsTest.java +++ b/src/test/java/opwvhk/avro/util/UtilsTest.java @@ -5,21 +5,21 @@ import java.util.Map; import java.util.Objects; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class UtilsTest { +class UtilsTest { @Test - public void digest() { + void digest() { assertThat(Base64.getEncoder().encodeToString(Utils.digest("md5").digest(new byte[0]))).isEqualTo("1B2M2Y8AsgTpgAmY7PhCfg=="); assertThatThrownBy(() -> Utils.digest("foobar")).isInstanceOf(IllegalArgumentException.class).hasMessage("Unknown algorithm"); } @Test - public void findFirstNonNullParameter() { + void findFirstNonNullParameter() { assertThat(Utils.first(1, null, null)).isEqualTo(1); assertThat(Utils.first(null, 2, null)).isEqualTo(2); assertThat(Utils.first(null, null, 3)).isEqualTo(3); @@ -29,7 +29,7 @@ public void findFirstNonNullParameter() { } @Test - public void truncatingText() { + void truncatingText() { assertThat(Utils.truncate(10, null)).isNull(); assertThat(Utils.truncate(30, "This is a simple sentence.")).isEqualTo("This is a simple sentence."); @@ -38,7 +38,7 @@ public void truncatingText() { } @Test - public void testRecursiveEquality() { + void testRecursiveEquality() { Dummy dummy1a = new Dummy("name", null); Dummy dummy1b = new Dummy("name", null); Dummy dummy2 = new Dummy("other", null); @@ -75,14 +75,14 @@ public void testRecursiveEquality() { } @Test - public void testRecursionFailure() { + void testRecursionFailure() { assertThatThrownBy(() -> Utils.nonRecursive("test", this, null, () -> { throw new RuntimeException("Oops..."); })).isInstanceOf(RuntimeException.class).hasMessage("Oops..."); } @Test - public void testRequirementsCheckers() { + void testRequirementsCheckers() { Utils.require(true, Objects::nonNull, "Good"); assertThatThrownBy(() -> Utils.require(null, Objects::nonNull, "foo")).isInstanceOf(IllegalArgumentException.class); diff --git a/src/test/java/opwvhk/avro/xml/BasicXmlParsingTest.java b/src/test/java/opwvhk/avro/xml/BasicXmlParsingTest.java index 5b1da87..5126ce0 100644 --- a/src/test/java/opwvhk/avro/xml/BasicXmlParsingTest.java +++ b/src/test/java/opwvhk/avro/xml/BasicXmlParsingTest.java @@ -7,8 +7,8 @@ import opwvhk.avro.io.ValueResolver; import org.apache.avro.generic.GenericData; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class BasicXmlParsingTest { +class BasicXmlParsingTest { /** * Logger for this class. */ @@ -25,21 +25,21 @@ public class BasicXmlParsingTest { private XmlAsAvroParser parser; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { URL payloadXsd = requireNonNull(getClass().getResource("payload.xsd")); parser = new XmlAsAvroParser(GenericData.get(), payloadXsd, null, null, new PayloadDebugHandler()); } @Test - public void testValidXsdIsRequired() { + void testValidXsdIsRequired() { URL notAnXsd = requireNonNull(getClass().getResource("textPayload.xml")); assertThatThrownBy(() -> new XmlAsAvroParser(GenericData.get(), notAnXsd, null, null, new PayloadDebugHandler())).isInstanceOf( IllegalStateException.class); } @Test - public void testTextPayload() throws IOException, SAXException { + void testTextPayload() throws IOException, SAXException { URL payloadLocation = requireNonNull(getClass().getResource("textPayload.xml")); assertThat(parser.>parse(payloadLocation)).isEqualTo(Map.of( "source", "Bronsysteem", @@ -52,7 +52,7 @@ public void testTextPayload() throws IOException, SAXException { } @Test - public void testTextPayloadWithoutNamespace() throws IOException, SAXException { + void testTextPayloadWithoutNamespace() throws IOException, SAXException { URL payloadLocation = requireNonNull(getClass().getResource("textPayloadWithoutNamespace.xml")); assertThat(parser.>parse(payloadLocation)).isEqualTo(Map.of( "source", "Bronsysteem", @@ -65,7 +65,7 @@ public void testTextPayloadWithoutNamespace() throws IOException, SAXException { } @Test - public void testRawBinaryPayload() throws IOException, SAXException { + void testRawBinaryPayload() throws IOException, SAXException { URL payloadLocation = requireNonNull(getClass().getResource("binaryPayload.xml")); assertThat(parser.>parse(payloadLocation)).isEqualTo(Map.of( "source", "Bronsysteem", @@ -78,7 +78,7 @@ public void testRawBinaryPayload() throws IOException, SAXException { } @Test - public void testXmlPayload() throws IOException, SAXException { + void testXmlPayload() throws IOException, SAXException { URL payloadLocation = requireNonNull(getClass().getResource("xmlPayload.xml")); assertThat(parser.>parse(payloadLocation)).isEqualTo(Map.of( "source", "Bronsysteem", @@ -109,7 +109,7 @@ public void testXmlPayload() throws IOException, SAXException { } @Test - public void testDefaultPayload() throws IOException, SAXException { + void testDefaultPayload() throws IOException, SAXException { URL payloadLocation = requireNonNull(getClass().getResource("defaultAndCompactXmlPayload.xml")); assertThat(parser.>parse(payloadLocation)).isEqualTo(Map.of( "source", "Bronsysteem", diff --git a/src/test/java/opwvhk/avro/xml/DataRecordsTest.java b/src/test/java/opwvhk/avro/xml/DataRecordsTest.java index 1a29f24..61f51fd 100644 --- a/src/test/java/opwvhk/avro/xml/DataRecordsTest.java +++ b/src/test/java/opwvhk/avro/xml/DataRecordsTest.java @@ -1,6 +1,6 @@ package opwvhk.avro.xml; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static opwvhk.avro.xml.datamodel.Cardinality.MULTIPLE; import static opwvhk.avro.xml.datamodel.Cardinality.OPTIONAL; @@ -8,9 +8,9 @@ import static opwvhk.avro.xml.datamodel.FixedType.STRING; import static org.assertj.core.api.Assertions.assertThat; -public class DataRecordsTest { +class DataRecordsTest { @Test - public void validateFieldDataAsText() { + void validateFieldDataAsText() { assertThat(new FieldData("field", null, REQUIRED, null, "abc").toString()) .isEqualTo("field"); assertThat(new FieldData("field", "documented", OPTIONAL, STRING, "abc").toString()) @@ -20,7 +20,7 @@ public void validateFieldDataAsText() { } @Test - public void validateTypeDataAsText() { + void validateTypeDataAsText() { assertThat(new TypeData(null, null, false).toString()).isEqualTo("anonymous"); assertThat(new TypeData("type", null, true).toString()).isEqualTo("type (mixed)"); assertThat(new TypeData("type", "something", true).toString()).isEqualTo("type (mixed; something)"); diff --git a/src/test/java/opwvhk/avro/xml/XmlResolvingTest.java b/src/test/java/opwvhk/avro/xml/XmlResolvingTest.java index 383359e..f87ac18 100644 --- a/src/test/java/opwvhk/avro/xml/XmlResolvingTest.java +++ b/src/test/java/opwvhk/avro/xml/XmlResolvingTest.java @@ -20,8 +20,8 @@ import org.apache.avro.io.EncoderFactory; import org.apache.avro.io.JsonEncoder; import org.assertj.core.api.Assertions; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -34,12 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class XmlResolvingTest { +class XmlResolvingTest { private static final GenericData MODEL = GenericData.get(); - @BeforeClass - public static void beforeClass() { + @BeforeAll + static void beforeClass() { Assertions.setMaxStackTraceElementsDisplayed(10); MODEL.addLogicalTypeConversion(new TimeConversions.DateConversion()); @@ -52,7 +52,7 @@ public static void beforeClass() { } @Test - public void testHappyFlowSchema() throws IOException { + void testHappyFlowSchema() throws IOException { URL xsdLocation = requireNonNull(getClass().getResource("resolvingTest.xsd")); XsdAnalyzer xsdAnalyzer = new XsdAnalyzer(xsdLocation); Schema actualSchema = xsdAnalyzer.schemaOf("outer"); @@ -62,7 +62,7 @@ public void testHappyFlowSchema() throws IOException { } @Test - public void testHappyFlowWithoutXsd() throws IOException, SAXException { + void testHappyFlowWithoutXsd() throws IOException, SAXException { Schema readSchema = new Schema.Parser().parse(getClass().getResourceAsStream("resolvingTestNoBinary.avsc")); XmlAsAvroParser parser = new XmlAsAvroParser(readSchema, MODEL); @@ -88,7 +88,7 @@ public void testHappyFlowWithoutXsd() throws IOException, SAXException { @SuppressWarnings("UnnecessaryUnicodeEscape") @Test - public void testSuccessfulResolvingAndParsing() throws IOException, SAXException { + void testSuccessfulResolvingAndParsing() throws IOException, SAXException { URL xsdLocation = requireNonNull(getClass().getResource("resolvingTest.xsd")); Schema readSchema = new Schema.Parser().parse(getClass().getResourceAsStream("resolvingTest.avsc")); XmlAsAvroParser parser = new XmlAsAvroParser(xsdLocation, "outer", readSchema, MODEL); @@ -158,7 +158,7 @@ public void testSuccessfulResolvingAndParsing() throws IOException, SAXException } @Test - public void testResolvingAndParsingWithoutNamespace() throws IOException, SAXException { + void testResolvingAndParsingWithoutNamespace() throws IOException, SAXException { URL xsdLocation = requireNonNull(getClass().getResource("resolvingTest.xsd")); Schema readSchema = new Schema.Parser().parse(getClass().getResourceAsStream("resolvingTest.avsc")); XmlAsAvroParser parser = new XmlAsAvroParser(xsdLocation, "outer", readSchema, MODEL); @@ -195,7 +195,7 @@ public void testResolvingAndParsingWithoutNamespace() throws IOException, SAXExc } @Test - public void testFailuresForNamespaceRelatedErrors() throws IOException { + void testFailuresForNamespaceRelatedErrors() throws IOException { URL xsdLocation = requireNonNull(getClass().getResource("resolvingTest.xsd")); Schema readSchema = new Schema.Parser().parse(getClass().getResourceAsStream("resolvingTest.avsc")); XmlAsAvroParser parser = new XmlAsAvroParser(xsdLocation, "outer", readSchema, MODEL); @@ -210,7 +210,7 @@ public void testFailuresForNamespaceRelatedErrors() throws IOException { } @Test - public void testContentOfMixedElements() throws IOException, SAXException { + void testContentOfMixedElements() throws IOException, SAXException { URL xsdLocation = requireNonNull(getClass().getResource("payload.xsd")); Schema readSchema = new Schema.Parser().parse(getClass().getResourceAsStream("envelope.avsc")); XmlAsAvroParser parser = new XmlAsAvroParser(xsdLocation, "envelope", readSchema, MODEL); @@ -290,7 +290,7 @@ public void testContentOfMixedElements() throws IOException, SAXException { } @Test - public void testResolvingFailuresForScalars() { + void testResolvingFailuresForScalars() { // Short though this list is, it covers all failure paths for scalar types. @@ -321,7 +321,7 @@ public void testResolvingFailuresForScalars() { } @Test - public void testAllRequiredFieldsMustBeResolved() { + void testAllRequiredFieldsMustBeResolved() { assertThatSchemasFailToResolve( struct("read").withFields( required("name", FixedType.STRING), @@ -339,7 +339,7 @@ public void testAllRequiredFieldsMustBeResolved() { } @Test - public void testFieldsMustMatchCardinalityAndType() { + void testFieldsMustMatchCardinalityAndType() { // 2nd type is not a struct: there are no fields to match... assertThatSchemasFailToResolve(struct("tooComplex").withFields(required("field", FixedType.STRING)), FixedType.STRING); @@ -394,7 +394,7 @@ public void testFieldsMustMatchCardinalityAndType() { } @Test - public void testWrappedArrayFailures() { + void testWrappedArrayFailures() { // Arrays can be "wrapped", but then: // * the wrapping struct (write type) cannot have multiple fields // * the read type should not be a wrapping type diff --git a/src/test/java/opwvhk/avro/xml/XsdAnalyzerTest.java b/src/test/java/opwvhk/avro/xml/XsdAnalyzerTest.java index 404dab2..1be01b0 100644 --- a/src/test/java/opwvhk/avro/xml/XsdAnalyzerTest.java +++ b/src/test/java/opwvhk/avro/xml/XsdAnalyzerTest.java @@ -9,7 +9,6 @@ import java.util.Objects; import opwvhk.avro.xml.datamodel.DecimalType; -import opwvhk.avro.xml.datamodel.FixedType; import opwvhk.avro.xml.datamodel.StructType; import opwvhk.avro.xml.datamodel.Type; import org.apache.avro.Schema; @@ -24,8 +23,8 @@ import org.apache.ws.commons.schema.walker.XmlSchemaTypeInfo; import org.apache.ws.commons.schema.walker.XmlSchemaVisitor; import org.assertj.core.api.Condition; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static opwvhk.avro.xml.datamodel.FixedType.BINARY_BASE64; import static opwvhk.avro.xml.datamodel.FixedType.BINARY_HEX; @@ -45,11 +44,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class XsdAnalyzerTest { +class XsdAnalyzerTest { private static XsdAnalyzer analyzer; - @Before - public void setUp() + @BeforeEach + void setUp() throws Exception { URL StructTypeUrl = getClass().getResource("testCases.xsd"); analyzer = new XsdAnalyzer(Objects.requireNonNull(StructTypeUrl)); @@ -57,12 +56,12 @@ public void setUp() } @Test - public void checkTestNamespaces() { + void checkTestNamespaces() { assertThat(analyzer.availableNamespaces()).containsExactly("https://www.schiphol.nl/avro-tools/tests"); } @Test - public void checkXmlNamespaceIsCorrectlySpecified() + void checkXmlNamespaceIsCorrectlySpecified() throws IOException { assertThatThrownBy(() -> analyzer.typeOf(new QName("unknown", "unknown"))).isInstanceOf(IllegalArgumentException.class); @@ -78,7 +77,7 @@ public void checkXmlNamespaceIsCorrectlySpecified() */ @Test - public void groupedStructuresAreHandledAndDocumentedCorrectly() { + void groupedStructuresAreHandledAndDocumentedCorrectly() { Type type = analyzer.typeOf(new QName("https://www.schiphol.nl/avro-tools/tests", "GroupStructures")); StructType keep = struct("namespace.Keep").withFields( required("value", STRING) @@ -96,7 +95,7 @@ public void groupedStructuresAreHandledAndDocumentedCorrectly() { } @Test - public void attributesAreSupported() { + void attributesAreSupported() { // Test twice: once to ensure we can convert to schemas correctly. // Other tests use the structural model because that is easier. @@ -115,7 +114,7 @@ public void attributesAreSupported() { } @Test - public void attributesWithSimpleContentAreSupported() { + void attributesWithSimpleContentAreSupported() { Type type = analyzer.typeOf("ExtensionInSimpleContent"); assertThat(type).isEqualTo(struct("namespace.ExtensionInSimpleContent").withFields( @@ -125,7 +124,7 @@ public void attributesWithSimpleContentAreSupported() { } @Test - public void attributesWithComplexContentAreSupported() { + void attributesWithComplexContentAreSupported() { Type type = analyzer.typeOf("ExtensionInMixedComplexContent"); assertThat(type).isEqualTo(struct("namespace.ExtensionInMixedComplexContent").withFields( required("value", STRING), @@ -134,7 +133,7 @@ public void attributesWithComplexContentAreSupported() { } @Test - public void repeatedNestedValuesBecomeArrays() { + void repeatedNestedValuesBecomeArrays() { Type type = analyzer.typeOf("RepeatedNestedRecordWithOptionalField"); StructType array = struct("namespace.array").withFields( @@ -148,7 +147,7 @@ public void repeatedNestedValuesBecomeArrays() { } @Test - public void repeatedSequencedElementsBecomeArrays() { + void repeatedSequencedElementsBecomeArrays() { Type type = analyzer.typeOf("RepeatedSequence"); StructType namedStructType = struct("namespace.named").withFields( @@ -162,7 +161,7 @@ public void repeatedSequencedElementsBecomeArrays() { } @Test - public void repeatedChoiceElementsBecomeArrays() { + void repeatedChoiceElementsBecomeArrays() { Type type = analyzer.typeOf("RepeatedChoice"); assertThat(type).isEqualTo(struct("namespace.RepeatedChoice").withFields( @@ -171,7 +170,7 @@ public void repeatedChoiceElementsBecomeArrays() { } @Test - public void optionalAllMakesElementsNullable() { + void optionalAllMakesElementsNullable() { Type type = analyzer.typeOf("OptionalAll"); assertThat(type).isEqualTo(struct("namespace.OptionalAll").withFields( @@ -181,20 +180,20 @@ public void optionalAllMakesElementsNullable() { } @Test - public void allowsRestrictionInSimpleContent() { + void allowsRestrictionInSimpleContent() { Type type = analyzer.typeOf("RestrictionInSimpleContent"); assertThat(type).isEqualTo(STRING); } @Test - public void allowsRestrictionInComplexContent() { + void allowsRestrictionInComplexContent() { Type type = analyzer.typeOf("RestrictionInComplexContent"); assertThat(type).isEqualTo(struct("namespace.RestrictionInComplexContent").withFields( required("name", STRING))); } @Test - public void allowsExtensionWithElements() { + void allowsExtensionWithElements() { Type type = analyzer.typeOf("ExtensionWithElements"); assertThat(type).isEqualTo(struct("namespace.ExtensionWithElements").withFields( required("description", STRING), @@ -204,7 +203,7 @@ public void allowsExtensionWithElements() { } @Test - public void allowsExtensionOfComplexType() { + void allowsExtensionOfComplexType() { Type type = analyzer.typeOf("ExtensionOfComplexType"); assertThat(type).isEqualTo(struct("namespace.ExtensionOfComplexType").withFields( required("value", STRING), @@ -213,7 +212,7 @@ public void allowsExtensionOfComplexType() { } @Test - public void arbitraryXmlDataIsReadAsString() { + void arbitraryXmlDataIsReadAsString() { Type expected = unparsed(struct("namespace.ArbitraryContent").withFields( required("source", STRING), optional("value", "The entire element content, unparsed.", STRING, null) @@ -222,7 +221,7 @@ public void arbitraryXmlDataIsReadAsString() { } @Test - public void mixedComplexTypesAreCoercedToString() { + void mixedComplexTypesAreCoercedToString() { StructType expected = struct("namespace.MixedComplexType").withFields( required("source", STRING), required("Payload", STRING) @@ -232,7 +231,7 @@ public void mixedComplexTypesAreCoercedToString() { } @Test - public void mixedComplexContentTreatedAsNormal() { + void mixedComplexContentTreatedAsNormal() { Type type = analyzer.typeOf("MixedExtensionWithElements"); assertThat(type).isEqualTo( struct("namespace.MixedExtensionWithElements", "Note that the complexContent being mixed does not affect the outcome!").withFields( @@ -243,7 +242,7 @@ public void mixedComplexContentTreatedAsNormal() { } @Test - public void defaultValuesAreAddedIfPossible() { + void defaultValuesAreAddedIfPossible() { // Note: because we have a default value, the field becomes required (as there's always a value). // Reason: nil and absent values are treated equally, and mean "there's no value in the XML, so use the default" StructType optional = struct("namespace.optional").withFields( @@ -263,7 +262,7 @@ public void defaultValuesAreAddedIfPossible() { } @Test - public void recursionIsAllowed() { + void recursionIsAllowed() { StringWriter buffer = new StringWriter(); analyzer.walkSchemaInTargetNamespace("Recursive", new XmlSchemaVisitor() { private final PrintWriter output = new PrintWriter(buffer); @@ -398,7 +397,7 @@ public void onVisitAnyAttribute(XmlSchemaElement xmlSchemaElement, XmlSchemaAnyA } @Test - public void recursionYieldsStructTypesAsWell() { + void recursionYieldsStructTypesAsWell() { StructType recursiveComplexType = struct("namespace.RecursiveComplexType"); recursiveComplexType.setFields(List.of( required("level", DecimalType.INTEGER_TYPE), @@ -434,7 +433,7 @@ public void recursionYieldsStructTypesAsWell() { */ @Test - public void validateClassNameUniqueness() { + void validateClassNameUniqueness() { StructType normal = struct("namespace.Normal").withFields( required("field", STRING) ); @@ -465,7 +464,7 @@ public void validateClassNameUniqueness() { } @Test - public void checkMaximumNumberOfDuplicateNames() { + void checkMaximumNumberOfDuplicateNames() { TypeBuildingVisitor visitor = new TypeBuildingVisitor(new TypeStructureBuilder(), s -> s, 2); assertThatThrownBy(() -> analyzer.walkSchemaInTargetNamespace("Duplicates", visitor)).isInstanceOf(IllegalStateException.class); } @@ -476,32 +475,32 @@ public void checkMaximumNumberOfDuplicateNames() { */ @Test - public void failsIfElementNotFound() { + void failsIfElementNotFound() { assertFailureCreatingStructTypeFor("DoesNotExist"); } @Test - public void failsOnProhibitedAttribute() { + void failsOnProhibitedAttribute() { assertFailureCreatingStructTypeFor("ProhibitedAttribute"); } @Test - public void abstractElementsYieldNoStructType() { + void abstractElementsYieldNoStructType() { assertFailureCreatingStructTypeFor("AbstractElement"); } @Test - public void failsOnElementsThatCanBeSubstituted() { + void failsOnElementsThatCanBeSubstituted() { assertFailureCreatingStructTypeFor("NameWithAlias"); } @Test - public void butAcceptsElementsThatCanSubstituteAnother() { + void butAcceptsElementsThatCanSubstituteAnother() { assertThat(analyzer.typeOf("Alias")).isEqualTo(STRING); } @Test - public void failsOnAnyAttribute() { + void failsOnAnyAttribute() { assertFailureCreatingStructTypeFor("WithAnyAttribute"); } @@ -510,78 +509,78 @@ public void failsOnAnyAttribute() { */ @Test - public void simpleTypesMayNotBeAList() { + void simpleTypesMayNotBeAList() { assertFailureCreatingStructTypeFor("list"); } @Test - public void simpleTypesMayNotBeAUnion() { + void simpleTypesMayNotBeAUnion() { assertFailureCreatingStructTypeFor("union"); } @Test - public void simpleTypeRestrictionsMayContainASimpleType() { + void simpleTypeRestrictionsMayContainASimpleType() { assertThat(analyzer.typeOf("nestedSimpleType")).isEqualTo(DecimalType.INTEGER_TYPE); } @Test - public void uriValuesAreAllowed() { + void uriValuesAreAllowed() { assertThat(analyzer.typeOf("uri")).isEqualTo(STRING); } @Test - public void booleanValuesAreAllowed() { + void booleanValuesAreAllowed() { assertThat(analyzer.typeOf("boolean")).isEqualTo(BOOLEAN); } @Test - public void intValuesAreAllowed() { + void intValuesAreAllowed() { assertThat(analyzer.typeOf("int")).isEqualTo(DecimalType.INTEGER_TYPE); } @Test - public void longValuesAreAllowed() { + void longValuesAreAllowed() { assertThat(analyzer.typeOf("long")).isEqualTo(DecimalType.LONG_TYPE); } @Test - public void floatValuesAreAllowed() { + void floatValuesAreAllowed() { assertThat(analyzer.typeOf("float")).isEqualTo(FLOAT); } @Test - public void doubleValuesAreAllowed() { + void doubleValuesAreAllowed() { assertThat(analyzer.typeOf("double")).isEqualTo(DOUBLE); } @Test - public void stringValuesAreAllowed() { + void stringValuesAreAllowed() { assertThat(analyzer.typeOf("string")).isEqualTo(STRING); } @Test - public void timestampValuesAreAllowed() { + void timestampValuesAreAllowed() { assertThat(analyzer.typeOf("timestamp")).isEqualTo(DATETIME); } @Test - public void dateValuesAreAllowed() { + void dateValuesAreAllowed() { assertThat(analyzer.typeOf("date")).isEqualTo(DATE); } @Test - public void timeValuesAreAllowed() { + void timeValuesAreAllowed() { assertThat(analyzer.typeOf("time")).isEqualTo(TIME); } @Test - public void unknownTypesAreNotAllowed() { + void unknownTypesAreNotAllowed() { // Note: the element exists, but it uses an unsupported type assertFailureCreatingStructTypeFor("unsupportedSimpleType"); } @Test - public void unconstrainedDecimalAttributesAreNotAllowed() { + void unconstrainedDecimalAttributesAreNotAllowed() { Type type = analyzer.typeOf("unconstrainedDecimalAttribute"); assertThat(type).isEqualTo(struct("namespace.unconstrainedDecimalAttribute").withFields( optional("value", DOUBLE) @@ -589,7 +588,7 @@ public void unconstrainedDecimalAttributesAreNotAllowed() { } @Test - public void unconstrainedIntegerAttributesAreCoercedToLong() { + void unconstrainedIntegerAttributesAreCoercedToLong() { Type type = analyzer.typeOf("unconstrainedIntegerAttribute"); assertThat(type).isEqualTo(struct("namespace.unconstrainedIntegerAttribute").withFields( optional("value", DecimalType.LONG_TYPE) @@ -597,91 +596,91 @@ public void unconstrainedIntegerAttributesAreCoercedToLong() { } @Test - public void unconstrainedDecimalsBecomeDouble() { + void unconstrainedDecimalsBecomeDouble() { Type type = analyzer.typeOf("unconstrainedDecimal"); assertThat(type).isEqualTo(DOUBLE); } @Test - public void infiniteDecimalsBecomeDouble() { + void infiniteDecimalsBecomeDouble() { Type type = analyzer.typeOf("unboundedDecimal"); assertThat(type).isEqualTo(DOUBLE); } @Test - public void decimalsCanHavePrecisionAndScale() { + void decimalsCanHavePrecisionAndScale() { Type type = analyzer.typeOf("decimalBoundedByPrecision"); assertThat(type).is(decimalWithPrecisionAndScale(4, 2)); } @Test - public void decimalsCanHaveBoundsAndScale() { + void decimalsCanHaveBoundsAndScale() { Type type = analyzer.typeOf("decimalBoundedByLimits"); assertThat(type).is(decimalWithPrecisionAndScale(9, 2)); } @Test - public void integersHaveNoFraction() { + void integersHaveNoFraction() { assertFailureCreatingStructTypeFor("integerWithFractionMakesNoSense"); } @Test - public void unconstrainedIntegersAreCoercedToLong() { + void unconstrainedIntegersAreCoercedToLong() { Type type = analyzer.typeOf("coercedToLong"); assertThat(type).isEqualTo(DecimalType.LONG_TYPE); } @Test - public void integersWithFewDigitsAreCoercedToInteger() { + void integersWithFewDigitsAreCoercedToInteger() { Type type = analyzer.typeOf("integerWithFewDigits"); assertThat(type).isEqualTo(DecimalType.INTEGER_TYPE); } @Test - public void integersWithSmallExclusiveBoundsAreCoercedToInteger() { + void integersWithSmallExclusiveBoundsAreCoercedToInteger() { Type type = analyzer.typeOf("integerWithSmallExclusiveBounds"); assertThat(type).isEqualTo(DecimalType.INTEGER_TYPE); } @Test - public void integersWithSmallInclusiveBoundsAreCoercedToInteger() { + void integersWithSmallInclusiveBoundsAreCoercedToInteger() { Type type = analyzer.typeOf("integerWithSmallInclusiveBounds"); assertThat(type).isEqualTo(DecimalType.INTEGER_TYPE); } @Test - public void integersWithMediumDigitsAreCoercedToLong() { + void integersWithMediumDigitsAreCoercedToLong() { Type type = analyzer.typeOf("integerWithMediumDigits"); assertThat(type).isEqualTo(DecimalType.LONG_TYPE); } @Test - public void integersWithMediumBoundsAreCoercedToLong() { + void integersWithMediumBoundsAreCoercedToLong() { Type type = analyzer.typeOf("integerWithMediumBounds"); assertThat(type).isEqualTo(DecimalType.LONG_TYPE); } @Test - public void integersWithManyDigitsAreSupported() { + void integersWithManyDigitsAreSupported() { Type type = analyzer.typeOf("integerWithManyDigits"); assertThat(type).is(decimalWithPrecisionAndScale(20, 0)); } @Test - public void integersWithLargeBoundsAreSupported() { + void integersWithLargeBoundsAreSupported() { Type type = analyzer.typeOf("integerWithLargeBounds"); assertThat(type).is(decimalWithPrecisionAndScale(19, 0)); } @Test - public void enumerationsAreSupported() { + void enumerationsAreSupported() { analyzer.mapTargetNamespace(""); Type type = analyzer.typeOf("enumeration"); assertThat(type).isEqualTo(enumType("enumeration", null, List.of("NONE", "BICYCLE", "BUS", "TRAIN", "CAR"))); } @Test - public void binaryDataIsSupported() { + void binaryDataIsSupported() { assertThat(analyzer.typeOf("hexEncodedBinary")).isEqualTo(BINARY_HEX); assertThat(analyzer.typeOf("base64EncodedBinary")).isEqualTo(BINARY_BASE64); } @@ -691,7 +690,7 @@ public void binaryDataIsSupported() { */ @Test - public void coverMethodThatCannotBeCalled() { + void coverMethodThatCannotBeCalled() { // As substitution groups are not supported, onEnterSubstitutionGroup(...) always throws and onExitSubstitutionGroup(...) is never called. // We call it here to ensure that the statement "< 100% coverage means the code may fail unpredictably" is still true. new TypeBuildingVisitor(null, null, Integer.MAX_VALUE).onExitSubstitutionGroup(null); diff --git a/src/test/java/opwvhk/avro/xml/datamodel/TypeStructureTest.java b/src/test/java/opwvhk/avro/xml/datamodel/TypeStructureTest.java index b799bb1..6201464 100644 --- a/src/test/java/opwvhk/avro/xml/datamodel/TypeStructureTest.java +++ b/src/test/java/opwvhk/avro/xml/datamodel/TypeStructureTest.java @@ -6,7 +6,7 @@ import org.apache.avro.JsonProperties; import org.apache.avro.Schema; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.nio.charset.StandardCharsets.UTF_8; import static opwvhk.avro.xml.datamodel.TestStructures.optional; @@ -16,9 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class TypeStructureTest { +class TypeStructureTest { @Test - public void testAvroDefaultValues() { + void testAvroDefaultValues() { StructType struct = struct("defaults", "Testing default values").withFields( optional("optional1", null, FixedType.STRING, StructType.Field.NULL_VALUE), optional("optional2", null, FixedType.STRING, JsonProperties.NULL_VALUE), @@ -57,7 +57,7 @@ public void testAvroDefaultValues() { } @Test - public void testSimpleScalarParsing() { + void testSimpleScalarParsing() { // Nulls always succeed assertThat(FixedType.BOOLEAN.parse(null)).isNull(); assertThat(FixedType.FLOAT.parse(null)).isNull(); @@ -84,7 +84,7 @@ public void testSimpleScalarParsing() { } @Test - public void testDecimals() { + void testDecimals() { DecimalType smallInteger = DecimalType.integer(20, 7); assertThat(smallInteger.debugString("")).isEqualTo("decimal(7; 20 bits)"); DecimalType largeInteger = DecimalType.integer(40, 13); @@ -116,7 +116,7 @@ public void testDecimals() { } @Test - public void testEnums() { + void testEnums() { assertThatThrownBy(() -> new EnumType("name", null, List.of("the", "default", "symbol", "must"), "exist")).isInstanceOf( IllegalArgumentException.class); @@ -142,14 +142,14 @@ public void testEnums() { } @Test - public void testUnparsedContent() { + void testUnparsedContent() { Type type = unparsed(FixedType.STRING); assertThat(type.toString()).isEqualTo("(unparsed) string"); assertThat(type.debugString("> ")).isEqualTo("> (unparsed) string"); } @Test - public void testStructuralEdgeCases() { + void testStructuralEdgeCases() { StructType type = struct("name", "Testing"); assertThat(type.toString()).isEqualTo(""" StructType(name) {