Skip to content

Commit 0055e85

Browse files
authored
Move Assert.assertTrue(..) instance checks to AssertJ assertions (#2756)
1 parent 762f5bb commit 0055e85

File tree

25 files changed

+201
-193
lines changed

25 files changed

+201
-193
lines changed

api/src/test/java/org/apache/iceberg/expressions/TestExpressionBinding.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.iceberg.exceptions.ValidationException;
2424
import org.apache.iceberg.types.Types;
2525
import org.apache.iceberg.types.Types.StructType;
26+
import org.assertj.core.api.Assertions;
2627
import org.junit.Assert;
2728
import org.junit.Test;
2829

@@ -182,7 +183,7 @@ public void testTransformExpressionBinding() {
182183
Expression bound = Binder.bind(STRUCT, equal(bucket("x", 16), 10));
183184
TestHelpers.assertAllReferencesBound("BoundTransform", bound);
184185
BoundPredicate<?> pred = TestHelpers.assertAndUnwrap(bound);
185-
Assert.assertTrue("Should use a BoundTransform child", pred.term() instanceof BoundTransform);
186+
Assertions.assertThat(pred.term()).as("Should use a BoundTransform child").isInstanceOf(BoundTransform.class);
186187
BoundTransform<?, ?> transformExpr = (BoundTransform<?, ?>) pred.term();
187188
Assert.assertEquals("Should use a bucket[16] transform", "bucket[16]", transformExpr.transform().toString());
188189
}

api/src/test/java/org/apache/iceberg/transforms/TestProjection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.iceberg.expressions.UnboundPredicate;
3232
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
3333
import org.apache.iceberg.types.Types;
34+
import org.assertj.core.api.Assertions;
3435
import org.junit.Assert;
3536
import org.junit.Test;
3637

@@ -259,12 +260,12 @@ public void testBadSparkPartitionFilter() {
259260

260261
Expression projection = Projections.inclusive(spec).project(filter);
261262

262-
Assert.assertTrue(projection instanceof Or);
263+
Assertions.assertThat(projection).isInstanceOf(Or.class);
263264
Or or1 = (Or) projection;
264265
UnboundPredicate<?> dateint1 = assertAndUnwrapUnbound(or1.left());
265266
Assert.assertEquals("Should be a dateint predicate", "dateint", dateint1.ref().name());
266267
Assert.assertEquals("Should be dateint=20180416", 20180416, dateint1.literal().value());
267-
Assert.assertTrue(or1.right() instanceof Or);
268+
Assertions.assertThat(or1.right()).isInstanceOf(Or.class);
268269
Or or2 = (Or) or1.right();
269270
UnboundPredicate<?> dateint2 = assertAndUnwrapUnbound(or2.left());
270271
Assert.assertEquals("Should be a dateint predicate", "dateint", dateint2.ref().name());

api/src/test/java/org/apache/iceberg/transforms/TestStartsWith.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.iceberg.expressions.Projections;
3232
import org.apache.iceberg.expressions.UnboundPredicate;
3333
import org.apache.iceberg.types.Types;
34+
import org.assertj.core.api.Assertions;
3435
import org.junit.Assert;
3536
import org.junit.Test;
3637

@@ -55,7 +56,7 @@ public void testTruncateProjections() {
5556
assertProjectionStrict(spec, startsWith(COLUMN, "abab"), "abab", Expression.Operation.EQ);
5657

5758
Expression projection = Projections.strict(spec).project(startsWith(COLUMN, "ababab"));
58-
Assert.assertTrue(projection instanceof False);
59+
Assertions.assertThat(projection).isInstanceOf(False.class);
5960
}
6061

6162
@Test

aws/src/test/java/org/apache/iceberg/aws/glue/LockManagersTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
import java.util.Map;
2323
import org.apache.iceberg.CatalogProperties;
2424
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
25-
import org.junit.Assert;
25+
import org.assertj.core.api.Assertions;
2626
import org.junit.Test;
2727

2828
public class LockManagersTest {
2929

3030
@Test
3131
public void testLoadDefaultLockManager() {
32-
Assert.assertTrue(LockManagers.defaultLockManager() instanceof LockManagers.InMemoryLockManager);
32+
Assertions.assertThat(LockManagers.defaultLockManager()).isInstanceOf(LockManagers.InMemoryLockManager.class);
3333
}
3434

3535
@Test
3636
public void testLoadCustomLockManager() {
3737
Map<String, String> properties = Maps.newHashMap();
3838
properties.put(CatalogProperties.LOCK_IMPL, CustomLockManager.class.getName());
39-
Assert.assertTrue(LockManagers.from(properties) instanceof CustomLockManager);
39+
Assertions.assertThat(LockManagers.from(properties)).isInstanceOf(CustomLockManager.class);
4040
}
4141

4242
static class CustomLockManager implements LockManager {

core/src/test/java/org/apache/iceberg/TestCatalogUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.iceberg.io.InputFile;
3333
import org.apache.iceberg.io.OutputFile;
3434
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
35+
import org.assertj.core.api.Assertions;
3536
import org.junit.Assert;
3637
import org.junit.Test;
3738

@@ -44,7 +45,7 @@ public void loadCustomCatalog() {
4445
Configuration hadoopConf = new Configuration();
4546
String name = "custom";
4647
Catalog catalog = CatalogUtil.loadCatalog(TestCatalog.class.getName(), name, options, hadoopConf);
47-
Assert.assertTrue(catalog instanceof TestCatalog);
48+
Assertions.assertThat(catalog).isInstanceOf(TestCatalog.class);
4849
Assert.assertEquals(name, ((TestCatalog) catalog).catalogName);
4950
Assert.assertEquals(options, ((TestCatalog) catalog).flinkOptions);
5051
}
@@ -57,7 +58,7 @@ public void loadCustomCatalog_withHadoopConfig() {
5758
hadoopConf.set("key", "val");
5859
String name = "custom";
5960
Catalog catalog = CatalogUtil.loadCatalog(TestCatalogConfigurable.class.getName(), name, options, hadoopConf);
60-
Assert.assertTrue(catalog instanceof TestCatalogConfigurable);
61+
Assertions.assertThat(catalog).isInstanceOf(TestCatalogConfigurable.class);
6162
Assert.assertEquals(name, ((TestCatalogConfigurable) catalog).catalogName);
6263
Assert.assertEquals(options, ((TestCatalogConfigurable) catalog).flinkOptions);
6364
Assert.assertEquals(hadoopConf, ((TestCatalogConfigurable) catalog).configuration);
@@ -120,7 +121,7 @@ public void loadCustomFileIO_noArg() {
120121
Map<String, String> properties = Maps.newHashMap();
121122
properties.put("key", "val");
122123
FileIO fileIO = CatalogUtil.loadFileIO(TestFileIONoArg.class.getName(), properties, null);
123-
Assert.assertTrue(fileIO instanceof TestFileIONoArg);
124+
Assertions.assertThat(fileIO).isInstanceOf(TestFileIONoArg.class);
124125
Assert.assertEquals(properties, ((TestFileIONoArg) fileIO).map);
125126
}
126127

@@ -129,7 +130,7 @@ public void loadCustomFileIO_hadoopConfigConstructor() {
129130
Configuration configuration = new Configuration();
130131
configuration.set("key", "val");
131132
FileIO fileIO = CatalogUtil.loadFileIO(HadoopFileIO.class.getName(), Maps.newHashMap(), configuration);
132-
Assert.assertTrue(fileIO instanceof HadoopFileIO);
133+
Assertions.assertThat(fileIO).isInstanceOf(HadoopFileIO.class);
133134
Assert.assertEquals("val", ((HadoopFileIO) fileIO).conf().get("key"));
134135
}
135136

@@ -138,7 +139,7 @@ public void loadCustomFileIO_configurable() {
138139
Configuration configuration = new Configuration();
139140
configuration.set("key", "val");
140141
FileIO fileIO = CatalogUtil.loadFileIO(TestFileIOConfigurable.class.getName(), Maps.newHashMap(), configuration);
141-
Assert.assertTrue(fileIO instanceof TestFileIOConfigurable);
142+
Assertions.assertThat(fileIO).isInstanceOf(TestFileIOConfigurable.class);
142143
Assert.assertEquals(configuration, ((TestFileIOConfigurable) fileIO).configuration);
143144
}
144145

core/src/test/java/org/apache/iceberg/TestSortOrderParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testUnknownTransforms() {
4747

4848
Assert.assertEquals(10, order.orderId());
4949
Assert.assertEquals(1, order.fields().size());
50-
Assert.assertTrue(order.fields().get(0).transform() instanceof UnknownTransform);
50+
org.assertj.core.api.Assertions.assertThat(order.fields().get(0).transform()).isInstanceOf(UnknownTransform.class);
5151
Assert.assertEquals("custom_transform", order.fields().get(0).transform().toString());
5252
Assert.assertEquals(2, order.fields().get(0).sourceId());
5353
Assert.assertEquals(DESC, order.fields().get(0).direction());

core/src/test/java/org/apache/iceberg/avro/AvroTestHelpers.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.avro.generic.GenericData.Record;
2828
import org.apache.iceberg.types.Type;
2929
import org.apache.iceberg.types.Types;
30+
import org.assertj.core.api.Assertions;
3031
import org.junit.Assert;
3132

3233
import static org.apache.iceberg.avro.AvroSchemaUtil.toOption;
@@ -129,18 +130,18 @@ private static void assertEquals(Type type, Object expected, Object actual) {
129130
Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
130131
break;
131132
case STRUCT:
132-
Assert.assertTrue("Expected should be a Record", expected instanceof Record);
133-
Assert.assertTrue("Actual should be a Record", actual instanceof Record);
133+
Assertions.assertThat(expected).as("Expected should be a Record").isInstanceOf(Record.class);
134+
Assertions.assertThat(actual).as("Actual should be a Record").isInstanceOf(Record.class);
134135
assertEquals(type.asStructType(), (Record) expected, (Record) actual);
135136
break;
136137
case LIST:
137-
Assert.assertTrue("Expected should be a List", expected instanceof List);
138-
Assert.assertTrue("Actual should be a List", actual instanceof List);
138+
Assertions.assertThat(expected).as("Expected should be a List").isInstanceOf(List.class);
139+
Assertions.assertThat(actual).as("Actual should be a List").isInstanceOf(List.class);
139140
assertEquals(type.asListType(), (List) expected, (List) actual);
140141
break;
141142
case MAP:
142-
Assert.assertTrue("Expected should be a Map", expected instanceof Map);
143-
Assert.assertTrue("Actual should be a Map", actual instanceof Map);
143+
Assertions.assertThat(expected).as("Expected should be a Map").isInstanceOf(Map.class);
144+
Assertions.assertThat(actual).as("Actual should be a Map").isInstanceOf(Map.class);
144145
assertEquals(type.asMapType(), (Map<?, ?>) expected, (Map<?, ?>) actual);
145146
break;
146147
default:

core/src/test/java/org/apache/iceberg/util/TestExceptionUtil.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iceberg.util;
2121

2222
import java.io.IOException;
23+
import org.assertj.core.api.Assertions;
2324
import org.junit.Assert;
2425
import org.junit.Test;
2526
import org.slf4j.Logger;
@@ -56,11 +57,11 @@ public void testRunSafely() {
5657
Assert.assertEquals("Should have 2 suppressed exceptions", 2, e.getSuppressed().length);
5758

5859
Throwable throwSuppressed = e.getSuppressed()[0];
59-
Assert.assertTrue("Should be an Exception", throwSuppressed instanceof Exception);
60+
Assertions.assertThat(throwSuppressed).as("Should be an Exception").isInstanceOf(Exception.class);
6061
Assert.assertEquals("Should have correct message", "test catch suppression", throwSuppressed.getMessage());
6162

6263
Throwable finallySuppressed = e.getSuppressed()[1];
63-
Assert.assertTrue("Should be a RuntimeException", finallySuppressed instanceof RuntimeException);
64+
Assertions.assertThat(finallySuppressed).as("Should be a RuntimeException").isInstanceOf(RuntimeException.class);
6465
Assert.assertEquals("Should have correct message", "test finally suppression", finallySuppressed.getMessage());
6566
}
6667
}
@@ -90,11 +91,11 @@ public void testRunSafelyTwoExceptions() {
9091
Assert.assertEquals("Should have 2 suppressed exceptions", 2, e.getSuppressed().length);
9192

9293
Throwable throwSuppressed = e.getSuppressed()[0];
93-
Assert.assertTrue("Should be an Exception", throwSuppressed instanceof Exception);
94+
Assertions.assertThat(throwSuppressed).as("Should be an Exception").isInstanceOf(Exception.class);
9495
Assert.assertEquals("Should have correct message", "test catch suppression", throwSuppressed.getMessage());
9596

9697
Throwable finallySuppressed = e.getSuppressed()[1];
97-
Assert.assertTrue("Should be a RuntimeException", finallySuppressed instanceof RuntimeException);
98+
Assertions.assertThat(finallySuppressed).as("Should be a RuntimeException").isInstanceOf(RuntimeException.class);
9899
Assert.assertEquals("Should have correct message", "test finally suppression", finallySuppressed.getMessage());
99100
}
100101
}
@@ -125,11 +126,11 @@ public void testRunSafelyThreeExceptions() {
125126
Assert.assertEquals("Should have 2 suppressed exceptions", 2, e.getSuppressed().length);
126127

127128
Throwable throwSuppressed = e.getSuppressed()[0];
128-
Assert.assertTrue("Should be an Exception", throwSuppressed instanceof Exception);
129+
Assertions.assertThat(throwSuppressed).as("Should be an Exception").isInstanceOf(Exception.class);
129130
Assert.assertEquals("Should have correct message", "test catch suppression", throwSuppressed.getMessage());
130131

131132
Throwable finallySuppressed = e.getSuppressed()[1];
132-
Assert.assertTrue("Should be a RuntimeException", finallySuppressed instanceof RuntimeException);
133+
Assertions.assertThat(finallySuppressed).as("Should be a RuntimeException").isInstanceOf(RuntimeException.class);
133134
Assert.assertEquals("Should have correct message", "test finally suppression", finallySuppressed.getMessage());
134135
}
135136
}
@@ -156,11 +157,12 @@ public void testRunSafelyRuntimeExceptions() {
156157
Assert.assertEquals("Should have 2 suppressed exceptions", 2, e.getSuppressed().length);
157158

158159
Throwable throwSuppressed = e.getSuppressed()[0];
159-
Assert.assertTrue("Should be an Exception", throwSuppressed instanceof Exception);
160+
Assertions.assertThat(throwSuppressed).as("Should be an Exception").isInstanceOf(Exception.class);
160161
Assert.assertEquals("Should have correct message", "test catch suppression", throwSuppressed.getMessage());
161162

162163
Throwable finallySuppressed = e.getSuppressed()[1];
163-
Assert.assertTrue("Should be a CustomCheckedException", finallySuppressed instanceof CustomCheckedException);
164+
Assertions.assertThat(finallySuppressed).as("Should be a CustomCheckedException")
165+
.isInstanceOf(CustomCheckedException.class);
164166
Assert.assertEquals("Should have correct message", "test finally suppression", finallySuppressed.getMessage());
165167
}
166168
}

data/src/test/java/org/apache/iceberg/data/DataTestHelpers.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import org.apache.iceberg.types.Type;
2525
import org.apache.iceberg.types.Types;
26+
import org.assertj.core.api.Assertions;
2627
import org.junit.Assert;
2728

2829
public class DataTestHelpers {
@@ -88,24 +89,24 @@ private static void assertEquals(Type type, Object expected, Object actual) {
8889
Assert.assertEquals("Primitive value should be equal to expected for type " + type, expected, actual);
8990
break;
9091
case FIXED:
91-
Assert.assertTrue("Expected should be a byte[]", expected instanceof byte[]);
92-
Assert.assertTrue("Actual should be a byte[]", actual instanceof byte[]);
92+
Assertions.assertThat(expected).as("Expected should be a byte[]").isInstanceOf(byte[].class);
93+
Assertions.assertThat(expected).as("Actual should be a byte[]").isInstanceOf(byte[].class);
9394
Assert.assertArrayEquals("Array contents should be equal",
9495
(byte[]) expected, (byte[]) actual);
9596
break;
9697
case STRUCT:
97-
Assert.assertTrue("Expected should be a Record", expected instanceof Record);
98-
Assert.assertTrue("Actual should be a Record", actual instanceof Record);
98+
Assertions.assertThat(expected).as("Expected should be a Record").isInstanceOf(Record.class);
99+
Assertions.assertThat(actual).as("Actual should be a Record").isInstanceOf(Record.class);
99100
assertEquals(type.asStructType(), (Record) expected, (Record) actual);
100101
break;
101102
case LIST:
102-
Assert.assertTrue("Expected should be a List", expected instanceof List);
103-
Assert.assertTrue("Actual should be a List", actual instanceof List);
103+
Assertions.assertThat(expected).as("Expected should be a List").isInstanceOf(List.class);
104+
Assertions.assertThat(actual).as("Actual should be a List").isInstanceOf(List.class);
104105
assertEquals(type.asListType(), (List) expected, (List) actual);
105106
break;
106107
case MAP:
107-
Assert.assertTrue("Expected should be a Map", expected instanceof Map);
108-
Assert.assertTrue("Actual should be a Map", actual instanceof Map);
108+
Assertions.assertThat(expected).as("Expected should be a Map").isInstanceOf(Map.class);
109+
Assertions.assertThat(actual).as("Actual should be a Map").isInstanceOf(Map.class);
109110
assertEquals(type.asMapType(), (Map<?, ?>) expected, (Map<?, ?>) actual);
110111
break;
111112
default:

flink/src/test/java/org/apache/iceberg/flink/TestCatalogTableLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.iceberg.io.FileIO;
3636
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
3737
import org.apache.iceberg.types.Types;
38+
import org.assertj.core.api.Assertions;
3839
import org.junit.AfterClass;
3940
import org.junit.Assert;
4041
import org.junit.BeforeClass;
@@ -107,7 +108,7 @@ private static void validateTableLoader(TableLoader loader) throws IOException,
107108

108109
private static void validateHadoopConf(Table table) {
109110
FileIO io = table.io();
110-
Assert.assertTrue("FileIO should be a HadoopFileIO", io instanceof HadoopFileIO);
111+
Assertions.assertThat(io).as("FileIO should be a HadoopFileIO").isInstanceOf(HadoopFileIO.class);
111112
HadoopFileIO hadoopIO = (HadoopFileIO) io;
112113
Assert.assertEquals("my_value", hadoopIO.conf().get("my_key"));
113114
}

0 commit comments

Comments
 (0)