diff --git a/mr/build.gradle b/mr/build.gradle index 848f6dee3c43..37e665d6d2e6 100644 --- a/mr/build.gradle +++ b/mr/build.gradle @@ -23,6 +23,9 @@ project(':iceberg-mr') { exclude group: 'org.apache.parquet', module: 'parquet-hadoop-bundle' } } + test { + useJUnitPlatform() + } dependencies { implementation project(path: ':iceberg-bundled-guava', configuration: 'shadow') diff --git a/mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java b/mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java index f849163acc6a..012ad2350224 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java +++ b/mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java @@ -20,8 +20,10 @@ import static org.apache.iceberg.types.Types.NestedField.required; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; +import java.nio.file.Path; import java.util.Optional; import java.util.Properties; import org.apache.hadoop.conf.Configuration; @@ -39,12 +41,9 @@ import org.apache.iceberg.hadoop.HadoopTables; import org.apache.iceberg.hive.HiveCatalog; import org.apache.iceberg.types.Types; -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class TestCatalogs { @@ -54,9 +53,9 @@ public class TestCatalogs { private Configuration conf; - @Rule public TemporaryFolder temp = new TemporaryFolder(); + @TempDir private Path temp; - @Before + @BeforeEach public void before() { conf = new Configuration(); } @@ -65,25 +64,25 @@ public void before() { public void testLoadTableFromLocation() throws IOException { conf.set(CatalogUtil.ICEBERG_CATALOG_TYPE, Catalogs.LOCATION); - Assertions.assertThatThrownBy(() -> Catalogs.loadTable(conf)) + assertThatThrownBy(() -> Catalogs.loadTable(conf)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Table location not set"); HadoopTables tables = new HadoopTables(); - Table hadoopTable = tables.create(SCHEMA, temp.newFolder("hadoop_tables").toString()); + Table hadoopTable = tables.create(SCHEMA, temp.resolve("hadoop_tables").toString()); conf.set(InputFormatConfig.TABLE_LOCATION, hadoopTable.location()); - Assert.assertEquals(hadoopTable.location(), Catalogs.loadTable(conf).location()); + assertThat(Catalogs.loadTable(conf).location()).isEqualTo(hadoopTable.location()); } @Test public void testLoadTableFromCatalog() throws IOException { String defaultCatalogName = "default"; - String warehouseLocation = temp.newFolder("hadoop", "warehouse").toString(); + String warehouseLocation = temp.resolve("hadoop").resolve("warehouse").toString(); setCustomCatalogProperties(defaultCatalogName, warehouseLocation); - Assertions.assertThatThrownBy(() -> Catalogs.loadTable(conf)) + assertThatThrownBy(() -> Catalogs.loadTable(conf)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Table identifier not set"); @@ -92,15 +91,15 @@ public void testLoadTableFromCatalog() throws IOException { conf.set(InputFormatConfig.TABLE_IDENTIFIER, "table"); - Assert.assertEquals(hadoopCatalogTable.location(), Catalogs.loadTable(conf).location()); + assertThat(Catalogs.loadTable(conf).location()).isEqualTo(hadoopCatalogTable.location()); } @Test public void testCreateDropTableToLocation() throws IOException { Properties missingSchema = new Properties(); - missingSchema.put("location", temp.newFolder("hadoop_tables").toString()); + missingSchema.put("location", temp.resolve("hadoop_tables").toString()); - Assertions.assertThatThrownBy(() -> Catalogs.createTable(conf, missingSchema)) + assertThatThrownBy(() -> Catalogs.createTable(conf, missingSchema)) .isInstanceOf(NullPointerException.class) .hasMessage("Table schema not set"); @@ -108,12 +107,12 @@ public void testCreateDropTableToLocation() throws IOException { Properties missingLocation = new Properties(); missingLocation.put(InputFormatConfig.TABLE_SCHEMA, SchemaParser.toJson(SCHEMA)); - Assertions.assertThatThrownBy(() -> Catalogs.createTable(conf, missingLocation)) + assertThatThrownBy(() -> Catalogs.createTable(conf, missingLocation)) .isInstanceOf(NullPointerException.class) .hasMessage("Table location not set"); Properties properties = new Properties(); - properties.put("location", temp.getRoot() + "/hadoop_tables"); + properties.put("location", temp.toFile() + "/hadoop_tables"); properties.put(InputFormatConfig.TABLE_SCHEMA, SchemaParser.toJson(SCHEMA)); properties.put(InputFormatConfig.PARTITION_SPEC, PartitionSpecParser.toJson(SPEC)); properties.put("dummy", "test"); @@ -123,20 +122,21 @@ public void testCreateDropTableToLocation() throws IOException { HadoopTables tables = new HadoopTables(); Table table = tables.load(properties.getProperty("location")); - Assert.assertEquals(properties.getProperty("location"), table.location()); - Assert.assertEquals(SchemaParser.toJson(SCHEMA), SchemaParser.toJson(table.schema())); - Assert.assertEquals(PartitionSpecParser.toJson(SPEC), PartitionSpecParser.toJson(table.spec())); + assertThat(table.location()).isEqualTo(properties.getProperty("location")); + assertThat(SchemaParser.toJson(table.schema())).isEqualTo(SchemaParser.toJson(SCHEMA)); + assertThat(PartitionSpecParser.toJson(table.spec())) + .isEqualTo(PartitionSpecParser.toJson(SPEC)); assertThat(table.properties()).containsEntry("dummy", "test"); - Assertions.assertThatThrownBy(() -> Catalogs.dropTable(conf, new Properties())) + assertThatThrownBy(() -> Catalogs.dropTable(conf, new Properties())) .isInstanceOf(NullPointerException.class) .hasMessage("Table location not set"); Properties dropProperties = new Properties(); - dropProperties.put("location", temp.getRoot() + "/hadoop_tables"); + dropProperties.put("location", temp.toFile() + "/hadoop_tables"); Catalogs.dropTable(conf, dropProperties); - Assertions.assertThatThrownBy(() -> Catalogs.loadTable(conf, dropProperties)) + assertThatThrownBy(() -> Catalogs.loadTable(conf, dropProperties)) .isInstanceOf(NoSuchTableException.class) .hasMessage("Table does not exist at location: " + properties.getProperty("location")); } @@ -145,7 +145,7 @@ public void testCreateDropTableToLocation() throws IOException { public void testCreateDropTableToCatalog() throws IOException { TableIdentifier identifier = TableIdentifier.of("test", "table"); String defaultCatalogName = "default"; - String warehouseLocation = temp.newFolder("hadoop", "warehouse").toString(); + String warehouseLocation = temp.resolve("hadoop").resolve("warehouse").toString(); setCustomCatalogProperties(defaultCatalogName, warehouseLocation); @@ -153,14 +153,14 @@ public void testCreateDropTableToCatalog() throws IOException { missingSchema.put("name", identifier.toString()); missingSchema.put(InputFormatConfig.CATALOG_NAME, defaultCatalogName); - Assertions.assertThatThrownBy(() -> Catalogs.createTable(conf, missingSchema)) + assertThatThrownBy(() -> Catalogs.createTable(conf, missingSchema)) .isInstanceOf(NullPointerException.class) .hasMessage("Table schema not set"); Properties missingIdentifier = new Properties(); missingIdentifier.put(InputFormatConfig.TABLE_SCHEMA, SchemaParser.toJson(SCHEMA)); missingIdentifier.put(InputFormatConfig.CATALOG_NAME, defaultCatalogName); - Assertions.assertThatThrownBy(() -> Catalogs.createTable(conf, missingIdentifier)) + assertThatThrownBy(() -> Catalogs.createTable(conf, missingIdentifier)) .isInstanceOf(NullPointerException.class) .hasMessage("Table identifier not set"); @@ -176,11 +176,12 @@ public void testCreateDropTableToCatalog() throws IOException { HadoopCatalog catalog = new CustomHadoopCatalog(conf, warehouseLocation); Table table = catalog.loadTable(identifier); - Assert.assertEquals(SchemaParser.toJson(SCHEMA), SchemaParser.toJson(table.schema())); - Assert.assertEquals(PartitionSpecParser.toJson(SPEC), PartitionSpecParser.toJson(table.spec())); + assertThat(SchemaParser.toJson(table.schema())).isEqualTo(SchemaParser.toJson(SCHEMA)); + assertThat(PartitionSpecParser.toJson(table.spec())) + .isEqualTo(PartitionSpecParser.toJson(SPEC)); assertThat(table.properties()).containsEntry("dummy", "test"); - Assertions.assertThatThrownBy(() -> Catalogs.dropTable(conf, new Properties())) + assertThatThrownBy(() -> Catalogs.dropTable(conf, new Properties())) .isInstanceOf(NullPointerException.class) .hasMessage("Table identifier not set"); @@ -189,7 +190,7 @@ public void testCreateDropTableToCatalog() throws IOException { dropProperties.put(InputFormatConfig.CATALOG_NAME, defaultCatalogName); Catalogs.dropTable(conf, dropProperties); - Assertions.assertThatThrownBy(() -> Catalogs.loadTable(conf, dropProperties)) + assertThatThrownBy(() -> Catalogs.loadTable(conf, dropProperties)) .isInstanceOf(NoSuchTableException.class) .hasMessage("Table does not exist: test.table"); } @@ -198,11 +199,11 @@ public void testCreateDropTableToCatalog() throws IOException { public void testLoadCatalogDefault() { String catalogName = "barCatalog"; Optional defaultCatalog = Catalogs.loadCatalog(conf, catalogName); - Assert.assertTrue(defaultCatalog.isPresent()); - Assertions.assertThat(defaultCatalog.get()).isInstanceOf(HiveCatalog.class); + assertThat(defaultCatalog).isPresent(); + assertThat(defaultCatalog.get()).isInstanceOf(HiveCatalog.class); Properties properties = new Properties(); properties.put(InputFormatConfig.CATALOG_NAME, catalogName); - Assert.assertTrue(Catalogs.hiveCatalog(conf, properties)); + assertThat(Catalogs.hiveCatalog(conf, properties)).isTrue(); } @Test @@ -212,11 +213,11 @@ public void testLoadCatalogHive() { InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogUtil.ICEBERG_CATALOG_TYPE), CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE); Optional hiveCatalog = Catalogs.loadCatalog(conf, catalogName); - Assert.assertTrue(hiveCatalog.isPresent()); - Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class); + assertThat(hiveCatalog).isPresent(); + assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class); Properties properties = new Properties(); properties.put(InputFormatConfig.CATALOG_NAME, catalogName); - Assert.assertTrue(Catalogs.hiveCatalog(conf, properties)); + assertThat(Catalogs.hiveCatalog(conf, properties)).isTrue(); } @Test @@ -230,13 +231,13 @@ public void testLoadCatalogHadoop() { catalogName, CatalogProperties.WAREHOUSE_LOCATION), "/tmp/mylocation"); Optional hadoopCatalog = Catalogs.loadCatalog(conf, catalogName); - Assert.assertTrue(hadoopCatalog.isPresent()); - Assertions.assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class); - Assert.assertEquals( - "HadoopCatalog{name=barCatalog, location=/tmp/mylocation}", hadoopCatalog.get().toString()); + assertThat(hadoopCatalog).isPresent(); + assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class); + assertThat(hadoopCatalog.get().toString()) + .isEqualTo("HadoopCatalog{name=barCatalog, location=/tmp/mylocation}"); Properties properties = new Properties(); properties.put(InputFormatConfig.CATALOG_NAME, catalogName); - Assert.assertFalse(Catalogs.hiveCatalog(conf, properties)); + assertThat(Catalogs.hiveCatalog(conf, properties)).isFalse(); } @Test @@ -250,16 +251,16 @@ public void testLoadCatalogCustom() { catalogName, CatalogProperties.WAREHOUSE_LOCATION), "/tmp/mylocation"); Optional customHadoopCatalog = Catalogs.loadCatalog(conf, catalogName); - Assert.assertTrue(customHadoopCatalog.isPresent()); - Assertions.assertThat(customHadoopCatalog.get()).isInstanceOf(CustomHadoopCatalog.class); + assertThat(customHadoopCatalog).isPresent(); + assertThat(customHadoopCatalog.get()).isInstanceOf(CustomHadoopCatalog.class); Properties properties = new Properties(); properties.put(InputFormatConfig.CATALOG_NAME, catalogName); - Assert.assertFalse(Catalogs.hiveCatalog(conf, properties)); + assertThat(Catalogs.hiveCatalog(conf, properties)).isFalse(); } @Test public void testLoadCatalogLocation() { - Assert.assertFalse(Catalogs.loadCatalog(conf, Catalogs.ICEBERG_HADOOP_TABLE_NAME).isPresent()); + assertThat(Catalogs.loadCatalog(conf, Catalogs.ICEBERG_HADOOP_TABLE_NAME)).isNotPresent(); } @Test @@ -269,7 +270,7 @@ public void testLoadCatalogUnknown() { InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogUtil.ICEBERG_CATALOG_TYPE), "fooType"); - Assertions.assertThatThrownBy(() -> Catalogs.loadCatalog(conf, catalogName)) + assertThatThrownBy(() -> Catalogs.loadCatalog(conf, catalogName)) .isInstanceOf(UnsupportedOperationException.class) .hasMessage("Unknown catalog type: fooType"); } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergTestUtils.java b/mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergTestUtils.java index de5189f7c3ad..43a61d83e434 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergTestUtils.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/HiveIcebergTestUtils.java @@ -19,6 +19,7 @@ package org.apache.iceberg.mr.hive; import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -63,7 +64,6 @@ import org.apache.iceberg.relocated.com.google.common.collect.Lists; import org.apache.iceberg.types.Types; import org.apache.iceberg.util.ByteBuffers; -import org.junit.Assert; public class HiveIcebergTestUtils { // TODO: Can this be a constant all around the Iceberg tests? @@ -218,13 +218,10 @@ public static void assertEquals(Record expected, Record actual) { for (int i = 0; i < expected.size(); ++i) { if (expected.get(i) instanceof OffsetDateTime) { // For OffsetDateTime we just compare the actual instant - Assert.assertEquals( - ((OffsetDateTime) expected.get(i)).toInstant(), - ((OffsetDateTime) actual.get(i)).toInstant()); - } else if (expected.get(i) instanceof byte[]) { - Assert.assertArrayEquals((byte[]) expected.get(i), (byte[]) actual.get(i)); + assertThat(((OffsetDateTime) actual.get(i)).toInstant()) + .isEqualTo(((OffsetDateTime) expected.get(i)).toInstant()); } else { - Assert.assertEquals(expected.get(i), actual.get(i)); + assertThat(actual.get(i)).isEqualTo(expected.get(i)); } } } @@ -265,7 +262,7 @@ public static void validateData(List expected, List actual, int sortedExpected.sort(Comparator.comparingLong(record -> (Long) record.get(sortBy))); sortedActual.sort(Comparator.comparingLong(record -> (Long) record.get(sortBy))); - Assert.assertEquals(sortedExpected.size(), sortedActual.size()); + assertThat(sortedActual).hasSameSizeAs(sortedExpected); for (int i = 0; i < sortedExpected.size(); ++i) { assertEquals(sortedExpected.get(i), sortedActual.get(i)); } @@ -288,9 +285,9 @@ public static void validateFiles(Table table, Configuration conf, JobID jobId, i .filter(path -> !path.getFileName().toString().startsWith(".")) .collect(Collectors.toList()); - Assert.assertEquals(dataFileNum, dataFiles.size()); - Assert.assertFalse( - new File(HiveIcebergOutputCommitter.generateJobLocation(table.location(), conf, jobId)) - .exists()); + assertThat(dataFiles).hasSize(dataFileNum); + assertThat( + new File(HiveIcebergOutputCommitter.generateJobLocation(table.location(), conf, jobId))) + .doesNotExist(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/TestDeserializer.java b/mr/src/test/java/org/apache/iceberg/mr/hive/TestDeserializer.java index 4a5d819279f2..8f58a36d6265 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/TestDeserializer.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/TestDeserializer.java @@ -19,6 +19,8 @@ package org.apache.iceberg.mr.hive; import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; import java.util.Arrays; import java.util.Collections; @@ -35,9 +37,7 @@ import org.apache.iceberg.hive.HiveVersion; import org.apache.iceberg.mr.hive.serde.objectinspector.IcebergObjectInspector; import org.apache.iceberg.types.Types; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestDeserializer { private static final Schema CUSTOMER_SCHEMA = @@ -74,7 +74,7 @@ public void testSchemaDeserialize() { Record actual = deserializer.deserialize(new Object[] {new LongWritable(1L), new Text("Bob")}); - Assert.assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test @@ -92,7 +92,7 @@ public void testStructDeserialize() { Record actual = deserializer.deserialize(new Object[] {new LongWritable(1L), new Text("Bob")}); - Assert.assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test @@ -127,7 +127,7 @@ public void testMapDeserialize() { Object[] data = new Object[] {map}; Record actual = deserializer.deserialize(data); - Assert.assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test @@ -155,13 +155,14 @@ public void testListDeserialize() { Object[] data = new Object[] {new Object[] {new LongWritable(1L)}}; Record actual = deserializer.deserialize(data); - Assert.assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test public void testDeserializeEverySupportedType() { - Assume.assumeFalse( - "No test yet for Hive3 (Date/Timestamp creation)", HiveVersion.min(HiveVersion.HIVE_3)); + assumeThat(HiveVersion.min(HiveVersion.HIVE_3)) + .as("No test yet for Hive3 (Date/Timestamp creation)") + .isFalse(); Deserializer deserializer = new Deserializer.Builder() @@ -196,9 +197,9 @@ public void testNullDeserialize() { Record actual = deserializer.deserialize(nulls); - Assert.assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); // Check null record as well - Assert.assertNull(deserializer.deserialize(null)); + assertThat(deserializer.deserialize(null)).isNull(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergFilterFactory.java b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergFilterFactory.java index 05fe0fdea5ae..121e2c8b6d8a 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergFilterFactory.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergFilterFactory.java @@ -18,7 +18,7 @@ */ package org.apache.iceberg.mr.hive; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; import java.sql.Date; @@ -40,7 +40,7 @@ import org.apache.iceberg.types.Types; import org.apache.iceberg.util.DateTimeUtil; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestHiveIcebergFilterFactory { @@ -82,10 +82,10 @@ public void testNotEqualsOperand() { UnboundPredicate childExpressionActual = (UnboundPredicate) actual.child(); UnboundPredicate childExpressionExpected = Expressions.equal("salary", 3000L); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.child().op(), expected.child().op()); - assertEquals(childExpressionActual.ref().name(), childExpressionExpected.ref().name()); - assertEquals(childExpressionActual.literal(), childExpressionExpected.literal()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.child().op()).isEqualTo(actual.child().op()); + assertThat(childExpressionExpected.ref().name()).isEqualTo(childExpressionActual.ref().name()); + assertThat(childExpressionExpected.literal()).isEqualTo(childExpressionActual.literal()); } @Test @@ -98,9 +98,9 @@ public void testLessThanOperand() { UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.literal(), expected.literal()); - assertEquals(actual.ref().name(), expected.ref().name()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.literal()).isEqualTo(actual.literal()); + assertThat(expected.ref().name()).isEqualTo(actual.ref().name()); } @Test @@ -126,9 +126,9 @@ public void testInOperand() { UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.literals(), expected.literals()); - assertEquals(actual.ref().name(), expected.ref().name()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.literals()).isEqualTo(actual.literals()); + assertThat(expected.ref().name()).isEqualTo(actual.ref().name()); } @Test @@ -144,9 +144,9 @@ public void testBetweenOperand() { Expressions.lessThanOrEqual("salary", 3000L)); And actual = (And) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.left().op(), expected.left().op()); - assertEquals(actual.right().op(), expected.right().op()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.left().op()).isEqualTo(actual.left().op()); + assertThat(expected.right().op()).isEqualTo(actual.right().op()); } @Test @@ -173,8 +173,8 @@ public void testIsNullOperand() { UnboundPredicate actual = (UnboundPredicate) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.ref().name(), expected.ref().name()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.ref().name()).isEqualTo(actual.ref().name()); } @Test @@ -193,9 +193,9 @@ public void testAndOperand() { Expressions.and(Expressions.equal("salary", 3000L), Expressions.equal("salary", 4000L)); And actual = (And) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.left().op(), expected.left().op()); - assertEquals(actual.right().op(), expected.right().op()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.left().op()).isEqualTo(actual.left().op()); + assertThat(expected.right().op()).isEqualTo(actual.right().op()); } @Test @@ -213,9 +213,9 @@ public void testOrOperand() { (Or) Expressions.or(Expressions.equal("salary", 3000L), Expressions.equal("salary", 4000L)); Or actual = (Or) HiveIcebergFilterFactory.generateFilterExpression(arg); - assertEquals(actual.op(), expected.op()); - assertEquals(actual.left().op(), expected.left().op()); - assertEquals(actual.right().op(), expected.right().op()); + assertThat(expected.op()).isEqualTo(actual.op()); + assertThat(expected.left().op()).isEqualTo(actual.left().op()); + assertThat(expected.right().op()).isEqualTo(actual.right().op()); } @Test @@ -308,9 +308,9 @@ public void testDecimalType() { } private void assertPredicatesMatch(UnboundPredicate expected, UnboundPredicate actual) { - assertEquals(expected.op(), actual.op()); - assertEquals(expected.literal(), actual.literal()); - assertEquals(expected.ref().name(), actual.ref().name()); + assertThat(actual.op()).isEqualTo(expected.op()); + assertThat(actual.literal()).isEqualTo(expected.literal()); + assertThat(actual.ref().name()).isEqualTo(expected.ref().name()); } private static class MockSearchArgument implements SearchArgument { diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java index 0d9b5a0c1d5e..8b8e209144fa 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java @@ -20,8 +20,10 @@ import static org.apache.iceberg.mr.hive.HiveIcebergRecordWriter.getWriters; import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; +import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Map; @@ -55,10 +57,8 @@ import org.apache.iceberg.types.Types; import org.apache.iceberg.util.SerializationUtil; import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -80,7 +80,7 @@ public class TestHiveIcebergOutputCommitter { private static final PartitionSpec PARTITIONED_SPEC = PartitionSpec.builderFor(CUSTOMER_SCHEMA).bucket("customer_id", 3).build(); - @Rule public TemporaryFolder temp = new TemporaryFolder(); + @TempDir private Path temp; @Test public void testNeedsTaskCommit() { @@ -91,24 +91,25 @@ public void testNeedsTaskCommit() { mapOnlyJobConf.setNumReduceTasks(0); // Map only job should commit map tasks - Assert.assertTrue( - committer.needsTaskCommit(new TaskAttemptContextImpl(mapOnlyJobConf, MAP_TASK_ID))); + assertThat(committer.needsTaskCommit(new TaskAttemptContextImpl(mapOnlyJobConf, MAP_TASK_ID))) + .isTrue(); JobConf mapReduceJobConf = new JobConf(); mapReduceJobConf.setNumMapTasks(10); mapReduceJobConf.setNumReduceTasks(10); // MapReduce job should not commit map tasks, but should commit reduce tasks - Assert.assertFalse( - committer.needsTaskCommit(new TaskAttemptContextImpl(mapReduceJobConf, MAP_TASK_ID))); - Assert.assertTrue( - committer.needsTaskCommit(new TaskAttemptContextImpl(mapReduceJobConf, REDUCE_TASK_ID))); + assertThat(committer.needsTaskCommit(new TaskAttemptContextImpl(mapReduceJobConf, MAP_TASK_ID))) + .isFalse(); + assertThat( + committer.needsTaskCommit(new TaskAttemptContextImpl(mapReduceJobConf, REDUCE_TASK_ID))) + .isTrue(); } @Test public void testSuccessfulUnpartitionedWrite() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), false); + Table table = table(temp.toFile().getPath(), false); JobConf conf = jobConf(table, 1); List expected = writeRecords(table.name(), 1, 0, true, false, conf); @@ -121,7 +122,7 @@ public void testSuccessfulUnpartitionedWrite() throws IOException { @Test public void testSuccessfulPartitionedWrite() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), true); + Table table = table(temp.toFile().getPath(), true); JobConf conf = jobConf(table, 1); List expected = writeRecords(table.name(), 1, 0, true, false, conf); committer.commitJob(new JobContextImpl(conf, JOB_ID)); @@ -133,7 +134,7 @@ public void testSuccessfulPartitionedWrite() throws IOException { @Test public void testSuccessfulMultipleTasksUnpartitionedWrite() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), false); + Table table = table(temp.toFile().getPath(), false); JobConf conf = jobConf(table, 2); List expected = writeRecords(table.name(), 2, 0, true, false, conf); committer.commitJob(new JobContextImpl(conf, JOB_ID)); @@ -145,7 +146,7 @@ public void testSuccessfulMultipleTasksUnpartitionedWrite() throws IOException { @Test public void testSuccessfulMultipleTasksPartitionedWrite() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), true); + Table table = table(temp.toFile().getPath(), true); JobConf conf = jobConf(table, 2); List expected = writeRecords(table.name(), 2, 0, true, false, conf); committer.commitJob(new JobContextImpl(conf, JOB_ID)); @@ -157,7 +158,7 @@ public void testSuccessfulMultipleTasksPartitionedWrite() throws IOException { @Test public void testRetryTask() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), false); + Table table = table(temp.toFile().getPath(), false); JobConf conf = jobConf(table, 2); // Write records and abort the tasks @@ -181,7 +182,7 @@ public void testRetryTask() throws IOException { @Test public void testAbortJob() throws IOException { HiveIcebergOutputCommitter committer = new HiveIcebergOutputCommitter(); - Table table = table(temp.getRoot().getPath(), false); + Table table = table(temp.toFile().getPath(), false); JobConf conf = jobConf(table, 1); writeRecords(table.name(), 1, 0, true, false, conf); committer.abortJob(new JobContextImpl(conf, JOB_ID), JobStatus.State.FAILED); @@ -201,7 +202,7 @@ public void writerIsClosedAfterTaskCommitFailure() throws IOException { .when(failingCommitter) .commitTask(argumentCaptor.capture()); - Table table = table(temp.getRoot().getPath(), false); + Table table = table(temp.toFile().getPath(), false); JobConf conf = jobConf(table, 1); Assertions.assertThatThrownBy( @@ -209,14 +210,14 @@ public void writerIsClosedAfterTaskCommitFailure() throws IOException { .isInstanceOf(RuntimeException.class) .hasMessage(exceptionMessage); - Assert.assertEquals(1, argumentCaptor.getAllValues().size()); + assertThat(argumentCaptor.getAllValues()).hasSize(1); TaskAttemptID capturedId = TezUtil.taskAttemptWrapper(argumentCaptor.getValue().getTaskAttemptID()); // writer is still in the map after commitTask failure - Assert.assertNotNull(getWriters(capturedId)); + assertThat(getWriters(capturedId)).isNotNull(); failingCommitter.abortTask(new TaskAttemptContextImpl(conf, capturedId)); // abortTask succeeds and removes writer - Assert.assertNull(getWriters(capturedId)); + assertThat(getWriters(capturedId)).isNull(); } private Table table(String location, boolean partitioned) { diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergSerDe.java b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergSerDe.java index 889c441c28fc..919230a9fbd9 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergSerDe.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergSerDe.java @@ -19,9 +19,11 @@ package org.apache.iceberg.mr.hive; import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Properties; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde2.SerDeException; @@ -34,22 +36,20 @@ import org.apache.iceberg.mr.hive.serde.objectinspector.IcebergObjectInspector; import org.apache.iceberg.mr.mapred.Container; import org.apache.iceberg.types.Types; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class TestHiveIcebergSerDe { private static final Schema schema = new Schema(required(1, "string_field", Types.StringType.get())); - @Rule public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir private Path tmp; @Test public void testInitialize() throws IOException, SerDeException { - File location = tmp.newFolder(); - Assert.assertTrue(location.delete()); + File location = tmp.toFile(); + assertThat(location.delete()).isTrue(); Configuration conf = new Configuration(); @@ -63,7 +63,7 @@ public void testInitialize() throws IOException, SerDeException { HiveIcebergSerDe serDe = new HiveIcebergSerDe(); serDe.initialize(conf, properties); - Assert.assertEquals(IcebergObjectInspector.create(schema), serDe.getObjectInspector()); + assertThat(serDe.getObjectInspector()).isEqualTo(IcebergObjectInspector.create(schema)); } @Test @@ -74,6 +74,6 @@ public void testDeserialize() { Container container = new Container<>(); container.set(record); - Assert.assertEquals(record, serDe.deserialize(container)); + assertThat(serDe.deserialize(container)).isEqualTo(record); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergBinaryObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergBinaryObjectInspector.java index 5db84e5aa4b9..87fe4208c964 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergBinaryObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergBinaryObjectInspector.java @@ -18,14 +18,15 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.nio.ByteBuffer; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; import org.apache.hadoop.io.BytesWritable; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergBinaryObjectInspector { @@ -33,39 +34,40 @@ public class TestIcebergBinaryObjectInspector { public void testIcebergByteBufferObjectInspector() { BinaryObjectInspector oi = IcebergBinaryObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.BINARY, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.BINARY); - Assert.assertEquals(TypeInfoFactory.binaryTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.binaryTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.binaryTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.binaryTypeInfo.getTypeName()); - Assert.assertEquals(byte[].class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(BytesWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(byte[].class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(BytesWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); byte[] bytes = new byte[] {0, 1, 2, 3}; ByteBuffer buffer = ByteBuffer.wrap(bytes); - Assert.assertArrayEquals(bytes, oi.getPrimitiveJavaObject(buffer)); - Assert.assertEquals(new BytesWritable(bytes), oi.getPrimitiveWritableObject(buffer)); + assertThat(oi.getPrimitiveJavaObject(buffer)).isEqualTo(bytes); + assertThat(oi.getPrimitiveWritableObject(buffer)).isEqualTo(new BytesWritable(bytes)); ByteBuffer slice = ByteBuffer.wrap(bytes, 1, 2).slice(); - Assert.assertArrayEquals(new byte[] {1, 2}, oi.getPrimitiveJavaObject(slice)); - Assert.assertEquals(new BytesWritable(new byte[] {1, 2}), oi.getPrimitiveWritableObject(slice)); + assertThat(oi.getPrimitiveJavaObject(slice)).isEqualTo(new byte[] {1, 2}); + assertThat(oi.getPrimitiveWritableObject(slice)) + .isEqualTo(new BytesWritable(new byte[] {1, 2})); slice.position(1); - Assert.assertArrayEquals(new byte[] {2}, oi.getPrimitiveJavaObject(slice)); - Assert.assertEquals(new BytesWritable(new byte[] {2}), oi.getPrimitiveWritableObject(slice)); + assertThat(oi.getPrimitiveJavaObject(slice)).isEqualTo(new byte[] {2}); + assertThat(oi.getPrimitiveWritableObject(slice)).isEqualTo(new BytesWritable(new byte[] {2})); byte[] copy = (byte[]) oi.copyObject(bytes); - Assert.assertArrayEquals(bytes, copy); - Assert.assertNotSame(bytes, copy); + assertThat(copy).isEqualTo(bytes); + assertThat(copy).isNotSameAs(bytes); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDateObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDateObjectInspector.java index 73681fec5799..6e03fae861f9 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDateObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDateObjectInspector.java @@ -18,6 +18,8 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Date; import java.time.LocalDate; import org.apache.hadoop.hive.serde2.io.DateWritable; @@ -25,8 +27,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergDateObjectInspector { @@ -34,30 +35,31 @@ public class TestIcebergDateObjectInspector { public void testIcebergDateObjectInspector() { DateObjectInspector oi = IcebergDateObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals(PrimitiveObjectInspector.PrimitiveCategory.DATE, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.DATE); - Assert.assertEquals(TypeInfoFactory.dateTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.dateTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.dateTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.dateTypeInfo.getTypeName()); - Assert.assertEquals(Date.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(DateWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(Date.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(DateWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); LocalDate local = LocalDate.of(2020, 1, 1); Date date = Date.valueOf("2020-01-01"); - Assert.assertEquals(date, oi.getPrimitiveJavaObject(local)); - Assert.assertEquals(new DateWritable(date), oi.getPrimitiveWritableObject(local)); + assertThat(oi.getPrimitiveJavaObject(local)).isEqualTo(date); + assertThat(oi.getPrimitiveWritableObject(local)).isEqualTo(new DateWritable(date)); Date copy = (Date) oi.copyObject(date); - Assert.assertEquals(date, copy); - Assert.assertNotSame(date, copy); + assertThat(copy).isEqualTo(date); + assertThat(copy).isNotSameAs(date); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDecimalObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDecimalObjectInspector.java index 1c4734c77f4c..58d43e3d7047 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDecimalObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergDecimalObjectInspector.java @@ -18,6 +18,8 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.math.BigDecimal; import org.apache.hadoop.hive.common.type.HiveDecimal; import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; @@ -26,8 +28,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergDecimalObjectInspector { @@ -35,43 +36,44 @@ public class TestIcebergDecimalObjectInspector { public void testCache() { HiveDecimalObjectInspector oi = IcebergDecimalObjectInspector.get(38, 18); - Assert.assertSame(oi, IcebergDecimalObjectInspector.get(38, 18)); - Assert.assertNotSame(oi, IcebergDecimalObjectInspector.get(28, 18)); - Assert.assertNotSame(oi, IcebergDecimalObjectInspector.get(38, 28)); + assertThat(IcebergDecimalObjectInspector.get(38, 18)).isSameAs(oi); + assertThat(IcebergDecimalObjectInspector.get(28, 18)).isNotSameAs(oi); + assertThat(IcebergDecimalObjectInspector.get(38, 28)).isNotSameAs(oi); } @Test public void testIcebergDecimalObjectInspector() { HiveDecimalObjectInspector oi = IcebergDecimalObjectInspector.get(38, 18); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.DECIMAL, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.DECIMAL); - Assert.assertEquals(new DecimalTypeInfo(38, 18), oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.decimalTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(new DecimalTypeInfo(38, 18)); + assertThat(oi.getTypeName()) + .isEqualTo(TypeInfoFactory.decimalTypeInfo.getTypeName(), oi.getTypeName()); - Assert.assertEquals(38, oi.precision()); - Assert.assertEquals(18, oi.scale()); + assertThat(oi.precision()).isEqualTo(38); + assertThat(oi.scale()).isEqualTo(18); - Assert.assertEquals(HiveDecimal.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(HiveDecimalWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(HiveDecimal.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(HiveDecimalWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); HiveDecimal one = HiveDecimal.create(BigDecimal.ONE); - Assert.assertEquals(one, oi.getPrimitiveJavaObject(BigDecimal.ONE)); - Assert.assertEquals( - new HiveDecimalWritable(one), oi.getPrimitiveWritableObject(BigDecimal.ONE)); + assertThat(oi.getPrimitiveJavaObject(BigDecimal.ONE)).isEqualTo(one); + assertThat(oi.getPrimitiveWritableObject(BigDecimal.ONE)) + .isEqualTo(new HiveDecimalWritable(one)); HiveDecimal copy = (HiveDecimal) oi.copyObject(one); - Assert.assertEquals(one, copy); - Assert.assertNotSame(one, copy); + assertThat(copy).isEqualTo(one); + assertThat(copy).isNotSameAs(one); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergFixedObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergFixedObjectInspector.java index a902d027269d..7a8450f6852f 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergFixedObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergFixedObjectInspector.java @@ -18,12 +18,13 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; import org.apache.hadoop.io.BytesWritable; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergFixedObjectInspector { @@ -31,33 +32,33 @@ public class TestIcebergFixedObjectInspector { public void testIcebergFixedObjectInspector() { IcebergFixedObjectInspector oi = IcebergFixedObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.BINARY, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.BINARY); - Assert.assertEquals(TypeInfoFactory.binaryTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.binaryTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.binaryTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.binaryTypeInfo.getTypeName()); - Assert.assertEquals(byte[].class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(BytesWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(byte[].class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(BytesWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); - Assert.assertNull(oi.convert(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); + assertThat(oi.convert(null)).isNull(); byte[] bytes = new byte[] {0, 1}; BytesWritable bytesWritable = new BytesWritable(bytes); - Assert.assertArrayEquals(bytes, oi.getPrimitiveJavaObject(bytes)); - Assert.assertEquals(bytesWritable, oi.getPrimitiveWritableObject(bytes)); - Assert.assertEquals(bytes, oi.convert(bytes)); + assertThat(oi.getPrimitiveJavaObject(bytes)).isEqualTo(bytes); + assertThat(oi.getPrimitiveWritableObject(bytes)).isEqualTo(bytesWritable); + assertThat(oi.convert(bytes)).isEqualTo(bytes); byte[] copy = (byte[]) oi.copyObject(bytes); - Assert.assertArrayEquals(bytes, copy); - Assert.assertNotSame(bytes, copy); + assertThat(copy).isEqualTo(bytes); + assertThat(copy).isNotSameAs(bytes); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergObjectInspector.java index c4d3cea4b002..c2646376890c 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergObjectInspector.java @@ -19,6 +19,7 @@ package org.apache.iceberg.mr.hive.serde.objectinspector; import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; @@ -31,8 +32,7 @@ import org.apache.iceberg.hive.HiveVersion; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; import org.apache.iceberg.types.Types; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergObjectInspector { @@ -74,165 +74,161 @@ public class TestIcebergObjectInspector { @Test public void testIcebergObjectInspector() { ObjectInspector oi = IcebergObjectInspector.create(schema); - Assert.assertNotNull(oi); - Assert.assertEquals(ObjectInspector.Category.STRUCT, oi.getCategory()); + assertThat(oi).isNotNull(); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.STRUCT); StructObjectInspector soi = (StructObjectInspector) oi; // binary StructField binaryField = soi.getStructFieldRef("binary_field"); - Assert.assertEquals(1, binaryField.getFieldID()); - Assert.assertEquals("binary_field", binaryField.getFieldName()); - Assert.assertEquals("binary comment", binaryField.getFieldComment()); - Assert.assertEquals(IcebergBinaryObjectInspector.get(), binaryField.getFieldObjectInspector()); + assertThat(binaryField.getFieldID()).isEqualTo(1); + assertThat(binaryField.getFieldName()).isEqualTo("binary_field"); + assertThat(binaryField.getFieldComment()).isEqualTo("binary comment"); + assertThat(binaryField.getFieldObjectInspector()).isEqualTo(IcebergBinaryObjectInspector.get()); // boolean StructField booleanField = soi.getStructFieldRef("boolean_field"); - Assert.assertEquals(2, booleanField.getFieldID()); - Assert.assertEquals("boolean_field", booleanField.getFieldName()); - Assert.assertEquals("boolean comment", booleanField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(boolean.class), booleanField.getFieldObjectInspector()); + assertThat(booleanField.getFieldID()).isEqualTo(2); + assertThat(booleanField.getFieldName()).isEqualTo("boolean_field"); + assertThat(booleanField.getFieldComment()).isEqualTo("boolean comment"); + assertThat(booleanField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(boolean.class)); // date StructField dateField = soi.getStructFieldRef("date_field"); - Assert.assertEquals(3, dateField.getFieldID()); - Assert.assertEquals("date_field", dateField.getFieldName()); - Assert.assertEquals("date comment", dateField.getFieldComment()); + assertThat(dateField.getFieldID()).isEqualTo(3); + assertThat(dateField.getFieldName()).isEqualTo("date_field"); + assertThat(dateField.getFieldComment()).isEqualTo("date comment"); if (HiveVersion.min(HiveVersion.HIVE_3)) { - Assert.assertEquals( - "org.apache.iceberg.mr.hive.serde.objectinspector.IcebergDateObjectInspectorHive3", - dateField.getFieldObjectInspector().getClass().getName()); + assertThat(dateField.getFieldObjectInspector().getClass().getName()) + .isEqualTo( + "org.apache.iceberg.mr.hive.serde.objectinspector.IcebergDateObjectInspectorHive3"); } else { - Assert.assertEquals( - "org.apache.iceberg.mr.hive.serde.objectinspector.IcebergDateObjectInspector", - dateField.getFieldObjectInspector().getClass().getName()); + assertThat(dateField.getFieldObjectInspector().getClass().getName()) + .isEqualTo("org.apache.iceberg.mr.hive.serde.objectinspector.IcebergDateObjectInspector"); } // decimal StructField decimalField = soi.getStructFieldRef("decimal_field"); - Assert.assertEquals(4, decimalField.getFieldID()); - Assert.assertEquals("decimal_field", decimalField.getFieldName()); - Assert.assertEquals("decimal comment", decimalField.getFieldComment()); - Assert.assertEquals( - IcebergDecimalObjectInspector.get(38, 18), decimalField.getFieldObjectInspector()); + assertThat(decimalField.getFieldID()).isEqualTo(4); + assertThat(decimalField.getFieldName()).isEqualTo("decimal_field"); + assertThat(decimalField.getFieldComment()).isEqualTo("decimal comment"); + assertThat(decimalField.getFieldObjectInspector()) + .isEqualTo(IcebergDecimalObjectInspector.get(38, 18)); // double StructField doubleField = soi.getStructFieldRef("double_field"); - Assert.assertEquals(5, doubleField.getFieldID()); - Assert.assertEquals("double_field", doubleField.getFieldName()); - Assert.assertEquals("double comment", doubleField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(double.class), doubleField.getFieldObjectInspector()); + assertThat(doubleField.getFieldID()).isEqualTo(5); + assertThat(doubleField.getFieldName()).isEqualTo("double_field"); + assertThat(doubleField.getFieldComment()).isEqualTo("double comment"); + assertThat(doubleField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(double.class)); // fixed StructField fixedField = soi.getStructFieldRef("fixed_field"); - Assert.assertEquals(6, fixedField.getFieldID()); - Assert.assertEquals("fixed_field", fixedField.getFieldName()); - Assert.assertEquals("fixed comment", fixedField.getFieldComment()); - Assert.assertEquals(IcebergFixedObjectInspector.get(), fixedField.getFieldObjectInspector()); + assertThat(fixedField.getFieldID()).isEqualTo(6); + assertThat(fixedField.getFieldName()).isEqualTo("fixed_field"); + assertThat(fixedField.getFieldComment()).isEqualTo("fixed comment"); + assertThat(fixedField.getFieldObjectInspector()).isEqualTo(IcebergFixedObjectInspector.get()); // float StructField floatField = soi.getStructFieldRef("float_field"); - Assert.assertEquals(7, floatField.getFieldID()); - Assert.assertEquals("float_field", floatField.getFieldName()); - Assert.assertEquals("float comment", floatField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(float.class), floatField.getFieldObjectInspector()); + assertThat(floatField.getFieldID()).isEqualTo(7); + assertThat(floatField.getFieldName()).isEqualTo("float_field"); + assertThat(floatField.getFieldComment()).isEqualTo("float comment"); + assertThat(floatField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(float.class)); // integer StructField integerField = soi.getStructFieldRef("integer_field"); - Assert.assertEquals(8, integerField.getFieldID()); - Assert.assertEquals("integer_field", integerField.getFieldName()); - Assert.assertEquals("integer comment", integerField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(int.class), integerField.getFieldObjectInspector()); + assertThat(integerField.getFieldID()).isEqualTo(8); + assertThat(integerField.getFieldName()).isEqualTo("integer_field"); + assertThat(integerField.getFieldComment()).isEqualTo("integer comment"); + assertThat(integerField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(int.class)); // long StructField longField = soi.getStructFieldRef("long_field"); - Assert.assertEquals(9, longField.getFieldID()); - Assert.assertEquals("long_field", longField.getFieldName()); - Assert.assertEquals("long comment", longField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(long.class), longField.getFieldObjectInspector()); + assertThat(longField.getFieldID()).isEqualTo(9); + assertThat(longField.getFieldName()).isEqualTo("long_field"); + assertThat(longField.getFieldComment()).isEqualTo("long comment"); + assertThat(longField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(long.class)); // string StructField stringField = soi.getStructFieldRef("string_field"); - Assert.assertEquals(10, stringField.getFieldID()); - Assert.assertEquals("string_field", stringField.getFieldName()); - Assert.assertEquals("string comment", stringField.getFieldComment()); - Assert.assertEquals( - getPrimitiveObjectInspector(String.class), stringField.getFieldObjectInspector()); + assertThat(stringField.getFieldID()).isEqualTo(10); + assertThat(stringField.getFieldName()).isEqualTo("string_field"); + assertThat(stringField.getFieldComment()).isEqualTo("string comment"); + assertThat(stringField.getFieldObjectInspector()) + .isEqualTo(getPrimitiveObjectInspector(String.class)); // timestamp without tz StructField timestampField = soi.getStructFieldRef("timestamp_field"); - Assert.assertEquals(11, timestampField.getFieldID()); - Assert.assertEquals("timestamp_field", timestampField.getFieldName()); - Assert.assertEquals("timestamp comment", timestampField.getFieldComment()); + assertThat(timestampField.getFieldID()).isEqualTo(11); + assertThat(timestampField.getFieldName()).isEqualTo("timestamp_field"); + assertThat(timestampField.getFieldComment()).isEqualTo("timestamp comment"); if (HiveVersion.min(HiveVersion.HIVE_3)) { - Assert.assertEquals( - "IcebergTimestampObjectInspectorHive3", - timestampField.getFieldObjectInspector().getClass().getSimpleName()); + assertThat(timestampField.getFieldObjectInspector().getClass().getSimpleName()) + .isEqualTo("IcebergTimestampObjectInspectorHive3"); } else { - Assert.assertEquals( - IcebergTimestampObjectInspector.get(), timestampField.getFieldObjectInspector()); + assertThat(timestampField.getFieldObjectInspector()) + .isEqualTo(IcebergTimestampObjectInspector.get()); } // timestamp with tz StructField timestampTzField = soi.getStructFieldRef("timestamptz_field"); - Assert.assertEquals(12, timestampTzField.getFieldID()); - Assert.assertEquals("timestamptz_field", timestampTzField.getFieldName()); - Assert.assertEquals("timestamptz comment", timestampTzField.getFieldComment()); + assertThat(timestampTzField.getFieldID()).isEqualTo(12); + assertThat(timestampTzField.getFieldName()).isEqualTo("timestamptz_field"); + assertThat(timestampTzField.getFieldComment()).isEqualTo("timestamptz comment"); if (HiveVersion.min(HiveVersion.HIVE_3)) { - Assert.assertEquals( - "IcebergTimestampWithZoneObjectInspectorHive3", - timestampTzField.getFieldObjectInspector().getClass().getSimpleName()); + assertThat(timestampTzField.getFieldObjectInspector().getClass().getSimpleName()) + .isEqualTo("IcebergTimestampWithZoneObjectInspectorHive3"); } else { - Assert.assertEquals( - IcebergTimestampWithZoneObjectInspector.get(), - timestampTzField.getFieldObjectInspector()); + assertThat(timestampTzField.getFieldObjectInspector()) + .isEqualTo(IcebergTimestampWithZoneObjectInspector.get()); } // UUID StructField uuidField = soi.getStructFieldRef("uuid_field"); - Assert.assertEquals(13, uuidField.getFieldID()); - Assert.assertEquals("uuid_field", uuidField.getFieldName()); - Assert.assertEquals("uuid comment", uuidField.getFieldComment()); - Assert.assertEquals(IcebergUUIDObjectInspector.get(), uuidField.getFieldObjectInspector()); + assertThat(uuidField.getFieldID()).isEqualTo(13); + assertThat(uuidField.getFieldName()).isEqualTo("uuid_field"); + assertThat(uuidField.getFieldComment()).isEqualTo("uuid comment"); + assertThat(uuidField.getFieldObjectInspector()).isEqualTo(IcebergUUIDObjectInspector.get()); // list StructField listField = soi.getStructFieldRef("list_field"); - Assert.assertEquals(14, listField.getFieldID()); - Assert.assertEquals("list_field", listField.getFieldName()); - Assert.assertEquals("list comment", listField.getFieldComment()); - Assert.assertEquals(getListObjectInspector(String.class), listField.getFieldObjectInspector()); + assertThat(listField.getFieldID()).isEqualTo(14); + assertThat(listField.getFieldName()).isEqualTo("list_field"); + assertThat(listField.getFieldComment()).isEqualTo("list comment"); + assertThat(listField.getFieldObjectInspector()).isEqualTo(getListObjectInspector(String.class)); // map StructField mapField = soi.getStructFieldRef("map_field"); - Assert.assertEquals(16, mapField.getFieldID()); - Assert.assertEquals("map_field", mapField.getFieldName()); - Assert.assertEquals("map comment", mapField.getFieldComment()); - Assert.assertEquals( - getMapObjectInspector(String.class, int.class), mapField.getFieldObjectInspector()); + assertThat(mapField.getFieldID()).isEqualTo(16); + assertThat(mapField.getFieldName()).isEqualTo("map_field"); + assertThat(mapField.getFieldComment()).isEqualTo("map comment"); + assertThat(mapField.getFieldObjectInspector()) + .isEqualTo(getMapObjectInspector(String.class, int.class)); // struct StructField structField = soi.getStructFieldRef("struct_field"); - Assert.assertEquals(19, structField.getFieldID()); - Assert.assertEquals("struct_field", structField.getFieldName()); - Assert.assertEquals("struct comment", structField.getFieldComment()); + assertThat(structField.getFieldID()).isEqualTo(19); + assertThat(structField.getFieldName()).isEqualTo("struct_field"); + assertThat(structField.getFieldComment()).isEqualTo("struct comment"); ObjectInspector expectedObjectInspector = new IcebergRecordObjectInspector( (Types.StructType) schema.findType(19), ImmutableList.of(getPrimitiveObjectInspector(String.class))); - Assert.assertEquals(expectedObjectInspector, structField.getFieldObjectInspector()); + assertThat(structField.getFieldObjectInspector()).isEqualTo(expectedObjectInspector); // time StructField timeField = soi.getStructFieldRef("time_field"); - Assert.assertEquals(21, timeField.getFieldID()); - Assert.assertEquals("time_field", timeField.getFieldName()); - Assert.assertEquals("time comment", timeField.getFieldComment()); - Assert.assertEquals(IcebergTimeObjectInspector.get(), timeField.getFieldObjectInspector()); + assertThat(timeField.getFieldID()).isEqualTo(21); + assertThat(timeField.getFieldName()).isEqualTo("time_field"); + assertThat(timeField.getFieldComment()).isEqualTo("time comment"); + assertThat(timeField.getFieldObjectInspector()).isEqualTo(IcebergTimeObjectInspector.get()); } private static ObjectInspector getPrimitiveObjectInspector(Class clazz) { diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergRecordObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergRecordObjectInspector.java index 4ed358c116fb..d5824f8bd7d8 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergRecordObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergRecordObjectInspector.java @@ -19,6 +19,7 @@ package org.apache.iceberg.mr.hive.serde.objectinspector; import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThat; import org.apache.hadoop.hive.serde2.objectinspector.StructField; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; @@ -27,8 +28,7 @@ import org.apache.iceberg.data.Record; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; import org.apache.iceberg.types.Types; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergRecordObjectInspector { @@ -47,22 +47,22 @@ public void testIcebergRecordObjectInspector() { Record innerRecord = record.get(1, Record.class); StructObjectInspector soi = (StructObjectInspector) IcebergObjectInspector.create(schema); - Assert.assertEquals( - ImmutableList.of(record.get(0), record.get(1)), soi.getStructFieldsDataAsList(record)); + assertThat(soi.getStructFieldsDataAsList(record)) + .isEqualTo(ImmutableList.of(record.get(0), record.get(1))); StructField integerField = soi.getStructFieldRef("integer_field"); - Assert.assertEquals(record.get(0), soi.getStructFieldData(record, integerField)); + assertThat(soi.getStructFieldData(record, integerField)).isEqualTo(record.get(0)); StructField structField = soi.getStructFieldRef("struct_field"); Object innerData = soi.getStructFieldData(record, structField); - Assert.assertEquals(innerRecord, innerData); + assertThat(innerData).isEqualTo(innerRecord); StructObjectInspector innerSoi = (StructObjectInspector) structField.getFieldObjectInspector(); StructField stringField = innerSoi.getStructFieldRef("string_field"); - Assert.assertEquals( - ImmutableList.of(innerRecord.get(0)), innerSoi.getStructFieldsDataAsList(innerRecord)); - Assert.assertEquals(innerRecord.get(0), innerSoi.getStructFieldData(innerData, stringField)); + assertThat(innerSoi.getStructFieldsDataAsList(innerRecord)) + .isEqualTo(ImmutableList.of(innerRecord.get(0))); + assertThat(innerSoi.getStructFieldData(innerData, stringField)).isEqualTo(innerRecord.get(0)); } @Test @@ -76,8 +76,8 @@ public void testIcebergRecordObjectInspectorWithRowNull() { Types.StructType.of( Types.NestedField.required(3, "string_field", Types.StringType.get())))); StructObjectInspector soi = (StructObjectInspector) IcebergObjectInspector.create(schema); - Assert.assertNull(soi.getStructFieldsDataAsList(null)); + assertThat(soi.getStructFieldsDataAsList(null)).isNull(); StructField integerField = soi.getStructFieldRef("integer_field"); - Assert.assertNull(soi.getStructFieldData(null, integerField)); + assertThat(soi.getStructFieldData(null, integerField)).isNull(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimeObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimeObjectInspector.java index 04c3c710f27d..5af9ba341ebd 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimeObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimeObjectInspector.java @@ -18,13 +18,14 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.LocalTime; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; import org.apache.hadoop.io.Text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergTimeObjectInspector { @@ -33,34 +34,34 @@ public void testIcebergTimeObjectInspector() { IcebergTimeObjectInspector oi = IcebergTimeObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.STRING, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.STRING); - Assert.assertEquals(TypeInfoFactory.stringTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.stringTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.stringTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.stringTypeInfo.getTypeName()); - Assert.assertEquals(String.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(Text.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(String.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(Text.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); - Assert.assertNull(oi.convert(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); + assertThat(oi.convert(null)).isNull(); LocalTime localTime = LocalTime.now(); String time = localTime.toString(); Text text = new Text(time); - Assert.assertEquals(time, oi.getPrimitiveJavaObject(text)); - Assert.assertEquals(text, oi.getPrimitiveWritableObject(time)); - Assert.assertEquals(localTime, oi.convert(time)); + assertThat(oi.getPrimitiveJavaObject(text)).isEqualTo(time); + assertThat(oi.getPrimitiveWritableObject(time)).isEqualTo(text); + assertThat(oi.convert(time)).isEqualTo(localTime); Text copy = (Text) oi.copyObject(text); - Assert.assertEquals(text, copy); - Assert.assertNotSame(text, copy); + assertThat(copy).isEqualTo(text); + assertThat(copy).isNotSameAs(text); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampObjectInspector.java index 9205d7c0d7f8..ea40cc20420a 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampObjectInspector.java @@ -18,14 +18,15 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Timestamp; import java.time.LocalDateTime; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergTimestampObjectInspector { @@ -33,34 +34,34 @@ public class TestIcebergTimestampObjectInspector { public void testIcebergTimestampObjectInspector() { IcebergTimestampObjectInspector oi = IcebergTimestampObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.TIMESTAMP, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.TIMESTAMP); - Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.timestampTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.timestampTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.timestampTypeInfo.getTypeName()); - Assert.assertEquals(Timestamp.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(TimestampWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(Timestamp.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(TimestampWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); - Assert.assertNull(oi.convert(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); + assertThat(oi.convert(null)).isNull(); LocalDateTime local = LocalDateTime.of(2020, 1, 1, 12, 55, 30, 5560000); Timestamp ts = Timestamp.valueOf(local); - Assert.assertEquals(ts, oi.getPrimitiveJavaObject(local)); - Assert.assertEquals(new TimestampWritable(ts), oi.getPrimitiveWritableObject(local)); + assertThat(oi.getPrimitiveJavaObject(local)).isEqualTo(ts); + assertThat(oi.getPrimitiveWritableObject(local)).isEqualTo(new TimestampWritable(ts)); Timestamp copy = (Timestamp) oi.copyObject(ts); - Assert.assertEquals(ts, copy); - Assert.assertNotSame(ts, copy); + assertThat(copy).isEqualTo(ts); + assertThat(copy).isNotSameAs(ts); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); - Assert.assertEquals(local, oi.convert(ts)); + assertThat(oi.convert(ts)).isEqualTo(local); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampWithZoneObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampWithZoneObjectInspector.java index 20caec44f7bd..1b16e6e02c0e 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampWithZoneObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergTimestampWithZoneObjectInspector.java @@ -18,6 +18,8 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Timestamp; import java.time.LocalDateTime; import java.time.OffsetDateTime; @@ -26,8 +28,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergTimestampWithZoneObjectInspector { @@ -35,41 +36,40 @@ public class TestIcebergTimestampWithZoneObjectInspector { public void testIcebergTimestampObjectInspectorWithUTCAdjustment() { IcebergTimestampWithZoneObjectInspector oi = IcebergTimestampWithZoneObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.TIMESTAMP, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.TIMESTAMP); - Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.timestampTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.timestampTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.timestampTypeInfo.getTypeName()); - Assert.assertEquals(Timestamp.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(TimestampWritable.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(Timestamp.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(TimestampWritable.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); - Assert.assertNull(oi.convert(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); + assertThat(oi.convert(null)).isNull(); LocalDateTime local = LocalDateTime.of(2020, 1, 1, 16, 45, 33, 456000); OffsetDateTime offsetDateTime = OffsetDateTime.of(local, ZoneOffset.ofHours(-5)); Timestamp ts = Timestamp.from(offsetDateTime.toInstant()); - Assert.assertEquals(ts, oi.getPrimitiveJavaObject(offsetDateTime)); - Assert.assertEquals(new TimestampWritable(ts), oi.getPrimitiveWritableObject(offsetDateTime)); + assertThat(oi.getPrimitiveJavaObject(offsetDateTime)).isEqualTo(ts); + assertThat(oi.getPrimitiveWritableObject(offsetDateTime)).isEqualTo(new TimestampWritable(ts)); Timestamp copy = (Timestamp) oi.copyObject(ts); - Assert.assertEquals(ts, copy); - Assert.assertNotSame(ts, copy); + assertThat(copy).isEqualTo(ts); + assertThat(copy).isNotSameAs(ts); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); - Assert.assertEquals( - OffsetDateTime.ofInstant(local.toInstant(ZoneOffset.ofHours(-5)), ZoneOffset.UTC), - oi.convert(ts)); + assertThat(oi.convert(ts)) + .isEqualTo( + OffsetDateTime.ofInstant(local.toInstant(ZoneOffset.ofHours(-5)), ZoneOffset.UTC)); - Assert.assertEquals( - offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC), - oi.convert(Timestamp.from(offsetDateTime.toInstant()))); + assertThat(offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC)) + .isEqualTo(oi.convert(Timestamp.from(offsetDateTime.toInstant()))); } } diff --git a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergUUIDObjectInspector.java b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergUUIDObjectInspector.java index 303cabc1cc15..abc0c01ed8d1 100644 --- a/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergUUIDObjectInspector.java +++ b/mr/src/test/java/org/apache/iceberg/mr/hive/serde/objectinspector/TestIcebergUUIDObjectInspector.java @@ -18,13 +18,14 @@ */ package org.apache.iceberg.mr.hive.serde.objectinspector; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.UUID; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; import org.apache.hadoop.io.Text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestIcebergUUIDObjectInspector { @@ -32,34 +33,34 @@ public class TestIcebergUUIDObjectInspector { public void testIcebergUUIDObjectInspector() { IcebergUUIDObjectInspector oi = IcebergUUIDObjectInspector.get(); - Assert.assertEquals(ObjectInspector.Category.PRIMITIVE, oi.getCategory()); - Assert.assertEquals( - PrimitiveObjectInspector.PrimitiveCategory.STRING, oi.getPrimitiveCategory()); + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.PRIMITIVE); + assertThat(oi.getPrimitiveCategory()) + .isEqualTo(PrimitiveObjectInspector.PrimitiveCategory.STRING); - Assert.assertEquals(TypeInfoFactory.stringTypeInfo, oi.getTypeInfo()); - Assert.assertEquals(TypeInfoFactory.stringTypeInfo.getTypeName(), oi.getTypeName()); + assertThat(oi.getTypeInfo()).isEqualTo(TypeInfoFactory.stringTypeInfo); + assertThat(oi.getTypeName()).isEqualTo(TypeInfoFactory.stringTypeInfo.getTypeName()); - Assert.assertEquals(String.class, oi.getJavaPrimitiveClass()); - Assert.assertEquals(Text.class, oi.getPrimitiveWritableClass()); + assertThat(oi.getJavaPrimitiveClass()).isEqualTo(String.class); + assertThat(oi.getPrimitiveWritableClass()).isEqualTo(Text.class); - Assert.assertNull(oi.copyObject(null)); - Assert.assertNull(oi.getPrimitiveJavaObject(null)); - Assert.assertNull(oi.getPrimitiveWritableObject(null)); - Assert.assertNull(oi.convert(null)); + assertThat(oi.copyObject(null)).isNull(); + assertThat(oi.getPrimitiveJavaObject(null)).isNull(); + assertThat(oi.getPrimitiveWritableObject(null)).isNull(); + assertThat(oi.convert(null)).isNull(); UUID uuid = UUID.randomUUID(); String uuidStr = uuid.toString(); Text text = new Text(uuidStr); - Assert.assertEquals(uuidStr, oi.getPrimitiveJavaObject(text)); - Assert.assertEquals(text, oi.getPrimitiveWritableObject(uuidStr)); - Assert.assertEquals(uuid, oi.convert(uuidStr)); + assertThat(oi.getPrimitiveJavaObject(text)).isEqualTo(uuidStr); + assertThat(oi.getPrimitiveWritableObject(uuidStr)).isEqualTo(text); + assertThat(oi.convert(uuidStr)).isEqualTo(uuid); Text copy = (Text) oi.copyObject(text); - Assert.assertEquals(text, copy); - Assert.assertNotSame(text, copy); + assertThat(copy).isEqualTo(text); + assertThat(copy).isNotSameAs(text); - Assert.assertFalse(oi.preferWritable()); + assertThat(oi.preferWritable()).isFalse(); } }