diff --git a/kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapTransform.java b/kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapTransform.java index 08a1b4274256..7fd658c60bfb 100644 --- a/kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapTransform.java +++ b/kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapTransform.java @@ -38,7 +38,7 @@ public class JsonToMapTransform> implements Transform public static final String JSON_LEVEL = "json.root"; - private static final ObjectReader mapper = new ObjectMapper().reader(); + private static final ObjectReader MAPPER = new ObjectMapper().reader(); private boolean startAtRoot = false; @@ -77,7 +77,7 @@ private R process(R record) { JsonNode obj; try { - obj = mapper.readTree(json); + obj = MAPPER.readTree(json); } catch (Exception e) { throw new JsonToMapException( String.format( diff --git a/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/ArrayEncoding.java b/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/ArrayEncoding.java index 03321ed98414..637fbc4aa87e 100644 --- a/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/ArrayEncoding.java +++ b/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/ArrayEncoding.java @@ -42,9 +42,8 @@ public static ArrayEncoding parse(String value) { if (value == null) { return null; } - value = value.trim(); for (ArrayEncoding option : ArrayEncoding.values()) { - if (option.getValue().equalsIgnoreCase(value)) { + if (option.getValue().equalsIgnoreCase(value.trim())) { return option; } } diff --git a/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java b/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java index 94be2fa1a0a4..f0038277d6c6 100644 --- a/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java +++ b/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java @@ -18,14 +18,14 @@ */ package org.debezium.connector.mongodb.transforms; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; import org.apache.kafka.connect.data.Field; import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.SchemaBuilder; @@ -156,7 +156,7 @@ public void convertFieldValue( if (keyvalueforStruct.getValue().asArray().isEmpty()) { switch (arrayEncoding) { case ARRAY: - colValue = new ArrayList<>(); + colValue = Lists.newArrayList(); break; case DOCUMENT: final Schema fieldSchema = schema.field(key).schema(); @@ -168,7 +168,7 @@ public void convertFieldValue( case ARRAY: BsonType valueType = keyvalueforStruct.getValue().asArray().get(0).getBsonType(); List arrValues = keyvalueforStruct.getValue().asArray().getValues(); - ArrayList list = new ArrayList<>(); + List list = Lists.newArrayList(); arrValues.forEach( arrValue -> { @@ -184,7 +184,7 @@ public void convertFieldValue( break; case DOCUMENT: final BsonArray array = keyvalueforStruct.getValue().asArray(); - final Map convertedArray = new HashMap<>(); + final Map convertedArray = Maps.newHashMap(); final Schema arraySchema = schema.field(key).schema(); final Struct arrayStruct = new Struct(arraySchema); for (int i = 0; i < array.size(); i++) { @@ -209,8 +209,10 @@ public void convertFieldValue( struct.put(key, keyvalueforStruct.getValue().isNull() ? null : colValue); } + // TODO FIX Cyclomatic Complexity is 30 (max allowed is 12). [CyclomaticComplexity] + @SuppressWarnings("checkstyle:CyclomaticComplexity") private void convertFieldValue( - Schema valueSchema, BsonType valueType, BsonValue arrValue, ArrayList list) { + Schema valueSchema, BsonType valueType, BsonValue arrValue, List list) { if (arrValue.getBsonType() == BsonType.STRING && valueType == BsonType.STRING) { String temp = arrValue.asString().getValue(); list.add(temp); @@ -251,7 +253,7 @@ private void convertFieldValue( } list.add(struct1); } else if (arrValue.getBsonType() == BsonType.ARRAY && valueType == BsonType.ARRAY) { - ArrayList subList = new ArrayList<>(); + List subList = Lists.newArrayList(); final Schema subValueSchema; if (Arrays.asList(BsonType.ARRAY, BsonType.DOCUMENT) .contains(arrValue.asArray().get(0).getBsonType())) { @@ -266,8 +268,8 @@ private void convertFieldValue( } } - protected String arrayElementStructName(int i) { - return "_" + i; + protected String arrayElementStructName(int index) { + return "_" + index; } public void addFieldSchema(Entry keyValuesforSchema, SchemaBuilder builder) { @@ -370,7 +372,7 @@ public void addFieldSchema(Entry keyValuesforSchema, SchemaBu final BsonArray array = keyValuesforSchema.getValue().asArray(); final SchemaBuilder arrayStructBuilder = SchemaBuilder.struct().name(builder.name() + "." + key).optional(); - final Map convertedArray = new HashMap<>(); + final Map convertedArray = Maps.newHashMap(); for (int i = 0; i < array.size(); i++) { convertedArray.put(arrayElementStructName(i), array.get(i)); } @@ -409,12 +411,12 @@ private Schema subSchema(SchemaBuilder builder, String key, BsonType valueType, case DOCUMENT: final SchemaBuilder documentSchemaBuilder = SchemaBuilder.struct().name(builder.name() + "." + key).optional(); - final Map union = new HashMap<>(); + final Map union = Maps.newHashMap(); if (value.isArray()) { value .asArray() .forEach(f -> subSchema(documentSchemaBuilder, union, f.asDocument(), true)); - if (documentSchemaBuilder.fields().size() == 0) { + if (documentSchemaBuilder.fields().isEmpty()) { value .asArray() .forEach(f -> subSchema(documentSchemaBuilder, union, f.asDocument(), false)); @@ -443,9 +445,9 @@ private void subSchema( final String key = arrayDoc.getKey(); if (emptyChecker && ((arrayDoc.getValue() instanceof BsonDocument - && ((BsonDocument) arrayDoc.getValue()).size() == 0) + && ((BsonDocument) arrayDoc.getValue()).isEmpty()) || (arrayDoc.getValue() instanceof BsonArray - && ((BsonArray) arrayDoc.getValue()).size() == 0))) { + && ((BsonArray) arrayDoc.getValue()).isEmpty()))) { continue; } final BsonType prevType = union.putIfAbsent(key, arrayDoc.getValue().getBsonType()); @@ -459,7 +461,7 @@ private void subSchema( private void testType(SchemaBuilder builder, String key, BsonValue value, BsonType valueType) { if (valueType == BsonType.DOCUMENT) { - final Map union = new HashMap<>(); + final Map union = Maps.newHashMap(); for (BsonValue element : value.asArray()) { final BsonDocument arrayDocs = element.asDocument(); for (Entry arrayDoc : arrayDocs.entrySet()) { diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapTransformTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapTransformTest.java index 34d20669006f..87df4b1c904f 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapTransformTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapTransformTest.java @@ -19,8 +19,7 @@ package org.apache.iceberg.connect.transforms; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Map; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; @@ -85,7 +84,7 @@ public void shouldThrowExceptionNonJsonObjects() { offset, timestamp, TimestampType.CREATE_TIME); - assertThrows(JsonToMapException.class, () -> smt.apply(record)); + assertThatThrownBy(() -> smt.apply(record)).isInstanceOf(JsonToMapException.class); } } @@ -104,7 +103,7 @@ public void shouldThrowExceptionInvalidJson() { offset, timestamp, TimestampType.CREATE_TIME); - assertThrows(JsonToMapException.class, () -> smt.apply(record)); + assertThatThrownBy(() -> smt.apply(record)).isInstanceOf(JsonToMapException.class); } } @@ -132,7 +131,7 @@ public void singleValueOnRootNode() { "payload", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).optional().build()) .build(); - assertInstanceOf(Struct.class, result.value()); + assertThat(result.value()).isInstanceOf(Struct.class); Struct resultStruct = (Struct) result.value(); Map expectedValue = Maps.newHashMap(); @@ -159,7 +158,7 @@ public void structOnRootNode() { timestamp, TimestampType.CREATE_TIME); SinkRecord result = smt.apply(record); - assertInstanceOf(Struct.class, result.value()); + assertThat(result.value()).isInstanceOf(Struct.class); Struct resultStruct = (Struct) result.value(); assertThat(resultStruct.schema().fields().size()).isEqualTo(19); assertThat(resultStruct.get("string")).isEqualTo("string"); diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapUtilsTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapUtilsTest.java index 2f5259d1787a..eb34b04962bc 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapUtilsTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/JsonToMapUtilsTest.java @@ -19,9 +19,7 @@ package org.apache.iceberg.connect.transforms; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -95,23 +93,23 @@ public void primitiveBasedOnSchemaHappyPath() { .isEqualTo(3.0); assertThat(JsonToMapUtils.extractValue(doubleNode, Schema.Type.FLOAT64, "")).isEqualTo(0.3); byte[] byteResult = (byte[]) JsonToMapUtils.extractValue(bytesNode, Schema.Type.BYTES, ""); - assertArrayEquals(byteResult, Base64.getDecoder().decode("SGVsbG8=")); + assertThat(byteResult).isEqualTo(Base64.getDecoder().decode("SGVsbG8=")); } @Test @DisplayName("extractValue converts complex nodes to strings if schema is string") public void exactStringsFromComplexNodes() { JsonNode arrayObjects = objNode.get("array_objects"); - assertInstanceOf(ArrayNode.class, arrayObjects); + assertThat(arrayObjects).isInstanceOf(ArrayNode.class); JsonNode nestedObjNode = objNode.get("nested_obj"); - assertInstanceOf(ObjectNode.class, nestedObjNode); + assertThat(nestedObjNode).isInstanceOf(ObjectNode.class); JsonNode arrayDifferentTypes = objNode.get("array_different_types"); - assertInstanceOf(ArrayNode.class, arrayDifferentTypes); + assertThat(arrayDifferentTypes).isInstanceOf(ArrayNode.class); JsonNode bigInt = objNode.get("bigInt"); - assertInstanceOf(BigIntegerNode.class, bigInt); + assertThat(bigInt).isInstanceOf(BigIntegerNode.class); assertThat(JsonToMapUtils.extractValue(arrayObjects, Schema.Type.STRING, "")) .isEqualTo("[{\"key\":1}]"); @@ -124,9 +122,9 @@ public void exactStringsFromComplexNodes() { @Test @DisplayName("extractSimpleValue throws for non-primitive schema types") public void primitiveBasedOnSchemaThrows() { - assertThrows( - RuntimeException.class, - () -> JsonToMapUtils.extractValue(objNode.get("string"), Schema.Type.STRUCT, "")); + assertThatThrownBy( + () -> JsonToMapUtils.extractValue(objNode.get("string"), Schema.Type.STRUCT, "")) + .isInstanceOf(RuntimeException.class); } @Test @@ -158,7 +156,7 @@ public void schemaFromNodeNullOnNullNodes() { @DisplayName("schemaFromNode returns null for empty ObjectNodes") public void schemaFromNodeNullEmptyObjectNodes() { JsonNode node = objNode.get("empty_obj"); - assertInstanceOf(ObjectNode.class, node); + assertThat(node).isInstanceOf(ObjectNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)).isNull(); } @@ -167,7 +165,7 @@ public void schemaFromNodeNullEmptyObjectNodes() { "schemaFromNode returns bytes with logical name decimal with scale 0 for BigInteger nodes") public void schemaFromNodeStringForBigInteger() { JsonNode node = objNode.get("bigInt"); - assertInstanceOf(BigIntegerNode.class, node); + assertThat(node).isInstanceOf(BigIntegerNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)).isEqualTo(JsonToMapUtils.decimalSchema(0)); } @@ -176,8 +174,8 @@ public void schemaFromNodeStringForBigInteger() { public void schemaFromNodePrimitiveSchemasFromPrimitiveNodes() { JsonNode intNode = objNode.get("int"); JsonNode doubleNode = objNode.get("double"); - assertInstanceOf(IntNode.class, intNode); - assertInstanceOf(DoubleNode.class, doubleNode); + assertThat(intNode).isInstanceOf(IntNode.class); + assertThat(doubleNode).isInstanceOf(DoubleNode.class); assertThat(JsonToMapUtils.schemaFromNode(intNode)).isEqualTo(Schema.OPTIONAL_INT32_SCHEMA); assertThat(JsonToMapUtils.schemaFromNode(doubleNode)).isEqualTo(Schema.OPTIONAL_FLOAT64_SCHEMA); } @@ -186,7 +184,7 @@ public void schemaFromNodePrimitiveSchemasFromPrimitiveNodes() { @DisplayName("schemaFromNode returns Map for ObjectNodes") public void schmefromNodeObjectNodesAsMaps() { JsonNode node = objNode.get("nested_obj"); - assertInstanceOf(ObjectNode.class, node); + assertThat(node).isInstanceOf(ObjectNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)) .isEqualTo( SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).optional().build()); @@ -196,7 +194,7 @@ public void schmefromNodeObjectNodesAsMaps() { @DisplayName("schemaFromNode returns Array String schema for ArrayNodes with ObjectNode elements") public void schemaFromNodeArrayStringFromArrayObjects() { JsonNode arrayObjects = objNode.get("array_objects"); - assertInstanceOf(ArrayNode.class, arrayObjects); + assertThat(arrayObjects).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(arrayObjects)) .isEqualTo(JsonToMapUtils.ARRAY_MAP_OPTIONAL_STRING); } @@ -205,7 +203,7 @@ public void schemaFromNodeArrayStringFromArrayObjects() { @DisplayName("schemaFromNode returns Array String schema for ArrayNodes with inconsistent types") public void schemaFromNodeArrayStringFromInconsistentArrayNodes() { JsonNode inconsistent = objNode.get("array_different_types"); - assertInstanceOf(ArrayNode.class, inconsistent); + assertThat(inconsistent).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(inconsistent)) .isEqualTo(SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build()); } @@ -215,7 +213,7 @@ public void schemaFromNodeArrayStringFromInconsistentArrayNodes() { "schemaFromNode returns Array[Array[String]] for ArrayNodes of ArrayNodes with inconsistent types") public void schemaFromNodeArraysArrays() { JsonNode node = objNode.get("array_array_inconsistent"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); Schema expected = SchemaBuilder.array(SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build()) @@ -230,7 +228,7 @@ public void schemaFromNodeArraysArrays() { "schemaFromNode returns Array[Array[Map]] for ArrayNodes of ArrayNodes of objects") public void schemaFromNodeArrayArrayObjects() { JsonNode node = objNode.get("array_array_objects"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); Schema expected = SchemaBuilder.array(JsonToMapUtils.ARRAY_MAP_OPTIONAL_STRING).optional().build(); Schema result = JsonToMapUtils.schemaFromNode(node); @@ -241,7 +239,7 @@ public void schemaFromNodeArrayArrayObjects() { @DisplayName("schemaFromNode returns Array[Array[Int]] for ArrayNodes of ArrayNodes of IntNode") public void schemaFromNodeArrayArrayOfArrayArrayInt() { JsonNode node = objNode.get("array_array_int"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); Schema expected = SchemaBuilder.array(SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build()) .optional() @@ -254,7 +252,7 @@ public void schemaFromNodeArrayArrayOfArrayArrayInt() { @DisplayName("schemaFromNode returns null for empty ArrayNodes") public void schemaFromNodeNullFromEmptyArray() { JsonNode node = objNode.get("empty_arr"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)).isNull(); } @@ -262,7 +260,7 @@ public void schemaFromNodeNullFromEmptyArray() { @DisplayName("schemaFromNode returns null for empty Array of Array nodes") public void schemaFromNodeEmptyArrayOfEmptyArrays() { JsonNode node = objNode.get("empty_arr_arr"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)).isNull(); } @@ -271,7 +269,7 @@ public void schemaFromNodeEmptyArrayOfEmptyArrays() { "schemaFromNode returns optional map of optional for array of empty object") public void schemaFromNodeNullArrayEmptyObject() { JsonNode node = objNode.get("array_empty_object"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)) .isEqualTo(JsonToMapUtils.ARRAY_MAP_OPTIONAL_STRING); } @@ -281,7 +279,7 @@ public void schemaFromNodeNullArrayEmptyObject() { "schemaFromNode returns Array[Map] for array of objects if one object is empty") public void schemaFromNodeMixedObjectsOneEmpty() { JsonNode node = objNode.get("nested_object_contains_empty"); - assertInstanceOf(ArrayNode.class, node); + assertThat(node).isInstanceOf(ArrayNode.class); assertThat(JsonToMapUtils.schemaFromNode(node)) .isEqualTo(JsonToMapUtils.ARRAY_MAP_OPTIONAL_STRING); } @@ -329,9 +327,9 @@ public void addToStruct() { assertThat(result.get("empty_string")).isEqualTo(""); // assert empty fields don't show up on the struct - assertThrows(RuntimeException.class, () -> result.get("null")); - assertThrows(RuntimeException.class, () -> result.get("empty_obj")); - assertThrows(RuntimeException.class, () -> result.get("empty_arr")); - assertThrows(RuntimeException.class, () -> result.get("empty_arr_arr")); + assertThatThrownBy(() -> result.get("null")).isInstanceOf(RuntimeException.class); + assertThatThrownBy(() -> result.get("empty_obj")).isInstanceOf(RuntimeException.class); + assertThatThrownBy(() -> result.get("empty_arr")).isInstanceOf(RuntimeException.class); + assertThatThrownBy(() -> result.get("empty_arr_arr")).isInstanceOf(RuntimeException.class); } } diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/KafkaMetadataTransformTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/KafkaMetadataTransformTest.java index 1c9785f8e2fd..395cfcdf609c 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/KafkaMetadataTransformTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/KafkaMetadataTransformTest.java @@ -19,7 +19,7 @@ package org.apache.iceberg.connect.transforms; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Map; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; @@ -83,8 +83,8 @@ public void testThrowIfNotExpectedValue() { TimestampType.CREATE_TIME); try (KafkaMetadataTransform smt = new KafkaMetadataTransform()) { smt.configure(ImmutableMap.of()); - assertThrows(RuntimeException.class, () -> smt.apply(recordNotMap)); - assertThrows(RuntimeException.class, () -> smt.apply(recordNotStruct)); + assertThatThrownBy(() -> smt.apply(recordNotMap)).isInstanceOf(RuntimeException.class); + assertThatThrownBy(() -> smt.apply(recordNotStruct)).isInstanceOf(RuntimeException.class); } } @@ -181,9 +181,12 @@ public void testAppendsToStuctsExternal() { @DisplayName("throw if external field cannot be parsed") public void testAppendsToStuctsExternalShouldThrowIfInvalid() { try (KafkaMetadataTransform smt = new KafkaMetadataTransform()) { - assertThrows( - RuntimeException.class, - () -> smt.configure(ImmutableMap.of("external_field", "external,*,,,value"))); + + assertThatThrownBy( + () -> { + smt.configure(ImmutableMap.of("external_field", "external,*,,,value")); + }) + .isInstanceOf(RuntimeException.class); } } diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/MongoDebeziumTransformTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/MongoDebeziumTransformTest.java index 39cb2a8f623e..38bfa233d681 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/MongoDebeziumTransformTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/MongoDebeziumTransformTest.java @@ -19,7 +19,7 @@ package org.apache.iceberg.connect.transforms; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.net.URISyntaxException; @@ -563,6 +563,6 @@ public void shouldThrowExceptionWhenMissingAllRequiredFields() { TimestampType.CREATE_TIME); MongoDebeziumTransform smt = getTransformer("array"); - assertThrows(IllegalArgumentException.class, () -> smt.apply(record)); + assertThatThrownBy(() -> smt.apply(record)).isInstanceOf(IllegalArgumentException.class); } } diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoArrayConverterTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoArrayConverterTest.java index 8eee3880717a..65a7857ac2fb 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoArrayConverterTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoArrayConverterTest.java @@ -19,7 +19,7 @@ package org.debezium.connector.mongodb.transforms; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Arrays; import java.util.Map.Entry; @@ -98,7 +98,7 @@ public static String lines(String... lines) { private SchemaBuilder builder; @BeforeEach - public void setup() throws Exception { + public void setUpBeforeEach() throws Exception { builder = SchemaBuilder.struct().name("array"); } @@ -107,13 +107,13 @@ public void shouldDetectHeterogenousArray() { final MongoDataConverter converter = new MongoDataConverter(ArrayEncoding.ARRAY); final BsonDocument val = BsonDocument.parse(HETEROGENOUS_ARRAY); - assertThrows( - RuntimeException.class, - () -> { - for (Entry entry : val.entrySet()) { - converter.addFieldSchema(entry, builder); - } - }); + assertThatThrownBy( + () -> { + for (Entry entry : val.entrySet()) { + converter.addFieldSchema(entry, builder); + } + }) + .isInstanceOf(RuntimeException.class); } @Test @@ -121,13 +121,13 @@ public void shouldDetectHeterogenousDocumentInArray() { final MongoDataConverter converter = new MongoDataConverter(ArrayEncoding.ARRAY); final BsonDocument val = BsonDocument.parse(HETEROGENOUS_DOCUMENT_IN_ARRAY); - assertThrows( - RuntimeException.class, - () -> { - for (Entry entry : val.entrySet()) { - converter.addFieldSchema(entry, builder); - } - }); + assertThatThrownBy( + () -> { + for (Entry entry : val.entrySet()) { + converter.addFieldSchema(entry, builder); + } + }) + .isInstanceOf(RuntimeException.class); } @Test @@ -177,13 +177,13 @@ public void shouldCreateSchemaForHomogenousArray() { public void shouldCreateStructForHomogenousArray() { final MongoDataConverter converter = new MongoDataConverter(ArrayEncoding.ARRAY); final BsonDocument val = BsonDocument.parse(HOMOGENOUS_ARRAYS); - final SchemaBuilder builder = SchemaBuilder.struct().name("array"); + final SchemaBuilder schemaBuilder = SchemaBuilder.struct().name("array"); for (Entry entry : val.entrySet()) { - converter.addFieldSchema(entry, builder); + converter.addFieldSchema(entry, schemaBuilder); } - final Schema finalSchema = builder.build(); + final Schema finalSchema = schemaBuilder.build(); final Struct struct = new Struct(finalSchema); for (Entry entry : val.entrySet()) { diff --git a/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoDataConverterTest.java b/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoDataConverterTest.java index 165296ae9529..19848ce20d8d 100644 --- a/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoDataConverterTest.java +++ b/kafka-connect/kafka-connect-transforms/src/test/java/org/debezium/connector/mongodb/transforms/MongoDataConverterTest.java @@ -50,7 +50,7 @@ public class MongoDataConverterTest { private MongoDataConverter converter; @BeforeEach - public void setup() throws Exception { + public void setUpBeforeEach() throws Exception { record = getFile("restaurants5.json"); val = BsonDocument.parse(record); builder = SchemaBuilder.struct().name("pub");