You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by et...@apache.org on 2023/06/03 14:36:50 UTC
[iceberg] branch master updated: API: Switch tests to JUnit5 (io,metrics,transforms packages) (#7757)
This is an automated email from the ASF dual-hosted git repository.
etudenhoefner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 9d42eb44a3 API: Switch tests to JUnit5 (io,metrics,transforms packages) (#7757)
9d42eb44a3 is described below
commit 9d42eb44a32ff4a1f86e8427fe023bde1e9652f7
Author: Rakesh Das <16...@users.noreply.github.com>
AuthorDate: Sat Jun 3 20:06:44 2023 +0530
API: Switch tests to JUnit5 (io,metrics,transforms packages) (#7757)
---
.../org/apache/iceberg/io/TestCloseableGroup.java | 2 +-
.../apache/iceberg/io/TestCloseableIterable.java | 55 ++---
.../org/apache/iceberg/io/TestClosingIterator.java | 22 +-
.../apache/iceberg/metrics/TestDefaultCounter.java | 2 +-
.../iceberg/metrics/TestDefaultMetricsContext.java | 2 +-
.../apache/iceberg/metrics/TestDefaultTimer.java | 2 +-
.../metrics/TestFixedReservoirHistogram.java | 2 +-
.../apache/iceberg/transforms/TestBucketing.java | 258 ++++++++++-----------
.../transforms/TestBucketingProjection.java | 31 +--
.../org/apache/iceberg/transforms/TestDates.java | 163 ++++++-------
.../iceberg/transforms/TestDatesProjection.java | 32 +--
.../apache/iceberg/transforms/TestIdentity.java | 70 +++---
.../iceberg/transforms/TestNotStartsWith.java | 109 ++++-----
.../apache/iceberg/transforms/TestProjection.java | 118 +++++-----
.../apache/iceberg/transforms/TestResiduals.java | 73 +++---
.../apache/iceberg/transforms/TestStartsWith.java | 14 +-
.../apache/iceberg/transforms/TestTimestamps.java | 219 ++++++++---------
.../transforms/TestTimestampsProjection.java | 32 +--
.../transforms/TestTransformSerialization.java | 9 +-
.../apache/iceberg/transforms/TestTruncate.java | 102 ++++----
.../transforms/TestTruncatesProjection.java | 33 +--
.../iceberg/transforms/TestTruncatesResiduals.java | 12 +-
22 files changed, 651 insertions(+), 711 deletions(-)
diff --git a/api/src/test/java/org/apache/iceberg/io/TestCloseableGroup.java b/api/src/test/java/org/apache/iceberg/io/TestCloseableGroup.java
index a05a8a1ddf..4e9604fc1b 100644
--- a/api/src/test/java/org/apache/iceberg/io/TestCloseableGroup.java
+++ b/api/src/test/java/org/apache/iceberg/io/TestCloseableGroup.java
@@ -21,7 +21,7 @@ package org.apache.iceberg.io;
import java.io.Closeable;
import java.io.IOException;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class TestCloseableGroup {
diff --git a/api/src/test/java/org/apache/iceberg/io/TestCloseableIterable.java b/api/src/test/java/org/apache/iceberg/io/TestCloseableIterable.java
index 6f50605fab..5a148746cf 100644
--- a/api/src/test/java/org/apache/iceberg/io/TestCloseableIterable.java
+++ b/api/src/test/java/org/apache/iceberg/io/TestCloseableIterable.java
@@ -18,6 +18,8 @@
*/
package org.apache.iceberg.io;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -31,8 +33,7 @@ import org.apache.iceberg.metrics.DefaultMetricsContext;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestCloseableIterable {
@@ -43,26 +44,26 @@ public class TestCloseableIterable {
CloseableIterable<Integer> filtered = CloseableIterable.filter(iterable, x -> x > 5);
- Assert.assertFalse("Iterable should not be closed", iterable.closed());
- Assert.assertFalse("Iterator should not be closed", iterator.closed());
+ assertThat(iterable.closed()).isFalse();
+ assertThat(iterator.closed()).isFalse();
filtered.iterator().close();
- Assert.assertFalse("Iterable should not be closed", iterable.closed());
- Assert.assertTrue("Iterator should be closed", iterator.closed());
+ assertThat(iterable.closed()).isFalse();
+ assertThat(iterator.closed()).isTrue();
filtered.close();
- Assert.assertTrue("Iterable should be closed", iterable.closed());
- Assert.assertTrue("Iterator should be closed", iterator.closed());
+ assertThat(iterable.closed()).isTrue();
+ assertThat(iterator.closed()).isTrue();
}
@Test
public void testFilterAutomaticallyClosable() throws IOException {
TestableCloseableIterable iterable = new TestableCloseableIterable();
- Assert.assertFalse("Iterable should not be closed", iterable.closed());
+ assertThat(iterable.closed()).isFalse();
try (CloseableIterable<Integer> filtered = CloseableIterable.filter(iterable, x -> x > 5)) {
- Assert.assertFalse("Iterable should not be closed", iterable.closed());
+ assertThat(iterable.closed()).isFalse();
}
- Assert.assertTrue("Iterable should be closed", iterable.closed());
+ assertThat(iterable.closed()).isTrue();
}
@Test
@@ -73,19 +74,19 @@ public class TestCloseableIterable {
CloseableIterable<Integer> concat1 =
CloseableIterable.concat(Lists.newArrayList(iter, empty, empty));
- Assert.assertEquals(Iterables.getLast(concat1).intValue(), 3);
+ assertThat(Iterables.getLast(concat1).intValue()).isEqualTo(3);
CloseableIterable<Integer> concat2 =
CloseableIterable.concat(Lists.newArrayList(empty, empty, iter));
- Assert.assertEquals(Iterables.getLast(concat2).intValue(), 3);
+ assertThat(Iterables.getLast(concat2).intValue()).isEqualTo(3);
CloseableIterable<Integer> concat3 =
CloseableIterable.concat(Lists.newArrayList(empty, iter, empty));
- Assert.assertEquals(Iterables.getLast(concat3).intValue(), 3);
+ assertThat(Iterables.getLast(concat3).intValue()).isEqualTo(3);
CloseableIterable<Integer> concat4 =
CloseableIterable.concat(Lists.newArrayList(empty, iter, empty, empty, iter));
- Assert.assertEquals(Iterables.getLast(concat4).intValue(), 3);
+ assertThat(Iterables.getLast(concat4).intValue()).isEqualTo(3);
// This will throw a NoSuchElementException
CloseableIterable<Integer> concat5 =
@@ -107,9 +108,9 @@ public class TestCloseableIterable {
try (CloseableIterable<Integer> iter =
CloseableIterable.whenComplete(
CloseableIterable.combine(items, () -> {}), completionCounter::incrementAndGet)) {
- iter.forEach(val -> Assertions.assertThat(completionCounter.get()).isEqualTo(0));
+ iter.forEach(val -> assertThat(completionCounter.get()).isZero());
}
- Assertions.assertThat(completionCounter.get()).isEqualTo(1);
+ assertThat(completionCounter.get()).isOne();
}
@Test
@@ -119,9 +120,9 @@ public class TestCloseableIterable {
try (CloseableIterable<Integer> iter =
CloseableIterable.whenComplete(
CloseableIterable.combine(empty, () -> {}), completionCounter::incrementAndGet)) {
- iter.forEach(val -> Assertions.assertThat(completionCounter.get()).isEqualTo(0));
+ iter.forEach(val -> Assertions.assertThat(completionCounter.get()).isZero());
}
- Assertions.assertThat(completionCounter.get()).isEqualTo(1);
+ Assertions.assertThat(completionCounter.get()).isOne();
}
@Test
@@ -131,9 +132,9 @@ public class TestCloseableIterable {
CloseableIterable<Integer> iter =
CloseableIterable.whenComplete(
CloseableIterable.combine(items, () -> {}), completionCounter::incrementAndGet);
- iter.forEach(val -> Assertions.assertThat(completionCounter.get()).isEqualTo(0));
+ iter.forEach(val -> assertThat(completionCounter.get()).isZero());
// given that we never close iter, the completionRunnable is never called
- Assertions.assertThat(completionCounter.get()).isEqualTo(0);
+ assertThat(completionCounter.get()).isZero();
}
@Test
@@ -151,20 +152,20 @@ public class TestCloseableIterable {
throw new RuntimeException("expected");
}),
completionCounter::incrementAndGet)) {
- iter.forEach(val -> Assertions.assertThat(completionCounter.get()).isEqualTo(0));
+ iter.forEach(val -> assertThat(completionCounter.get()).isZero());
}
})
.isInstanceOf(RuntimeException.class)
.hasMessage("expected");
- Assertions.assertThat(completionCounter.get()).isEqualTo(1);
+ Assertions.assertThat(completionCounter.get()).isOne();
}
@Test
public void testConcatWithEmpty() {
AtomicInteger counter = new AtomicInteger(0);
CloseableIterable.concat(Collections.emptyList()).forEach(c -> counter.incrementAndGet());
- Assertions.assertThat(counter.get()).isEqualTo(0);
+ assertThat(counter.get()).isZero();
}
@Test
@@ -197,7 +198,7 @@ public class TestCloseableIterable {
try (CloseableIterable<Integer> concat = CloseableIterable.concat(transform)) {
concat.forEach(count -> consumedCounter.getAndIncrement());
}
- Assertions.assertThat(counter.get()).isEqualTo(items.size()).isEqualTo(consumedCounter.get());
+ assertThat(counter.get()).isEqualTo(items.size()).isEqualTo(consumedCounter.get());
}
@Test
@@ -214,7 +215,7 @@ public class TestCloseableIterable {
CloseableIterable<Integer> items =
CloseableIterable.count(
counter, CloseableIterable.withNoopClose(Arrays.asList(1, 2, 3, 4, 5)));
- Assertions.assertThat(counter.value()).isEqualTo(0);
+ assertThat(counter.value()).isZero();
items.forEach(item -> {});
Assertions.assertThat(counter.value()).isEqualTo(5);
}
@@ -227,7 +228,7 @@ public class TestCloseableIterable {
counter,
CloseableIterable.withNoopClose(Arrays.asList(1, 2, 3, 4, 5)),
x -> x % 2 == 0);
- Assertions.assertThat(counter.value()).isEqualTo(0);
+ assertThat(counter.value()).isZero();
items.forEach(item -> {});
Assertions.assertThat(counter.value()).isEqualTo(3);
}
diff --git a/api/src/test/java/org/apache/iceberg/io/TestClosingIterator.java b/api/src/test/java/org/apache/iceberg/io/TestClosingIterator.java
index 6fdf8c1244..19bca2edc2 100644
--- a/api/src/test/java/org/apache/iceberg/io/TestClosingIterator.java
+++ b/api/src/test/java/org/apache/iceberg/io/TestClosingIterator.java
@@ -18,23 +18,21 @@
*/
package org.apache.iceberg.io;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestClosingIterator {
@Test
public void testEmptyIterator() {
CloseableIterator<String> underlying = mock(CloseableIterator.class);
ClosingIterator<String> closingIterator = new ClosingIterator<>(underlying);
- assertFalse(closingIterator.hasNext());
+ assertThat(closingIterator).isExhausted();
}
@Test
@@ -43,8 +41,8 @@ public class TestClosingIterator {
when(underlying.hasNext()).thenReturn(true);
when(underlying.next()).thenReturn("hello");
ClosingIterator<String> closingIterator = new ClosingIterator<>(underlying);
- assertTrue(closingIterator.hasNext());
- assertEquals("hello", closingIterator.next());
+ assertThat(closingIterator).hasNext();
+ assertThat(closingIterator.next()).isEqualTo("hello");
}
@Test
@@ -53,10 +51,9 @@ public class TestClosingIterator {
when(underlying.hasNext()).thenReturn(true).thenReturn(false);
when(underlying.next()).thenReturn("hello");
ClosingIterator<String> closingIterator = new ClosingIterator<>(underlying);
- assertTrue(closingIterator.hasNext());
- assertEquals("hello", closingIterator.next());
-
- assertFalse(closingIterator.hasNext());
+ assertThat(closingIterator).hasNext();
+ assertThat(closingIterator.next()).isEqualTo("hello");
+ assertThat(closingIterator).isExhausted();
verify(underlying, times(1)).close();
}
@@ -64,8 +61,7 @@ public class TestClosingIterator {
public void testCloseCalledOnceForMultipleHasNextCalls() throws Exception {
CloseableIterator<String> underlying = mock(CloseableIterator.class);
ClosingIterator<String> closingIterator = new ClosingIterator<>(underlying);
- assertFalse(closingIterator.hasNext());
- assertFalse(closingIterator.hasNext());
+ assertThat(closingIterator).isExhausted();
verify(underlying, times(1)).close();
}
diff --git a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultCounter.java b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultCounter.java
index 7d8eaf8579..5f62e20ab4 100644
--- a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultCounter.java
+++ b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultCounter.java
@@ -20,7 +20,7 @@ package org.apache.iceberg.metrics;
import org.apache.iceberg.metrics.MetricsContext.Unit;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDefaultCounter {
diff --git a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultMetricsContext.java b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultMetricsContext.java
index b7e0d90b38..86c216119e 100644
--- a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultMetricsContext.java
+++ b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultMetricsContext.java
@@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.withinPercentage;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDefaultMetricsContext {
diff --git a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultTimer.java b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultTimer.java
index 8c47006743..950bbc931d 100644
--- a/api/src/test/java/org/apache/iceberg/metrics/TestDefaultTimer.java
+++ b/api/src/test/java/org/apache/iceberg/metrics/TestDefaultTimer.java
@@ -32,7 +32,7 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDefaultTimer {
diff --git a/api/src/test/java/org/apache/iceberg/metrics/TestFixedReservoirHistogram.java b/api/src/test/java/org/apache/iceberg/metrics/TestFixedReservoirHistogram.java
index 168a337b11..25e323c026 100644
--- a/api/src/test/java/org/apache/iceberg/metrics/TestFixedReservoirHistogram.java
+++ b/api/src/test/java/org/apache/iceberg/metrics/TestFixedReservoirHistogram.java
@@ -29,7 +29,7 @@ import java.util.concurrent.Future;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestFixedReservoirHistogram {
@Test
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestBucketing.java b/api/src/test/java/org/apache/iceberg/transforms/TestBucketing.java
index 8ac5b542a8..b8a0e40c11 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestBucketing.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestBucketing.java
@@ -18,6 +18,8 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
@@ -33,16 +35,15 @@ import org.apache.iceberg.relocated.com.google.common.hash.Hashing;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.BucketUtil;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class TestBucketing {
private static final HashFunction MURMUR3 = Hashing.murmur3_32_fixed();
private static Constructor<UUID> uuidBytesConstructor;
- @BeforeClass
+ @BeforeAll
public static void getUUIDConstructor() {
try {
uuidBytesConstructor = UUID.class.getDeclaredConstructor(byte[].class);
@@ -54,7 +55,7 @@ public class TestBucketing {
private Random testRandom = null;
- @Before
+ @BeforeEach
public void initRandom() {
// reinitialize random for each test to avoid dependence on run order
this.testRandom = new Random(314358);
@@ -62,72 +63,82 @@ public class TestBucketing {
@Test
public void testSpecValues() {
- Assert.assertEquals("Spec example: hash(true) = 1392991556", 1392991556, BucketUtil.hash(1));
- Assert.assertEquals("Spec example: hash(34) = 2017239379", 2017239379, BucketUtil.hash(34));
- Assert.assertEquals("Spec example: hash(34L) = 2017239379", 2017239379, BucketUtil.hash(34L));
-
- Assert.assertEquals(
- "Spec example: hash(17.11F) = -142385009", -142385009, BucketUtil.hash(1.0F));
- Assert.assertEquals(
- "Spec example: hash(17.11D) = -142385009", -142385009, BucketUtil.hash(1.0D));
- Assert.assertEquals("Spec example: hash(0.0F) = 1669671676", 1669671676, BucketUtil.hash(0.0F));
- Assert.assertEquals(
- "Spec example: hash(-0.0F) = 1669671676", 1669671676, BucketUtil.hash(-0.0F));
- Assert.assertEquals("Spec example: hash(0.0) = 1669671676", 1669671676, BucketUtil.hash(0.0));
- Assert.assertEquals("Spec example: hash(-0.0) = 1669671676", 1669671676, BucketUtil.hash(-0.0));
-
- Assert.assertEquals(
- "Spec example: hash(decimal2(14.20)) = -500754589",
- -500754589,
- BucketUtil.hash(new BigDecimal("14.20")));
- Assert.assertEquals(
- "Spec example: hash(decimal2(14.20)) = -500754589",
- -500754589,
- BucketUtil.hash(new BigDecimal("14.20")));
+ assertThat(BucketUtil.hash(1))
+ .as("Spec example: hash(true) = 1392991556")
+ .isEqualTo(1392991556);
+ assertThat(BucketUtil.hash(34)).as("Spec example: hash(34) = 2017239379").isEqualTo(2017239379);
+ assertThat(BucketUtil.hash(34L))
+ .as("Spec example: hash(34L) = 2017239379")
+ .isEqualTo(2017239379);
+
+ assertThat(BucketUtil.hash(1.0F))
+ .as("Spec example: hash(17.11F) = -142385009")
+ .isEqualTo(-142385009);
+ assertThat(BucketUtil.hash(1.0D))
+ .as("Spec example: hash(17.11D) = -142385009")
+ .isEqualTo(-142385009);
+ assertThat(BucketUtil.hash(0.0F))
+ .as("Spec example: hash(0.0F) = 1669671676")
+ .isEqualTo(1669671676);
+ assertThat(BucketUtil.hash(-0.0F))
+ .as("Spec example: hash(-0.0F) = 1669671676")
+ .isEqualTo(1669671676);
+ assertThat(BucketUtil.hash(0.0))
+ .as("Spec example: hash(0.0) = 1669671676")
+ .isEqualTo(1669671676);
+ assertThat(BucketUtil.hash(-0.0))
+ .as("Spec example: hash(-0.0) = 1669671676")
+ .isEqualTo(1669671676);
+
+ assertThat(BucketUtil.hash(new BigDecimal("14.20")))
+ .as("Spec example: hash(decimal2(14.20)) = -500754589")
+ .isEqualTo(-500754589)
+ .as("Spec example: hash(decimal2(14.20)) = -500754589")
+ .isEqualTo(-500754589);
Literal<Integer> date = Literal.of("2017-11-16").to(Types.DateType.get());
- Assert.assertEquals(
- "Spec example: hash(2017-11-16) = -653330422", -653330422, BucketUtil.hash(date.value()));
+ assertThat(BucketUtil.hash(date.value()))
+ .as("Spec example: hash(2017-11-16) = -653330422")
+ .isEqualTo(-653330422);
Literal<Long> timeValue = Literal.of("22:31:08").to(Types.TimeType.get());
- Assert.assertEquals(
- "Spec example: hash(22:31:08) = -662762989",
- -662762989,
- BucketUtil.hash(timeValue.value()));
+ assertThat(BucketUtil.hash(timeValue.value()))
+ .as("Spec example: hash(22:31:08) = -662762989")
+ .isEqualTo(-662762989);
Literal<Long> timestampVal =
Literal.of("2017-11-16T22:31:08").to(Types.TimestampType.withoutZone());
- Assert.assertEquals(
- "Spec example: hash(2017-11-16T22:31:08) = -2047944441",
- -2047944441,
- BucketUtil.hash(timestampVal.value()));
+ assertThat(BucketUtil.hash(timestampVal.value()))
+ .as("Spec example: hash(2017-11-16T22:31:08) = -2047944441")
+ .isEqualTo(-2047944441);
Literal<Long> timestamptzVal =
Literal.of("2017-11-16T14:31:08-08:00").to(Types.TimestampType.withZone());
- Assert.assertEquals(
- "Spec example: hash(2017-11-16T14:31:08-08:00) = -2047944441",
- -2047944441,
- BucketUtil.hash(timestamptzVal.value()));
-
- Assert.assertEquals(
- "Spec example: hash(\"iceberg\") = 1210000089", 1210000089, BucketUtil.hash("iceberg"));
- Assert.assertEquals(
- "Spec example: hash(\"iceberg\") = 1210000089",
- 1210000089,
- BucketUtil.hash(new Utf8("iceberg")));
+ assertThat(BucketUtil.hash(timestamptzVal.value()))
+ .as("Spec example: hash(2017-11-16T14:31:08-08:00) = -2047944441")
+ .isEqualTo(-2047944441);
+
+ assertThat(BucketUtil.hash("iceberg"))
+ .as("Spec example: hash(\"iceberg\") = 1210000089")
+ .isEqualTo(1210000089);
+ assertThat(BucketUtil.hash(new Utf8("iceberg")))
+ .as("Spec example: hash(\"iceberg\") = 1210000089")
+ .isEqualTo(1210000089);
Literal<UUID> uuid =
Literal.of("f79c3e09-677c-4bbd-a479-3f349cb785e7").to(Types.UUIDType.get());
- Assert.assertEquals(
- "Spec example: hash(f79c3e09-677c-4bbd-a479-3f349cb785e7) = 1488055340",
- 1488055340,
- BucketUtil.hash(uuid.value()));
+ assertThat(BucketUtil.hash(uuid.value()))
+ .as("Spec example: hash(f79c3e09-677c-4bbd-a479-3f349cb785e7) = 1488055340")
+ .isEqualTo(1488055340);
ByteBuffer bytes = ByteBuffer.wrap(new byte[] {0, 1, 2, 3});
- Assert.assertEquals(
- "Spec example: hash([00 01 02 03]) = -188683207", -188683207, BucketUtil.hash(bytes));
- Assert.assertEquals(
- "Spec example: hash([00 01 02 03]) = -188683207", -188683207, BucketUtil.hash(bytes));
+ assertThat(BucketUtil.hash(bytes))
+ .as("Spec example: hash([00 01 02 03]) = -188683207")
+ .isEqualTo(-188683207);
+ // another assertion for confirming that hashing a ByteBuffer again doesnt modify its value.
+ assertThat(BucketUtil.hash(bytes))
+ .as("Spec example: hash([00 01 02 03]) = -188683207")
+ .isEqualTo(-188683207);
}
@Test
@@ -137,10 +148,9 @@ public class TestBucketing {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putLong(num);
- Assert.assertEquals(
- "Integer hash should match hash of little-endian bytes",
- hashBytes(buffer.array()),
- BucketUtil.hash(num));
+ assertThat(BucketUtil.hash(num))
+ .as("Integer hash should match hash of little-endian bytes")
+ .isEqualTo(hashBytes(buffer.array()));
}
@Test
@@ -150,46 +160,41 @@ public class TestBucketing {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putLong(num);
- Assert.assertEquals(
- "Long hash should match hash of little-endian bytes",
- hashBytes(buffer.array()),
- BucketUtil.hash(num));
+ assertThat(BucketUtil.hash(num))
+ .as("Long hash should match hash of little-endian bytes")
+ .isEqualTo(hashBytes(buffer.array()));
}
@Test
public void testIntegerTypePromotion() {
int randomInt = testRandom.nextInt();
- Assert.assertEquals(
- "Integer and Long bucket results should match",
- BucketUtil.hash(randomInt),
- BucketUtil.hash((long) randomInt));
+ assertThat(BucketUtil.hash((long) randomInt))
+ .as("Integer and Long bucket results should match")
+ .isEqualTo(BucketUtil.hash(randomInt));
}
@Test
public void testFloatTypePromotion() {
float randomFloat = testRandom.nextFloat();
- Assert.assertEquals(
- "Float and Double bucket results should match",
- BucketUtil.hash(randomFloat),
- BucketUtil.hash((double) randomFloat));
+ assertThat(BucketUtil.hash((double) randomFloat))
+ .as("Float and Double bucket results should match")
+ .isEqualTo(BucketUtil.hash(randomFloat));
}
@Test
public void testFloatNegativeZero() {
- Assert.assertEquals(
- "Positive and negative 0.0f should have the same hash",
- BucketUtil.hash(-0.0f),
- BucketUtil.hash(0.0f));
+ assertThat(BucketUtil.hash(0.0f))
+ .as("Positive and negative 0.0f should have the same hash")
+ .isEqualTo(BucketUtil.hash(-0.0f));
}
@Test
public void testDoubleNegativeZero() {
- Assert.assertEquals(
- "Positive and negative 0.0 should have the same hash",
- BucketUtil.hash(-0.0),
- BucketUtil.hash(0.0));
+ assertThat(BucketUtil.hash(0.0))
+ .as("Positive and negative 0.0 should have the same hash")
+ .isEqualTo(BucketUtil.hash(-0.0));
}
@Test
@@ -211,11 +216,10 @@ public class TestBucketing {
};
for (float value : testNaNs) {
- Assert.assertTrue("Bit pattern is expected to be NaN.", Float.isNaN(value));
- Assert.assertEquals(
- "All NaN representations should result in the same hash",
- BucketUtil.hash(value),
- BucketUtil.hash(canonicalNaN));
+ assertThat(Float.isNaN(value)).as("Bit pattern is expected to be NaN.").isTrue();
+ assertThat(BucketUtil.hash(canonicalNaN))
+ .as("All NaN representations should result in the same hash")
+ .isEqualTo(BucketUtil.hash(value));
}
}
@@ -238,11 +242,10 @@ public class TestBucketing {
};
for (double value : testNaNs) {
- Assert.assertTrue("Bit pattern is expected to be NaN.", Double.isNaN(value));
- Assert.assertEquals(
- "All NaN representations should result in the same hash",
- BucketUtil.hash(value),
- BucketUtil.hash(canonicalNaN));
+ assertThat(Double.isNaN(value)).as("Bit pattern is expected to be NaN.").isTrue();
+ assertThat(BucketUtil.hash(canonicalNaN))
+ .as("All NaN representations should result in the same hash")
+ .isEqualTo(BucketUtil.hash(value));
}
}
@@ -252,10 +255,9 @@ public class TestBucketing {
BigDecimal decimal = BigDecimal.valueOf(num);
byte[] unscaledBytes = decimal.unscaledValue().toByteArray();
- Assert.assertEquals(
- "Decimal hash should match hash of backing bytes",
- hashBytes(unscaledBytes),
- BucketUtil.hash(decimal));
+ assertThat(BucketUtil.hash(decimal))
+ .as("Decimal hash should match hash of backing bytes")
+ .isEqualTo(hashBytes(unscaledBytes));
}
@Test
@@ -263,23 +265,22 @@ public class TestBucketing {
String string = "string to test murmur3 hash";
byte[] asBytes = string.getBytes(StandardCharsets.UTF_8);
- Assert.assertEquals(
- "String hash should match hash of UTF-8 bytes",
- hashBytes(asBytes),
- BucketUtil.hash(string));
+ assertThat(BucketUtil.hash(string))
+ .as("String hash should match hash of UTF-8 bytes")
+ .isEqualTo(hashBytes(asBytes));
}
@Test
public void testStringWithSurrogatePair() {
String string = "string with a surrogate pair: 💰";
- Assert.assertNotEquals(
- "string has no surrogate pairs", string.length(), string.codePoints().count());
+ assertThat(string.codePoints().count())
+ .as("string has no surrogate pairs")
+ .isNotEqualTo(string.length());
byte[] asBytes = string.getBytes(StandardCharsets.UTF_8);
- Assert.assertEquals(
- "String hash should match hash of UTF-8 bytes",
- hashBytes(asBytes),
- BucketUtil.hash(string));
+ assertThat(BucketUtil.hash(string))
+ .as("String hash should match hash of UTF-8 bytes")
+ .isEqualTo(hashBytes(asBytes));
}
@Test
@@ -287,8 +288,9 @@ public class TestBucketing {
Utf8 utf8 = new Utf8("string to test murmur3 hash");
byte[] asBytes = utf8.toString().getBytes(StandardCharsets.UTF_8);
- Assert.assertEquals(
- "String hash should match hash of UTF-8 bytes", hashBytes(asBytes), BucketUtil.hash(utf8));
+ assertThat(BucketUtil.hash(utf8))
+ .as("String hash should match hash of UTF-8 bytes")
+ .isEqualTo(hashBytes(asBytes));
}
@Test
@@ -296,14 +298,13 @@ public class TestBucketing {
byte[] bytes = randomBytes(128);
ByteBuffer buffer = ByteBuffer.wrap(bytes, 5, 100);
- Assert.assertEquals(
- "HeapByteBuffer hash should match hash for correct slice",
- hashBytes(bytes, 5, 100),
- BucketUtil.hash(buffer));
+ assertThat(BucketUtil.hash(buffer))
+ .as("HeapByteBuffer hash should match hash for correct slice")
+ .isEqualTo(hashBytes(bytes, 5, 100));
// verify that the buffer was not modified
- Assert.assertEquals("Buffer position should not change", 5, buffer.position());
- Assert.assertEquals("Buffer limit should not change", 105, buffer.limit());
+ assertThat(buffer.position()).as("Buffer position should not change").isEqualTo(5);
+ assertThat(buffer.limit()).as("Buffer limit should not change").isEqualTo(105);
}
@Test
@@ -311,16 +312,15 @@ public class TestBucketing {
byte[] bytes = randomBytes(128);
ByteBuffer raw = ByteBuffer.wrap(bytes, 5, 100);
ByteBuffer buffer = raw.slice();
- Assert.assertEquals("Buffer arrayOffset should be 5", 5, buffer.arrayOffset());
+ assertThat(buffer.arrayOffset()).as("Buffer arrayOffset should be 5").isEqualTo(5);
- Assert.assertEquals(
- "HeapByteBuffer hash should match hash for correct slice",
- hashBytes(bytes, 5, 100),
- BucketUtil.hash(buffer));
+ assertThat(BucketUtil.hash(buffer))
+ .as("HeapByteBuffer hash should match hash for correct slice")
+ .isEqualTo(hashBytes(bytes, 5, 100));
// verify that the buffer was not modified
- Assert.assertEquals("Buffer position should be 0", 0, buffer.position());
- Assert.assertEquals("Buffer limit should not change", 100, buffer.limit());
+ assertThat(buffer.position()).as("Buffer position should be 0").isEqualTo(0);
+ assertThat(buffer.limit()).as("Buffer limit should not change").isEqualTo(100);
}
@Test
@@ -335,14 +335,13 @@ public class TestBucketing {
buffer.put(bytes, 5, 100);
buffer.reset();
- Assert.assertEquals(
- "DirectByteBuffer hash should match hash for correct slice",
- hashBytes(bytes, 5, 100),
- BucketUtil.hash(buffer));
+ assertThat(BucketUtil.hash(buffer))
+ .as("DirectByteBuffer hash should match hash for correct slice")
+ .isEqualTo(hashBytes(bytes, 5, 100));
// verify that the buffer was not modified
- Assert.assertEquals("Buffer position should not change", 5, buffer.position());
- Assert.assertEquals("Buffer limit should not change", 105, buffer.limit());
+ assertThat(buffer.position()).as("Buffer position should not change").isEqualTo(5);
+ assertThat(buffer.limit()).as("Buffer limit should not change").isEqualTo(105);
}
@Test
@@ -350,10 +349,9 @@ public class TestBucketing {
byte[] uuidBytes = randomBytes(16);
UUID uuid = newUUID(uuidBytes);
- Assert.assertEquals(
- "UUID hash should match hash of backing bytes",
- hashBytes(uuidBytes),
- BucketUtil.hash(uuid));
+ assertThat(BucketUtil.hash(uuid))
+ .as("UUID hash should match hash of backing bytes")
+ .isEqualTo(hashBytes(uuidBytes));
}
@Test
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestBucketingProjection.java b/api/src/test/java/org/apache/iceberg/transforms/TestBucketingProjection.java
index 34b5a19dfd..52a6d2cd49 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestBucketingProjection.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestBucketingProjection.java
@@ -28,6 +28,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThanOrEqual;
import static org.apache.iceberg.expressions.Expressions.notEqual;
import static org.apache.iceberg.expressions.Expressions.notIn;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
@@ -42,8 +43,7 @@ import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestBucketingProjection {
@@ -56,10 +56,10 @@ public class TestBucketingProjection {
Expression projection = Projections.strict(spec).project(filter);
UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Strict projection never runs for IN", Expression.Operation.IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Strict projection never runs for IN")
+ .isNotEqualTo(Expression.Operation.IN);
if (predicate.op() == Expression.Operation.NOT_IN) {
Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
@@ -69,24 +69,24 @@ public class TestBucketingProjection {
.map(String::valueOf)
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<?> literal = predicate.literal();
String output = String.valueOf(literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
public void assertProjectionStrictValue(
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.strict(spec).project(filter);
- Assert.assertEquals(projection.op(), expectedOp);
+ assertThat(expectedOp).isEqualTo(projection.op());
}
public void assertProjectionInclusiveValue(
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.inclusive(spec).project(filter);
- Assert.assertEquals(projection.op(), expectedOp);
+ assertThat(expectedOp).isEqualTo(projection.op());
}
public void assertProjectionInclusive(
@@ -97,10 +97,11 @@ public class TestBucketingProjection {
Expression projection = Projections.inclusive(spec).project(filter);
UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(predicate.op(), expectedOp);
+ assertThat(expectedOp).isEqualTo(predicate.op());
- Assert.assertNotEquals(
- "Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());
+ assertThat(predicate.op())
+ .as("Inclusive projection never runs for NOT_IN")
+ .isNotEqualTo(Expression.Operation.NOT_IN);
if (predicate.op() == Expression.Operation.IN) {
Iterable<?> values = Iterables.transform(predicate.literals(), Literal::value);
@@ -110,11 +111,11 @@ public class TestBucketingProjection {
.map(String::valueOf)
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<?> literal = predicate.literal();
String output = String.valueOf(literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestDates.java b/api/src/test/java/org/apache/iceberg/transforms/TestDates.java
index 1df5beeaa7..b9c3802446 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestDates.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestDates.java
@@ -18,11 +18,12 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDates {
@Test
@@ -34,19 +35,21 @@ public class TestDates {
Literal<Integer> nd = Literal.of("1969-12-31").to(type);
Transform<Integer, Integer> years = Transforms.year(type);
- Assert.assertEquals("Should produce 2017 - 1970 = 47", 47, (int) years.apply(date.value()));
- Assert.assertEquals("Should produce 1970 - 1970 = 0", 0, (int) years.apply(pd.value()));
- Assert.assertEquals("Should produce 1969 - 1970 = -1", -1, (int) years.apply(nd.value()));
+ assertThat((int) years.apply(date.value())).as("Should produce 2017 - 1970 = 47").isEqualTo(47);
+ assertThat((int) years.apply(pd.value())).as("Should produce 1970 - 1970 = 0").isZero();
+ assertThat((int) years.apply(nd.value())).as("Should produce 1969 - 1970 = -1").isEqualTo(-1);
Transform<Integer, Integer> months = Transforms.month(type);
- Assert.assertEquals("Should produce 47 * 12 + 11 = 575", 575, (int) months.apply(date.value()));
- Assert.assertEquals("Should produce 0 * 12 + 0 = 0", 0, (int) months.apply(pd.value()));
- Assert.assertEquals("Should produce -1", -1, (int) months.apply(nd.value()));
+ assertThat((int) months.apply(date.value()))
+ .as("Should produce 47 * 12 + 11 = 575")
+ .isEqualTo(575);
+ assertThat((int) months.apply(pd.value())).as("Should produce 0 * 12 + 0 = 0").isZero();
+ assertThat((int) months.apply(nd.value())).isEqualTo(-1);
Transform<Integer, Integer> days = Transforms.day(type);
- Assert.assertEquals("Should produce 17501", 17501, (int) days.apply(date.value()));
- Assert.assertEquals("Should produce 0 * 365 + 0 = 0", 0, (int) days.apply(pd.value()));
- Assert.assertEquals("Should produce -1", -1, (int) days.apply(nd.value()));
+ assertThat((int) days.apply(date.value())).isEqualTo(17501);
+ assertThat((int) days.apply(pd.value())).as("Should produce 0 * 365 + 0 = 0").isZero();
+ assertThat((int) days.apply(nd.value())).isEqualTo(-1);
}
@Test
@@ -57,25 +60,32 @@ public class TestDates {
Literal<Integer> nd = Literal.of("1969-12-31").to(type);
Transform<Integer, Integer> years = Transforms.year();
- Assert.assertEquals(
- "Should produce 2017 - 1970 = 47", 47, (int) years.bind(type).apply(date.value()));
- Assert.assertEquals(
- "Should produce 1970 - 1970 = 0", 0, (int) years.bind(type).apply(pd.value()));
- Assert.assertEquals(
- "Should produce 1969 - 1970 = -1", -1, (int) years.bind(type).apply(nd.value()));
+ assertThat((int) years.bind(type).apply(date.value()))
+ .as("Should produce 2017 - 1970 = 47")
+ .isEqualTo(47);
+ assertThat((int) years.bind(type).apply(pd.value()))
+ .as("Should produce 1970 - 1970 = 0")
+ .isZero();
+ assertThat((int) years.bind(type).apply(nd.value()))
+ .as("Should produce 1969 - 1970 = -1")
+ .isEqualTo(-1);
Transform<Integer, Integer> months = Transforms.month();
- Assert.assertEquals(
- "Should produce 47 * 12 + 11 = 575", 575, (int) months.bind(type).apply(date.value()));
- Assert.assertEquals(
- "Should produce 0 * 12 + 0 = 0", 0, (int) months.bind(type).apply(pd.value()));
- Assert.assertEquals("Should produce -1", -1, (int) months.bind(type).apply(nd.value()));
+ assertThat((int) months.bind(type).apply(date.value()))
+ .as("Should produce 47 * 12 + 11 = 575")
+ .isEqualTo(575);
+ assertThat((int) months.bind(type).apply(pd.value()))
+ .as("Should produce 0 * 12 + 0 = 0")
+ .isZero();
+ assertThat((int) months.bind(type).apply(nd.value())).isEqualTo(-1);
Transform<Integer, Integer> days = Transforms.day();
- Assert.assertEquals("Should produce 17501", 17501, (int) days.bind(type).apply(date.value()));
- Assert.assertEquals(
- "Should produce 0 * 365 + 0 = 0", 0, (int) days.bind(type).apply(pd.value()));
- Assert.assertEquals("Should produce -1", -1, (int) days.bind(type).apply(nd.value()));
+ assertThat((int) days.bind(type).apply(date.value())).isEqualTo(17501);
+
+ assertThat((int) days.bind(type).apply(pd.value()))
+ .as("Should produce 0 * 365 + 0 = 0")
+ .isZero();
+ assertThat((int) days.bind(type).apply(nd.value())).isEqualTo(-1);
}
@Test
@@ -84,22 +94,14 @@ public class TestDates {
Literal<Integer> date = Literal.of("2017-12-01").to(type);
Transform<Integer, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("2017");
Transform<Integer, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("2017-12");
Transform<Integer, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12-01",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("2017-12-01");
}
@Test
@@ -108,22 +110,14 @@ public class TestDates {
Literal<Integer> date = Literal.of("1969-12-30").to(type);
Transform<Integer, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Integer, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-12");
Transform<Integer, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-30",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-12-30");
}
@Test
@@ -132,22 +126,14 @@ public class TestDates {
Literal<Integer> date = Literal.of("1970-01-01").to(type);
Transform<Integer, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1970",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1970");
Transform<Integer, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1970-01",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1970-01");
Transform<Integer, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1970-01-01",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1970-01-01");
}
@Test
@@ -156,22 +142,14 @@ public class TestDates {
Literal<Integer> date = Literal.of("1969-01-01").to(type);
Transform<Integer, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Integer, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-01",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-01");
Transform<Integer, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-01-01",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-01-01");
}
@Test
@@ -180,33 +158,28 @@ public class TestDates {
Literal<Integer> date = Literal.of("1969-12-31").to(type);
Transform<Integer, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Integer, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-12");
Transform<Integer, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-31",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-12-31");
}
@Test
public void testNullHumanString() {
Types.DateType type = Types.DateType.get();
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.year().toHumanString(type, null));
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.month().toHumanString(type, null));
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.day().toHumanString(type, null));
+ assertThat(Transforms.year().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
+ assertThat(Transforms.month().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
+ assertThat(Transforms.day().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
}
@Test
@@ -215,14 +188,14 @@ public class TestDates {
Transform<Integer, Integer> year = Transforms.year();
Type yearResultType = year.getResultType(type);
- Assert.assertEquals(Types.IntegerType.get(), yearResultType);
+ assertThat(yearResultType).isEqualTo(Types.IntegerType.get());
Transform<Integer, Integer> month = Transforms.month();
Type monthResultType = month.getResultType(type);
- Assert.assertEquals(Types.IntegerType.get(), monthResultType);
+ assertThat(monthResultType).isEqualTo(Types.IntegerType.get());
Transform<Integer, Integer> day = Transforms.day();
Type dayResultType = day.getResultType(type);
- Assert.assertEquals(Types.DateType.get(), dayResultType);
+ assertThat(dayResultType).isEqualTo(Types.DateType.get());
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestDatesProjection.java b/api/src/test/java/org/apache/iceberg/transforms/TestDatesProjection.java
index 5106be0ca6..e07e89ba28 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestDatesProjection.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestDatesProjection.java
@@ -28,6 +28,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThanOrEqual;
import static org.apache.iceberg.expressions.Expressions.notEqual;
import static org.apache.iceberg.expressions.Expressions.notIn;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Collectors;
import org.apache.iceberg.PartitionSpec;
@@ -40,8 +41,7 @@ import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestDatesProjection {
private static final Types.DateType TYPE = Types.DateType.get();
@@ -57,10 +57,10 @@ public class TestDatesProjection {
Expression projection = Projections.strict(spec).project(filter);
UnboundPredicate<Integer> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Strict projection never runs for IN", Expression.Operation.IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Strict projection never runs for IN")
+ .isNotEqualTo(Expression.Operation.IN);
Transform<?, Integer> transform =
(Transform<?, Integer>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -73,11 +73,11 @@ public class TestDatesProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<Integer> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
@@ -85,14 +85,14 @@ public class TestDatesProjection {
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.strict(spec).project(filter);
- Assert.assertEquals(expectedOp, projection.op());
+ assertThat(projection.op()).isEqualTo(expectedOp);
}
public void assertProjectionInclusiveValue(
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.inclusive(spec).project(filter);
- Assert.assertEquals(expectedOp, projection.op());
+ assertThat(projection.op()).isEqualTo(expectedOp);
}
@SuppressWarnings("unchecked")
@@ -104,10 +104,10 @@ public class TestDatesProjection {
Expression projection = Projections.inclusive(spec).project(filter);
UnboundPredicate<Integer> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Inclusive projection never runs for NOT_IN")
+ .isNotEqualTo(Expression.Operation.NOT_IN);
Transform<?, Integer> transform =
(Transform<?, Integer>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -120,11 +120,11 @@ public class TestDatesProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<Integer> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestIdentity.java b/api/src/test/java/org/apache/iceberg/transforms/TestIdentity.java
index 3925a67a19..6101fdf098 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestIdentity.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestIdentity.java
@@ -18,12 +18,13 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestIdentity {
@Test
@@ -31,8 +32,9 @@ public class TestIdentity {
Types.LongType longType = Types.LongType.get();
Transform<Long, Long> identity = Transforms.identity();
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", identity.toHumanString(longType, null));
+ assertThat(identity.toHumanString(longType, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
}
@Test
@@ -40,10 +42,9 @@ public class TestIdentity {
Types.BinaryType binary = Types.BinaryType.get();
Transform<ByteBuffer, ByteBuffer> identity = Transforms.identity();
- Assert.assertEquals(
- "Should base64-encode binary",
- "AQID",
- identity.toHumanString(binary, ByteBuffer.wrap(new byte[] {1, 2, 3})));
+ assertThat(identity.toHumanString(binary, ByteBuffer.wrap(new byte[] {1, 2, 3})))
+ .as("Should base64-encode binary")
+ .isEqualTo("AQID");
}
@Test
@@ -51,10 +52,9 @@ public class TestIdentity {
Types.FixedType fixed3 = Types.FixedType.ofLength(3);
Transform<byte[], byte[]> identity = Transforms.identity();
- Assert.assertEquals(
- "Should base64-encode binary",
- "AQID",
- identity.toHumanString(fixed3, new byte[] {1, 2, 3}));
+ assertThat(identity.toHumanString(fixed3, new byte[] {1, 2, 3}))
+ .as("Should base64-encode binary")
+ .isEqualTo("AQID");
}
@Test
@@ -65,8 +65,9 @@ public class TestIdentity {
String dateString = "2017-12-01";
Literal<Integer> dateLit = Literal.of(dateString).to(date);
- Assert.assertEquals(
- "Should produce identical date", dateString, identity.toHumanString(date, dateLit.value()));
+ assertThat(identity.toHumanString(date, dateLit.value()))
+ .as("Should produce identical date")
+ .isEqualTo(dateString);
}
@Test
@@ -77,8 +78,9 @@ public class TestIdentity {
String dateString = "2017-12-01";
Literal<Integer> dateLit = Literal.of(dateString).to(date);
- Assert.assertEquals(
- "Should produce identical date", dateString, identity.toHumanString(dateLit.value()));
+ assertThat(identity.toHumanString(dateLit.value()))
+ .as("Should produce identical date")
+ .isEqualTo(dateString);
}
@Test
@@ -89,8 +91,9 @@ public class TestIdentity {
String timeString = "10:12:55.038194";
Literal<Long> timeLit = Literal.of(timeString).to(time);
- Assert.assertEquals(
- "Should produce identical time", timeString, identity.toHumanString(time, timeLit.value()));
+ assertThat(identity.toHumanString(time, timeLit.value()))
+ .as("Should produce identical time")
+ .isEqualTo(timeString);
}
@Test
@@ -101,10 +104,9 @@ public class TestIdentity {
Literal<Long> ts = Literal.of("2017-12-01T10:12:55.038194-08:00").to(timestamptz);
// value will always be in UTC
- Assert.assertEquals(
- "Should produce timestamp with time zone adjusted to UTC",
- "2017-12-01T18:12:55.038194Z",
- identity.toHumanString(timestamptz, ts.value()));
+ assertThat(identity.toHumanString(timestamptz, ts.value()))
+ .as("Should produce timestamp with time zone adjusted to UTC")
+ .isEqualTo("2017-12-01T18:12:55.038194Z");
}
@Test
@@ -116,10 +118,9 @@ public class TestIdentity {
Literal<Long> ts = Literal.of(tsString).to(timestamp);
// value is not changed
- Assert.assertEquals(
- "Should produce identical timestamp without time zone",
- tsString,
- identity.toHumanString(timestamp, ts.value()));
+ assertThat(identity.toHumanString(timestamp, ts.value()))
+ .as("Should produce identical timestamp without time zone")
+ .isEqualTo(tsString);
}
@Test
@@ -127,10 +128,9 @@ public class TestIdentity {
Types.LongType longType = Types.LongType.get();
Transform<Long, Long> identity = Transforms.identity();
- Assert.assertEquals(
- "Should use Long toString",
- "-1234567890000",
- identity.toHumanString(longType, -1234567890000L));
+ assertThat(identity.toHumanString(longType, -1234567890000L))
+ .as("Should use Long toString")
+ .isEqualTo("-1234567890000");
}
@Test
@@ -139,8 +139,9 @@ public class TestIdentity {
Transform<String, String> identity = Transforms.identity();
String withSlash = "a/b/c=d";
- Assert.assertEquals(
- "Should not modify Strings", withSlash, identity.toHumanString(string, withSlash));
+ assertThat(identity.toHumanString(string, withSlash))
+ .as("Should not modify Strings")
+ .isEqualTo(withSlash);
}
@Test
@@ -150,7 +151,8 @@ public class TestIdentity {
String decimalString = "-1.50";
BigDecimal bigDecimal = new BigDecimal(decimalString);
- Assert.assertEquals(
- "Should not modify Strings", decimalString, identity.toHumanString(decimal, bigDecimal));
+ assertThat(identity.toHumanString(decimal, bigDecimal))
+ .as("Should not modify Strings")
+ .isEqualTo(decimalString);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestNotStartsWith.java b/api/src/test/java/org/apache/iceberg/transforms/TestNotStartsWith.java
index 88c762797b..be50a6643b 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestNotStartsWith.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestNotStartsWith.java
@@ -22,6 +22,7 @@ import static org.apache.iceberg.TestHelpers.assertAndUnwrapUnbound;
import static org.apache.iceberg.expressions.Expressions.notStartsWith;
import static org.apache.iceberg.types.Conversions.toByteBuffer;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.PartitionSpec;
@@ -42,8 +43,7 @@ import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.types.Types.StringType;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestNotStartsWith {
@@ -79,7 +79,7 @@ public class TestNotStartsWith {
// inclusive projection
// when using notStartsWith.
Expression projection = Projections.inclusive(spec).project(notStartsWith(COLUMN, "ababab"));
- Assert.assertTrue(projection instanceof True);
+ assertThat(projection).isInstanceOf(True.class);
assertProjectionStrict(
spec, notStartsWith(COLUMN, "ab"), "ab", Expression.Operation.NOT_STARTS_WITH);
@@ -101,28 +101,29 @@ public class TestNotStartsWith {
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
- Assert.assertEquals(
- "The projected literal should be truncated to the truncation width",
- projected.literal().value(),
- "ab");
+ assertThat(projected.literal().value())
+ .as("The projected literal should be truncated to the truncation width")
+ .isEqualTo("ab");
- Assert.assertFalse(
- "notStartsWith(abcde, truncate(abcde,2)) => false",
- evaluator.eval(TestHelpers.Row.of("abcde")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("abcde")))
+ .as("notStartsWith(abcde, truncate(abcde,2)) => false")
+ .isFalse();
- Assert.assertFalse(
- "notStartsWith(abcde, truncate(ab, 2)) => false", evaluator.eval(TestHelpers.Row.of("ab")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("ab")))
+ .as("notStartsWith(abcde, truncate(ab, 2)) => false")
+ .isFalse();
- Assert.assertFalse(
- "notStartsWith(abcde, truncate(abcdz, 2)) => false",
- evaluator.eval(TestHelpers.Row.of("abcdz")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("abcdz")))
+ .as("notStartsWith(abcde, truncate(abcdz, 2)) => false")
+ .isFalse();
- Assert.assertTrue(
- "notStartsWith(abcde, truncate(a, 2)) => true", evaluator.eval(TestHelpers.Row.of("a")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("a")))
+ .as("notStartsWith(abcde, truncate(a, 2)) => true")
+ .isTrue();
- Assert.assertTrue(
- "notStartsWith(abcde, truncate(aczcde, 2)) => true",
- evaluator.eval(TestHelpers.Row.of("aczcde")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("aczcde")))
+ .as("notStartsWith(abcde, truncate(aczcde, 2)) => true")
+ .isTrue();
}
@Test
@@ -135,20 +136,22 @@ public class TestNotStartsWith {
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
- Assert.assertEquals(
- "The projected literal should not be truncated as its size is shorter than truncation width",
- projected.literal().value(),
- "ab");
+ assertThat(projected.literal().value())
+ .as(
+ "The projected literal should not be truncated as its size is shorter than truncation width")
+ .isEqualTo("ab");
- Assert.assertFalse(
- "notStartsWith(ab, truncate(abcde, 16)) => false",
- evaluator.eval(TestHelpers.Row.of("abcde")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("abcde")))
+ .as("notStartsWith(ab, truncate(abcde, 16)) => false")
+ .isFalse();
- Assert.assertFalse(
- "notStartsWith(ab, truncate(ab, 16)) => false", evaluator.eval(TestHelpers.Row.of("ab")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("ab")))
+ .as("notStartsWith(ab, truncate(ab, 16)) => false")
+ .isFalse();
- Assert.assertTrue(
- "notStartsWith(ab, truncate(a, 16)) => true", evaluator.eval(TestHelpers.Row.of("a")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("a")))
+ .as("notStartsWith(ab, truncate(a, 16)) => true")
+ .isTrue();
}
@Test
@@ -161,48 +164,50 @@ public class TestNotStartsWith {
UnboundPredicate<String> projected = trunc.projectStrict(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
- Assert.assertEquals(
- "The projected literal should not be truncated as its size is equal to truncation width",
- projected.literal().value(),
- "abcdefg");
+ assertThat(projected.literal().value())
+ .as(
+ "The projected literal should not be truncated as its size is equal to truncation width")
+ .isEqualTo("abcdefg");
- Assert.assertFalse(
- "notStartsWith(abcdefg, truncate(abcdefg, 7)) => false",
- evaluator.eval(TestHelpers.Row.of("abcdefg")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("abcdefg")))
+ .as("notStartsWith(abcdefg, truncate(abcdefg, 7)) => false")
+ .isFalse();
- Assert.assertTrue(
- "notStartsWith(abcdefg, truncate(ab, 2)) => true",
- evaluator.eval(TestHelpers.Row.of("ab")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("ab")))
+ .as("notStartsWith(abcdefg, truncate(ab, 2)) => true")
+ .isTrue();
- Assert.assertTrue(
- "notStartsWith(abcdefg, truncate(a, 16)) => true", evaluator.eval(TestHelpers.Row.of("a")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("a")))
+ .as("notStartsWith(abcdefg, truncate(a, 16)) => true")
+ .isTrue();
}
@Test
public void testStrictMetricsEvaluatorForNotStartsWith() {
boolean shouldRead =
new StrictMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "bbb")).eval(FILE_1);
- Assert.assertFalse(
- "Should not match: strict metrics eval is always false for notStartsWith", shouldRead);
+ assertThat(shouldRead)
+ .as("Should not match: strict metrics eval is always false for notStartsWith")
+ .isFalse();
}
@Test
public void testInclusiveMetricsEvaluatorForNotStartsWith() {
boolean shouldRead =
new InclusiveMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "aaa")).eval(FILE_1);
- Assert.assertTrue("Should match: some columns meet the filter criteria", shouldRead);
+ assertThat(shouldRead).as("Should match: some columns meet the filter criteria").isTrue();
shouldRead = new InclusiveMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "b")).eval(FILE_1);
- Assert.assertFalse("Should not match: no columns match the filter criteria", shouldRead);
+ assertThat(shouldRead).as("Should not match: no columns match the filter criteria").isFalse();
shouldRead = new InclusiveMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "bb")).eval(FILE_1);
- Assert.assertFalse("Should not match: no columns match the filter criteria", shouldRead);
+ assertThat(shouldRead).as("Should not match: no columns match the filter criteria").isFalse();
shouldRead = new InclusiveMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "bbb")).eval(FILE_1);
- Assert.assertFalse("Should not match: no columns match the filter criteria", shouldRead);
+ assertThat(shouldRead).as("Should not match: no columns match the filter criteria").isFalse();
shouldRead = new InclusiveMetricsEvaluator(SCHEMA, notStartsWith(COLUMN, "bbbb")).eval(FILE_1);
- Assert.assertTrue("Should match: some columns match the filter criteria", shouldRead);
+ assertThat(shouldRead).as("Should match: some columns match the filter criteria").isTrue();
}
private void assertProjectionInclusive(
@@ -235,7 +240,7 @@ public class TestNotStartsWith {
(Truncate<CharSequence>) spec.getFieldsBySourceId(1).get(0).transform();
String output = transform.toHumanString(Types.StringType.get(), (String) literal.value());
- Assert.assertEquals(expectedOp, predicate.op());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(predicate.op()).isEqualTo(expectedOp);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestProjection.java b/api/src/test/java/org/apache/iceberg/transforms/TestProjection.java
index 72f8648af2..ccfda895f9 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestProjection.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestProjection.java
@@ -33,6 +33,7 @@ import static org.apache.iceberg.expressions.Expressions.truncate;
import static org.apache.iceberg.expressions.Expressions.year;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.apache.iceberg.PartitionSpec;
@@ -47,8 +48,7 @@ import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestProjection {
private static final Schema SCHEMA = new Schema(optional(16, "id", Types.LongType.get()));
@@ -76,17 +76,16 @@ public class TestProjection {
// check inclusive the bound predicate to ensure the types are correct
BoundPredicate<?> bound = assertAndUnwrap(predicate.bind(spec.schema().asStruct(), true));
- Assert.assertEquals(
- "Field name should match partition struct field", "id", projected.ref().name());
- Assert.assertEquals("Operation should match", bound.op(), projected.op());
+ assertThat(projected.ref().name())
+ .as("Field name should match partition struct field")
+ .isEqualTo("id");
+ assertThat(projected.op()).isEqualTo(bound.op());
if (bound.isLiteralPredicate()) {
- Assert.assertEquals(
- "Literal should be equal",
- bound.asLiteralPredicate().literal().value(),
- projected.literal().value());
+ assertThat(projected.literal().value())
+ .isEqualTo(bound.asLiteralPredicate().literal().value());
} else {
- Assert.assertNull("Literal should be null", projected.literal());
+ assertThat(projected.literal()).isNull();
}
}
}
@@ -114,17 +113,16 @@ public class TestProjection {
// check inclusive the bound predicate to ensure the types are correct
BoundPredicate<?> bound = assertAndUnwrap(predicate.bind(spec.schema().asStruct(), false));
- Assert.assertEquals(
- "Field name should match partition struct field", "id", projected.ref().name());
- Assert.assertEquals("Operation should match", bound.op(), projected.op());
+ assertThat(projected.ref().name())
+ .as("Field name should match partition struct field")
+ .isEqualTo("id");
+ assertThat(projected.op()).isEqualTo(bound.op());
if (bound.isLiteralPredicate()) {
- Assert.assertEquals(
- "Literal should be equal",
- bound.asLiteralPredicate().literal().value(),
- projected.literal().value());
+ assertThat(projected.literal().value())
+ .isEqualTo(bound.asLiteralPredicate().literal().value());
} else {
- Assert.assertNull("Literal should be null", projected.literal());
+ assertThat(projected.literal()).isNull();
}
}
}
@@ -161,17 +159,16 @@ public class TestProjection {
// check inclusive the bound predicate to ensure the types are correct
BoundPredicate<?> bound = assertAndUnwrap(predicate.bind(spec.schema().asStruct(), true));
- Assert.assertEquals(
- "Field name should match partition struct field", "id", projected.ref().name());
- Assert.assertEquals("Operation should match", bound.op(), projected.op());
+ assertThat(projected.ref().name())
+ .as("Field name should match partition struct field")
+ .isEqualTo("id");
+ assertThat(projected.op()).isEqualTo(bound.op());
if (bound.isLiteralPredicate()) {
- Assert.assertEquals(
- "Literal should be equal",
- bound.asLiteralPredicate().literal().value(),
- projected.literal().value());
+ assertThat(projected.literal().value())
+ .isEqualTo(bound.asLiteralPredicate().literal().value());
} else {
- Assert.assertNull("Literal should be null", projected.literal());
+ assertThat(projected.literal()).isNull();
}
}
}
@@ -199,17 +196,16 @@ public class TestProjection {
// check inclusive the bound predicate to ensure the types are correct
BoundPredicate<?> bound = assertAndUnwrap(predicate.bind(spec.schema().asStruct(), false));
- Assert.assertEquals(
- "Field name should match partition struct field", "id", projected.ref().name());
- Assert.assertEquals("Operation should match", bound.op(), projected.op());
+ assertThat(projected.ref().name())
+ .as("Field name should match partition struct field")
+ .isEqualTo("id");
+ assertThat(projected.op()).isEqualTo(bound.op());
if (bound.isLiteralPredicate()) {
- Assert.assertEquals(
- "Literal should be equal",
- bound.asLiteralPredicate().literal().value(),
- projected.literal().value());
+ assertThat(projected.literal().value())
+ .isEqualTo(bound.asLiteralPredicate().literal().value());
} else {
- Assert.assertNull("Literal should be null", projected.literal());
+ assertThat(projected.literal()).isNull();
}
}
}
@@ -255,16 +251,16 @@ public class TestProjection {
Assertions.assertThat(projection).isInstanceOf(Or.class);
Or or1 = (Or) projection;
UnboundPredicate<?> dateint1 = assertAndUnwrapUnbound(or1.left());
- Assert.assertEquals("Should be a dateint predicate", "dateint", dateint1.ref().name());
- Assert.assertEquals("Should be dateint=20180416", 20180416, dateint1.literal().value());
+ assertThat(dateint1.ref().name()).as("Should be a dateint predicate").isEqualTo("dateint");
+ assertThat(dateint1.literal().value()).as("Should be dateint=20180416").isEqualTo(20180416);
Assertions.assertThat(or1.right()).isInstanceOf(Or.class);
Or or2 = (Or) or1.right();
UnboundPredicate<?> dateint2 = assertAndUnwrapUnbound(or2.left());
- Assert.assertEquals("Should be a dateint predicate", "dateint", dateint2.ref().name());
- Assert.assertEquals("Should be dateint=20180415", 20180415, dateint2.literal().value());
+ assertThat(dateint2.ref().name()).as("Should be a dateint predicate").isEqualTo("dateint");
+ assertThat(dateint2.literal().value()).as("Should be dateint=20180415").isEqualTo(20180415);
UnboundPredicate<?> dateint3 = assertAndUnwrapUnbound(or2.right());
- Assert.assertEquals("Should be a dateint predicate", "dateint", dateint3.ref().name());
- Assert.assertEquals("Should be dateint=20180417", 20180417, dateint3.literal().value());
+ assertThat(dateint3.ref().name()).as("Should be a dateint predicate").isEqualTo("dateint");
+ assertThat(dateint3.literal().value()).as("Should be dateint=20180417").isEqualTo(20180417);
}
@Test
@@ -299,88 +295,82 @@ public class TestProjection {
UnboundPredicate<Integer> predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(hour("timestamp1"), 20));
- Assert.assertEquals(
- "should expected timestamp1_hour", "timestamp1_hour", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp1_hour");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(hour("timestamp1"), 20));
- Assert.assertEquals(
- "should expected timestamp1_hour", "timestamp1_hour", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp1_hour");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(day("timestamp2"), 20));
- Assert.assertEquals("should expected timestamp2_day", "timestamp2_day", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp2_day");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(day("timestamp2"), 20));
- Assert.assertEquals("should expected timestamp2_day", "timestamp2_day", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp2_day");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(month("timestamp3"), 20));
- Assert.assertEquals(
- "should expected timestamp3_month", "timestamp3_month", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp3_month");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(month("timestamp3"), 20));
- Assert.assertEquals(
- "should expected timestamp3_month", "timestamp3_month", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp3_month");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(year("timestamp4"), 20));
- Assert.assertEquals(
- "should expected timestamp4_year", "timestamp4_year", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp4_year");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(year("timestamp4"), 20));
- Assert.assertEquals(
- "should expected timestamp4_year", "timestamp4_year", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("timestamp4_year");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(day("date1"), 20));
- Assert.assertEquals("should expected date1_day", "date1_day", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date1_day");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(day("date1"), 20));
- Assert.assertEquals("should expected date1_day", "date1_day", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date1_day");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(month("date2"), 20));
- Assert.assertEquals("should expected date2_month", "date2_month", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date2_month");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(month("date2"), 20));
- Assert.assertEquals("should expected date2_month", "date2_month", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date2_month");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(year("date3"), 20));
- Assert.assertEquals("should expected date3_year", "date3_year", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date3_year");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(year("date3"), 20));
- Assert.assertEquals("should expected date3_year", "date3_year", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("date3_year");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(bucket("long", 10), 20));
- Assert.assertEquals("should expected long_bucket", "long_bucket", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("long_bucket");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(bucket("long", 10), 20));
- Assert.assertEquals("should expected long_bucket", "long_bucket", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("long_bucket");
predicate =
(UnboundPredicate<Integer>)
Projections.strict(partitionSpec).project(equal(truncate("string", 10), "abc"));
- Assert.assertEquals("should expected string_trunc", "string_trunc", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("string_trunc");
predicate =
(UnboundPredicate<Integer>)
Projections.inclusive(partitionSpec).project(equal(truncate("string", 10), "abc"));
- Assert.assertEquals("should expected string_trunc", "string_trunc", predicate.ref().name());
+ assertThat(predicate.ref().name()).isEqualTo("string_trunc");
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestResiduals.java b/api/src/test/java/org/apache/iceberg/transforms/TestResiduals.java
index c2bb855cfd..fa3436e570 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestResiduals.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestResiduals.java
@@ -32,6 +32,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThan;
import static org.apache.iceberg.expressions.Expressions.notIn;
import static org.apache.iceberg.expressions.Expressions.notNaN;
import static org.apache.iceberg.expressions.Expressions.or;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.function.Function;
import org.apache.iceberg.PartitionSpec;
@@ -45,8 +46,7 @@ import org.apache.iceberg.expressions.ResidualEvaluator;
import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestResiduals {
@Test
@@ -71,24 +71,24 @@ public class TestResiduals {
// equal to the upper date bound
Expression residual = resEval.residualFor(Row.of(20170815));
UnboundPredicate<?> unbound = assertAndUnwrapUnbound(residual);
- Assert.assertEquals("Residual should be hour < 12", LT, unbound.op());
- Assert.assertEquals("Residual should be hour < 12", "hour", unbound.ref().name());
- Assert.assertEquals("Residual should be hour < 12", 12, unbound.literal().value());
+ assertThat(unbound.op()).as("Residual should be hour < 12").isEqualTo(LT);
+ assertThat(unbound.ref().name()).as("Residual should be hour < 12").isEqualTo("hour");
+ assertThat(unbound.literal().value()).as("Residual should be hour < 12").isEqualTo(12);
// equal to the lower date bound
residual = resEval.residualFor(Row.of(20170801));
unbound = assertAndUnwrapUnbound(residual);
- Assert.assertEquals("Residual should be hour > 11", GT, unbound.op());
- Assert.assertEquals("Residual should be hour > 11", "hour", unbound.ref().name());
- Assert.assertEquals("Residual should be hour > 11", 11, unbound.literal().value());
+ assertThat(unbound.op()).as("Residual should be hour > 11").isEqualTo(GT);
+ assertThat(unbound.ref().name()).as("Residual should be hour > 11").isEqualTo("hour");
+ assertThat(unbound.literal().value()).as("Residual should be hour > 11").isEqualTo(11);
// inside the date range
residual = resEval.residualFor(Row.of(20170812));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
// outside the date range
residual = resEval.residualFor(Row.of(20170817));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -113,24 +113,24 @@ public class TestResiduals {
// equal to the upper date bound
Expression residual = resEval.residualFor(Row.of(20170815));
UnboundPredicate<?> unbound = assertAndUnwrapUnbound(residual);
- Assert.assertEquals("Residual should be hour < 12", LT, unbound.op());
- Assert.assertEquals("Residual should be hour < 12", "HOUR", unbound.ref().name());
- Assert.assertEquals("Residual should be hour < 12", 12, unbound.literal().value());
+ assertThat(unbound.op()).as("Residual should be hour < 12").isEqualTo(LT);
+ assertThat(unbound.ref().name()).as("Residual should be hour < 12").isEqualTo("HOUR");
+ assertThat(unbound.literal().value()).as("Residual should be hour < 12").isEqualTo(12);
// equal to the lower date bound
residual = resEval.residualFor(Row.of(20170801));
unbound = assertAndUnwrapUnbound(residual);
- Assert.assertEquals("Residual should be hour > 11", GT, unbound.op());
- Assert.assertEquals("Residual should be hour > 11", "hOUr", unbound.ref().name());
- Assert.assertEquals("Residual should be hour > 11", 11, unbound.literal().value());
+ assertThat(unbound.op()).as("Residual should be hour > 11").isEqualTo(GT);
+ assertThat(unbound.ref().name()).as("Residual should be hour > 11").isEqualTo("hOUr");
+ assertThat(unbound.literal().value()).as("Residual should be hour > 11").isEqualTo(11);
// inside the date range
residual = resEval.residualFor(Row.of(20170812));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
// outside the date range
residual = resEval.residualFor(Row.of(20170817));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -170,8 +170,9 @@ public class TestResiduals {
for (Expression expr : expressions) {
ResidualEvaluator residualEvaluator =
ResidualEvaluator.of(PartitionSpec.unpartitioned(), expr, true);
- Assert.assertEquals(
- "Should return expression", expr, residualEvaluator.residualFor(Row.of()));
+ assertThat(residualEvaluator.residualFor(Row.of()))
+ .as("Should return expression")
+ .isEqualTo(expr);
}
}
@@ -188,10 +189,10 @@ public class TestResiduals {
ResidualEvaluator.of(spec, in("dateint", 20170815, 20170816, 20170817), true);
Expression residual = resEval.residualFor(Row.of(20170815));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
residual = resEval.residualFor(Row.of(20180815));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -217,10 +218,10 @@ public class TestResiduals {
ResidualEvaluator resEval = ResidualEvaluator.of(spec, pred, true);
Expression residual = resEval.residualFor(Row.of(tsDay));
- Assert.assertEquals("Residual should be the original in predicate", pred, residual);
+ assertThat(residual).as("Residual should be the original in predicate").isEqualTo(pred);
residual = resEval.residualFor(Row.of(tsDay + 3));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -236,10 +237,10 @@ public class TestResiduals {
ResidualEvaluator.of(spec, notIn("dateint", 20170815, 20170816, 20170817), true);
Expression residual = resEval.residualFor(Row.of(20180815));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
residual = resEval.residualFor(Row.of(20170815));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -255,10 +256,10 @@ public class TestResiduals {
ResidualEvaluator resEval = ResidualEvaluator.of(spec, isNaN("double"), true);
Expression residual = resEval.residualFor(Row.of(Double.NaN));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
residual = resEval.residualFor(Row.of(2D));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
// test float field
spec = PartitionSpec.builderFor(schema).identity("float").build();
@@ -266,10 +267,10 @@ public class TestResiduals {
resEval = ResidualEvaluator.of(spec, isNaN("float"), true);
residual = resEval.residualFor(Row.of(Float.NaN));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
residual = resEval.residualFor(Row.of(3F));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
}
@Test
@@ -285,10 +286,10 @@ public class TestResiduals {
ResidualEvaluator resEval = ResidualEvaluator.of(spec, notNaN("double"), true);
Expression residual = resEval.residualFor(Row.of(Double.NaN));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
residual = resEval.residualFor(Row.of(2D));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
// test float field
spec = PartitionSpec.builderFor(schema).identity("float").build();
@@ -296,10 +297,10 @@ public class TestResiduals {
resEval = ResidualEvaluator.of(spec, notNaN("float"), true);
residual = resEval.residualFor(Row.of(Float.NaN));
- Assert.assertEquals("Residual should be alwaysFalse", alwaysFalse(), residual);
+ assertThat(residual).isEqualTo(alwaysFalse());
residual = resEval.residualFor(Row.of(3F));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
}
@Test
@@ -325,9 +326,9 @@ public class TestResiduals {
ResidualEvaluator resEval = ResidualEvaluator.of(spec, pred, true);
Expression residual = resEval.residualFor(Row.of(tsDay));
- Assert.assertEquals("Residual should be the original notIn predicate", pred, residual);
+ assertThat(residual).as("Residual should be the original notIn predicate").isEqualTo(pred);
residual = resEval.residualFor(Row.of(tsDay + 3));
- Assert.assertEquals("Residual should be alwaysTrue", alwaysTrue(), residual);
+ assertThat(residual).isEqualTo(alwaysTrue());
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestStartsWith.java b/api/src/test/java/org/apache/iceberg/transforms/TestStartsWith.java
index 8ceeb91952..d8aa59e7fe 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestStartsWith.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestStartsWith.java
@@ -21,6 +21,7 @@ package org.apache.iceberg.transforms;
import static org.apache.iceberg.TestHelpers.assertAndUnwrapUnbound;
import static org.apache.iceberg.expressions.Expressions.startsWith;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
@@ -35,8 +36,7 @@ import org.apache.iceberg.expressions.Projections;
import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestStartsWith {
@@ -71,9 +71,9 @@ public class TestStartsWith {
UnboundPredicate<String> projected = trunc.project(COLUMN, boundExpr);
Evaluator evaluator = new Evaluator(SCHEMA.asStruct(), projected);
- Assert.assertTrue(
- "startsWith(abcde, truncate(abcdg,2)) => true",
- evaluator.eval(TestHelpers.Row.of("abcdg")));
+ assertThat(evaluator.eval(TestHelpers.Row.of("abcdg")))
+ .as("startsWith(abcde, truncate(abcdg,2)) => true")
+ .isTrue();
}
private void assertProjectionInclusive(
@@ -106,7 +106,7 @@ public class TestStartsWith {
(Truncate<CharSequence>) spec.getFieldsBySourceId(1).get(0).transform();
String output = transform.toHumanString(Types.StringType.get(), (String) literal.value());
- Assert.assertEquals(expectedOp, predicate.op());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(predicate.op()).isEqualTo(expectedOp);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTimestamps.java b/api/src/test/java/org/apache/iceberg/transforms/TestTimestamps.java
index aefa98ed26..3c37e643eb 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTimestamps.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTimestamps.java
@@ -18,11 +18,12 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTimestamps {
@Test
@@ -34,24 +35,28 @@ public class TestTimestamps {
Literal<Long> nts = Literal.of("1969-12-31T23:59:58.999999").to(type);
Transform<Long, Integer> years = Transforms.year(type);
- Assert.assertEquals("Should produce 2017 - 1970 = 47", 47, (int) years.apply(ts.value()));
- Assert.assertEquals("Should produce 1970 - 1970 = 0", 0, (int) years.apply(pts.value()));
- Assert.assertEquals("Should produce 1969 - 1970 = -1", -1, (int) years.apply(nts.value()));
+ assertThat((int) years.apply(ts.value())).as("Should produce 2017 - 1970 = 47").isEqualTo(47);
+ assertThat((int) years.apply(pts.value())).as("Should produce 1970 - 1970 = 0").isZero();
+ assertThat((int) years.apply(nts.value())).as("Should produce 1969 - 1970 = -1").isEqualTo(-1);
Transform<Long, Integer> months = Transforms.month(type);
- Assert.assertEquals("Should produce 47 * 12 + 11 = 575", 575, (int) months.apply(ts.value()));
- Assert.assertEquals("Should produce 0 * 12 + 0 = 0", 0, (int) months.apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) months.apply(nts.value()));
+ assertThat((int) months.apply(ts.value()))
+ .as("Should produce 47 * 12 + 11 = 575")
+ .isEqualTo(575);
+ assertThat((int) months.apply(pts.value())).as("Should produce 0 * 12 + 0 = 0").isZero();
+ assertThat((int) months.apply(nts.value())).isEqualTo(-1);
Transform<Long, Integer> days = Transforms.day(type);
- Assert.assertEquals("Should produce 17501", 17501, (int) days.apply(ts.value()));
- Assert.assertEquals("Should produce 0 * 365 + 0 = 0", 0, (int) days.apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) days.apply(nts.value()));
+ assertThat((int) days.apply(ts.value())).as("Should produce 17501").isEqualTo(17501);
+ assertThat((int) days.apply(pts.value())).as("Should produce 0 * 365 + 0 = 0").isZero();
+ assertThat((int) days.apply(nts.value())).isEqualTo(-1);
Transform<Long, Integer> hours = Transforms.hour(type);
- Assert.assertEquals("Should produce 17501 * 24 + 10", 420034, (int) hours.apply(ts.value()));
- Assert.assertEquals("Should produce 0 * 24 + 0 = 0", 0, (int) hours.apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) hours.apply(nts.value()));
+ assertThat((int) hours.apply(ts.value()))
+ .as("Should produce 17501 * 24 + 10")
+ .isEqualTo(420034);
+ assertThat((int) hours.apply(pts.value())).as("Should produce 0 * 24 + 0 = 0").isZero();
+ assertThat((int) hours.apply(nts.value())).isEqualTo(-1);
}
@Test
@@ -62,32 +67,40 @@ public class TestTimestamps {
Literal<Long> nts = Literal.of("1969-12-31T23:59:58.999999").to(type);
Transform<Long, Integer> years = Transforms.year();
- Assert.assertEquals(
- "Should produce 2017 - 1970 = 47", 47, (int) years.bind(type).apply(ts.value()));
- Assert.assertEquals(
- "Should produce 1970 - 1970 = 0", 0, (int) years.bind(type).apply(pts.value()));
- Assert.assertEquals(
- "Should produce 1969 - 1970 = -1", -1, (int) years.bind(type).apply(nts.value()));
+ assertThat((int) years.bind(type).apply(ts.value()))
+ .as("Should produce 2017 - 1970 = 47")
+ .isEqualTo(47);
+ assertThat((int) years.bind(type).apply(pts.value()))
+ .as("Should produce 1970 - 1970 = 0")
+ .isZero();
+ assertThat((int) years.bind(type).apply(nts.value()))
+ .as("Should produce 1969 - 1970 = -1")
+ .isEqualTo(-1);
Transform<Long, Integer> months = Transforms.month();
- Assert.assertEquals(
- "Should produce 47 * 12 + 11 = 575", 575, (int) months.bind(type).apply(ts.value()));
- Assert.assertEquals(
- "Should produce 0 * 12 + 0 = 0", 0, (int) months.bind(type).apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) months.bind(type).apply(nts.value()));
+ assertThat((int) months.bind(type).apply(ts.value()))
+ .as("Should produce 47 * 12 + 11 = 575")
+ .isEqualTo(575);
+ assertThat((int) months.bind(type).apply(pts.value()))
+ .as("Should produce 0 * 12 + 0 = 0")
+ .isZero();
+ assertThat((int) months.bind(type).apply(nts.value())).isEqualTo(-1);
Transform<Long, Integer> days = Transforms.day();
- Assert.assertEquals("Should produce 17501", 17501, (int) days.bind(type).apply(ts.value()));
- Assert.assertEquals(
- "Should produce 0 * 365 + 0 = 0", 0, (int) days.bind(type).apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) days.bind(type).apply(nts.value()));
+ assertThat((int) days.bind(type).apply(ts.value())).as("Should produce 17501").isEqualTo(17501);
+ assertThat((int) days.bind(type).apply(pts.value()))
+ .as("Should produce 0 * 365 + 0 = 0")
+ .isZero();
+ assertThat((int) days.bind(type).apply(nts.value())).isEqualTo(-1);
Transform<Long, Integer> hours = Transforms.hour();
- Assert.assertEquals(
- "Should produce 17501 * 24 + 10", 420034, (int) hours.bind(type).apply(ts.value()));
- Assert.assertEquals(
- "Should produce 0 * 24 + 0 = 0", 0, (int) hours.bind(type).apply(pts.value()));
- Assert.assertEquals("Should produce -1", -1, (int) hours.bind(type).apply(nts.value()));
+ assertThat((int) hours.bind(type).apply(ts.value()))
+ .as("Should produce 17501 * 24 + 10")
+ .isEqualTo(420034);
+ assertThat((int) hours.bind(type).apply(pts.value()))
+ .as("Should produce 0 * 24 + 0 = 0")
+ .isZero();
+ assertThat((int) hours.bind(type).apply(nts.value())).isEqualTo(-1);
}
@Test
@@ -96,28 +109,18 @@ public class TestTimestamps {
Literal<Long> date = Literal.of("2017-12-01T10:12:55.038194").to(type);
Transform<Long, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("2017");
Transform<Long, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("2017-12");
Transform<Long, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12-01",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("2017-12-01");
Transform<Long, Integer> hour = Transforms.hour();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12-01-10",
- hour.toHumanString(type, hour.bind(type).apply(date.value())));
+ assertThat(hour.toHumanString(type, hour.bind(type).apply(date.value())))
+ .isEqualTo("2017-12-01-10");
}
@Test
@@ -126,28 +129,18 @@ public class TestTimestamps {
Literal<Long> date = Literal.of("1969-12-30T10:12:55.038194").to(type);
Transform<Long, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Long, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-12");
Transform<Long, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-30",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-12-30");
Transform<Long, Integer> hour = Transforms.hour();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-30-10",
- hour.toHumanString(type, hour.bind(type).apply(date.value())));
+ assertThat(hour.toHumanString(type, hour.bind(type).apply(date.value())))
+ .isEqualTo("1969-12-30-10");
}
@Test
@@ -156,28 +149,18 @@ public class TestTimestamps {
Literal<Long> date = Literal.of("1969-12-30T00:00:00.000000").to(type);
Transform<Long, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Long, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-12");
Transform<Long, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-30",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-12-30");
Transform<Long, Integer> hour = Transforms.hour();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-30-00",
- hour.toHumanString(type, hour.bind(type).apply(date.value())));
+ assertThat(hour.toHumanString(type, hour.bind(type).apply(date.value())))
+ .isEqualTo("1969-12-30-00");
}
@Test
@@ -186,28 +169,18 @@ public class TestTimestamps {
Literal<Long> date = Literal.of("1969-12-31T23:59:59.999999").to(type);
Transform<Long, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("1969");
Transform<Long, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("1969-12");
Transform<Long, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-31",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("1969-12-31");
Transform<Long, Integer> hour = Transforms.hour();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "1969-12-31-23",
- hour.toHumanString(type, hour.bind(type).apply(date.value())));
+ assertThat(hour.toHumanString(type, hour.bind(type).apply(date.value())))
+ .isEqualTo("1969-12-31-23");
}
@Test
@@ -216,42 +189,36 @@ public class TestTimestamps {
Literal<Long> date = Literal.of("2017-12-01T10:12:55.038194-08:00").to(type);
Transform<Long, Integer> year = Transforms.year();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017",
- year.toHumanString(type, year.bind(type).apply(date.value())));
+ assertThat(year.toHumanString(type, year.bind(type).apply(date.value()))).isEqualTo("2017");
Transform<Long, Integer> month = Transforms.month();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12",
- month.toHumanString(type, month.bind(type).apply(date.value())));
+ assertThat(month.toHumanString(type, month.bind(type).apply(date.value())))
+ .isEqualTo("2017-12");
Transform<Long, Integer> day = Transforms.day();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12-01",
- day.toHumanString(type, day.bind(type).apply(date.value())));
+ assertThat(day.toHumanString(type, day.bind(type).apply(date.value()))).isEqualTo("2017-12-01");
// the hour is 18 because the value is always UTC
Transform<Long, Integer> hour = Transforms.hour();
- Assert.assertEquals(
- "Should produce the correct Human string",
- "2017-12-01-18",
- hour.toHumanString(type, hour.bind(type).apply(date.value())));
+ assertThat(hour.toHumanString(type, hour.bind(type).apply(date.value())))
+ .isEqualTo("2017-12-01-18");
}
@Test
public void testNullHumanString() {
Types.TimestampType type = Types.TimestampType.withZone();
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.year().toHumanString(type, null));
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.month().toHumanString(type, null));
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.day().toHumanString(type, null));
- Assert.assertEquals(
- "Should produce \"null\" for null", "null", Transforms.hour().toHumanString(type, null));
+ assertThat(Transforms.year().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
+ assertThat(Transforms.month().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
+ assertThat(Transforms.day().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
+ assertThat(Transforms.hour().toHumanString(type, null))
+ .as("Should produce \"null\" for null")
+ .isEqualTo("null");
}
@Test
@@ -260,18 +227,18 @@ public class TestTimestamps {
Transform<Integer, Integer> year = Transforms.year();
Type yearResultType = year.getResultType(type);
- Assert.assertEquals(Types.IntegerType.get(), yearResultType);
+ assertThat(yearResultType).isEqualTo(Types.IntegerType.get());
Transform<Integer, Integer> month = Transforms.month();
Type monthResultType = month.getResultType(type);
- Assert.assertEquals(Types.IntegerType.get(), monthResultType);
+ assertThat(monthResultType).isEqualTo(Types.IntegerType.get());
Transform<Integer, Integer> day = Transforms.day();
Type dayResultType = day.getResultType(type);
- Assert.assertEquals(Types.DateType.get(), dayResultType);
+ assertThat(dayResultType).isEqualTo(Types.DateType.get());
Transform<Integer, Integer> hour = Transforms.hour();
Type hourResultType = hour.getResultType(type);
- Assert.assertEquals(Types.IntegerType.get(), hourResultType);
+ assertThat(hourResultType).isEqualTo(Types.IntegerType.get());
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTimestampsProjection.java b/api/src/test/java/org/apache/iceberg/transforms/TestTimestampsProjection.java
index 3da034d501..cd20868a06 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTimestampsProjection.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTimestampsProjection.java
@@ -28,6 +28,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThanOrEqual;
import static org.apache.iceberg.expressions.Expressions.notEqual;
import static org.apache.iceberg.expressions.Expressions.notIn;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Collectors;
import org.apache.iceberg.PartitionSpec;
@@ -40,8 +41,7 @@ import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTimestampsProjection {
private static final Types.TimestampType TYPE = Types.TimestampType.withoutZone();
@@ -57,10 +57,10 @@ public class TestTimestampsProjection {
Expression projection = Projections.strict(spec).project(filter);
UnboundPredicate<Integer> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Strict projection never runs for IN", Expression.Operation.IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Strict projection never runs for IN")
+ .isNotEqualTo(Expression.Operation.IN);
Transform<?, Integer> transform =
(Transform<?, Integer>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -73,11 +73,11 @@ public class TestTimestampsProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<Integer> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
@@ -85,14 +85,14 @@ public class TestTimestampsProjection {
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.strict(spec).project(filter);
- Assert.assertEquals(expectedOp, projection.op());
+ assertThat(projection.op()).isEqualTo(expectedOp);
}
public void assertProjectionInclusiveValue(
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.inclusive(spec).project(filter);
- Assert.assertEquals(expectedOp, projection.op());
+ assertThat(projection.op()).isEqualTo(expectedOp);
}
@SuppressWarnings("unchecked")
@@ -104,10 +104,10 @@ public class TestTimestampsProjection {
Expression projection = Projections.inclusive(spec).project(filter);
UnboundPredicate<Integer> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Inclusive projection never runs for NOT_IN")
+ .isNotEqualTo(Expression.Operation.NOT_IN);
Transform<?, Integer> transform =
(Transform<?, Integer>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -120,11 +120,11 @@ public class TestTimestampsProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<Integer> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTransformSerialization.java b/api/src/test/java/org/apache/iceberg/transforms/TestTransformSerialization.java
index 2c04779c67..c2330247fa 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTransformSerialization.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTransformSerialization.java
@@ -18,12 +18,13 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.apache.iceberg.TestHelpers;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.SerializableFunction;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTransformSerialization {
@Test
@@ -59,11 +60,11 @@ public class TestTransformSerialization {
for (Type type : types) {
for (Transform<?, ?> transform : transforms) {
- Assert.assertEquals(transform, TestHelpers.roundTripSerialize(transform));
+ assertThat(TestHelpers.roundTripSerialize(transform)).isEqualTo(transform);
if (transform.canTransform(type)) {
SerializableFunction<?, ?> func = transform.bind(type);
- Assert.assertTrue(func.getClass().isInstance(TestHelpers.roundTripSerialize(func)));
+ assertThat(func).isInstanceOf(TestHelpers.roundTripSerialize(func).getClass());
}
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTruncate.java b/api/src/test/java/org/apache/iceberg/transforms/TestTruncate.java
index 68bc93d563..e9ee6cfde3 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTruncate.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTruncate.java
@@ -18,92 +18,96 @@
*/
package org.apache.iceberg.transforms;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTruncate {
@Test
public void testDeprecatedTruncateInteger() {
Truncate<Object> trunc = Truncate.get(Types.IntegerType.get(), 10);
- Assert.assertEquals(0, (int) trunc.apply(0));
- Assert.assertEquals(0, (int) trunc.apply(1));
- Assert.assertEquals(0, (int) trunc.apply(5));
- Assert.assertEquals(0, (int) trunc.apply(9));
- Assert.assertEquals(10, (int) trunc.apply(10));
- Assert.assertEquals(10, (int) trunc.apply(11));
- Assert.assertEquals(-10, (int) trunc.apply(-1));
- Assert.assertEquals(-10, (int) trunc.apply(-5));
- Assert.assertEquals(-10, (int) trunc.apply(-10));
- Assert.assertEquals(-20, (int) trunc.apply(-11));
+ assertThat((int) trunc.apply(0)).isZero();
+ assertThat((int) trunc.apply(1)).isZero();
+ assertThat((int) trunc.apply(5)).isZero();
+ assertThat((int) trunc.apply(9)).isZero();
+ assertThat((int) trunc.apply(10)).isEqualTo(10);
+ assertThat((int) trunc.apply(11)).isEqualTo(10);
+ assertThat((int) trunc.apply(-1)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-5)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-10)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-11)).isEqualTo(-20);
}
@Test
public void testTruncateInteger() {
Function<Object, Object> trunc = Truncate.get(10).bind(Types.IntegerType.get());
- Assert.assertEquals(0, (int) trunc.apply(0));
- Assert.assertEquals(0, (int) trunc.apply(1));
- Assert.assertEquals(0, (int) trunc.apply(5));
- Assert.assertEquals(0, (int) trunc.apply(9));
- Assert.assertEquals(10, (int) trunc.apply(10));
- Assert.assertEquals(10, (int) trunc.apply(11));
- Assert.assertEquals(-10, (int) trunc.apply(-1));
- Assert.assertEquals(-10, (int) trunc.apply(-5));
- Assert.assertEquals(-10, (int) trunc.apply(-10));
- Assert.assertEquals(-20, (int) trunc.apply(-11));
+ assertThat((int) trunc.apply(0)).isZero();
+ assertThat((int) trunc.apply(1)).isZero();
+ assertThat((int) trunc.apply(5)).isZero();
+ assertThat((int) trunc.apply(9)).isZero();
+ assertThat((int) trunc.apply(10)).isEqualTo(10);
+ assertThat((int) trunc.apply(11)).isEqualTo(10);
+ assertThat((int) trunc.apply(-1)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-5)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-10)).isEqualTo(-10);
+ assertThat((int) trunc.apply(-11)).isEqualTo(-20);
}
@Test
public void testTruncateLong() {
Function<Object, Object> trunc = Truncate.get(10).bind(Types.LongType.get());
- Assert.assertEquals(0L, (long) trunc.apply(0L));
- Assert.assertEquals(0L, (long) trunc.apply(1L));
- Assert.assertEquals(0L, (long) trunc.apply(5L));
- Assert.assertEquals(0L, (long) trunc.apply(9L));
- Assert.assertEquals(10L, (long) trunc.apply(10L));
- Assert.assertEquals(10L, (long) trunc.apply(11L));
- Assert.assertEquals(-10L, (long) trunc.apply(-1L));
- Assert.assertEquals(-10L, (long) trunc.apply(-5L));
- Assert.assertEquals(-10L, (long) trunc.apply(-10L));
- Assert.assertEquals(-20L, (long) trunc.apply(-11L));
+ assertThat((long) trunc.apply(0L)).isZero();
+ assertThat((long) trunc.apply(1L)).isZero();
+ assertThat((long) trunc.apply(5L)).isZero();
+ assertThat((long) trunc.apply(9L)).isZero();
+ assertThat((long) trunc.apply(10L)).isEqualTo(10L);
+ assertThat((long) trunc.apply(11L)).isEqualTo(10L);
+ assertThat((long) trunc.apply(-1L)).isEqualTo(-10L);
+ assertThat((long) trunc.apply(-5L)).isEqualTo(-10L);
+ assertThat((long) trunc.apply(-10L)).isEqualTo(-10L);
+ assertThat((long) trunc.apply(-11L)).isEqualTo(-20L);
}
@Test
public void testTruncateDecimal() {
// decimal truncation works by applying the decimal scale to the width: 10 scale 2 = 0.10
Function<Object, Object> trunc = Truncate.get(10).bind(Types.DecimalType.of(9, 2));
- Assert.assertEquals(new BigDecimal("12.30"), trunc.apply(new BigDecimal("12.34")));
- Assert.assertEquals(new BigDecimal("12.30"), trunc.apply(new BigDecimal("12.30")));
- Assert.assertEquals(new BigDecimal("12.20"), trunc.apply(new BigDecimal("12.29")));
- Assert.assertEquals(new BigDecimal("0.00"), trunc.apply(new BigDecimal("0.05")));
- Assert.assertEquals(new BigDecimal("-0.10"), trunc.apply(new BigDecimal("-0.05")));
+ assertThat(trunc.apply(new BigDecimal("12.34"))).isEqualTo(new BigDecimal("12.30"));
+ assertThat(trunc.apply(new BigDecimal("12.30"))).isEqualTo(new BigDecimal("12.30"));
+ assertThat(trunc.apply(new BigDecimal("12.29"))).isEqualTo(new BigDecimal("12.20"));
+ assertThat(trunc.apply(new BigDecimal("0.05"))).isEqualTo(new BigDecimal("0.00"));
+ assertThat(trunc.apply(new BigDecimal("-0.05"))).isEqualTo(new BigDecimal("-0.10"));
}
@Test
public void testTruncateString() {
Function<Object, Object> trunc = Truncate.get(5).bind(Types.StringType.get());
- Assert.assertEquals(
- "Should truncate strings longer than length", "abcde", trunc.apply("abcdefg"));
- Assert.assertEquals("Should not pad strings shorter than length", "abc", trunc.apply("abc"));
- Assert.assertEquals("Should not alter strings equal to length", "abcde", trunc.apply("abcde"));
+ assertThat(trunc.apply("abcdefg"))
+ .as("Should truncate strings longer than length")
+ .isEqualTo("abcde");
+ assertThat(trunc.apply("abc"))
+ .as("Should not pad strings shorter than length")
+ .isEqualTo("abc");
+ assertThat(trunc.apply("abcde"))
+ .as("Should not alter strings equal to length")
+ .isEqualTo("abcde");
}
@Test
public void testTruncateByteBuffer() {
Function<Object, Object> trunc = Truncate.get(4).bind(Types.BinaryType.get());
- Assert.assertEquals(
- "Should truncate binary longer than length",
- ByteBuffer.wrap("abcd".getBytes(StandardCharsets.UTF_8)),
- trunc.apply(ByteBuffer.wrap("abcdefg".getBytes(StandardCharsets.UTF_8))));
- Assert.assertEquals(
- "Should not pad binary shorter than length",
- ByteBuffer.wrap("abc".getBytes(StandardCharsets.UTF_8)),
- trunc.apply(ByteBuffer.wrap("abc".getBytes(StandardCharsets.UTF_8))));
+ assertThat(trunc.apply(ByteBuffer.wrap("abcdefg".getBytes(StandardCharsets.UTF_8))))
+ .as("Should truncate binary longer than length")
+ .isEqualTo(ByteBuffer.wrap("abcd".getBytes(StandardCharsets.UTF_8)));
+ assertThat(trunc.apply(ByteBuffer.wrap("abc".getBytes(StandardCharsets.UTF_8))))
+ .as("Should not pad binary shorter than length")
+ .isEqualTo(ByteBuffer.wrap("abc".getBytes(StandardCharsets.UTF_8)));
}
@Test
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesProjection.java b/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesProjection.java
index cc0ae0040a..588f6fc3bd 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesProjection.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesProjection.java
@@ -28,6 +28,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThanOrEqual;
import static org.apache.iceberg.expressions.Expressions.notEqual;
import static org.apache.iceberg.expressions.Expressions.notIn;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
@@ -42,8 +43,7 @@ import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTruncatesProjection {
@@ -57,10 +57,10 @@ public class TestTruncatesProjection {
Expression projection = Projections.strict(spec).project(filter);
UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(expectedOp, predicate.op());
-
- Assert.assertNotEquals(
- "Strict projection never runs for IN", Expression.Operation.IN, predicate.op());
+ assertThat(predicate.op())
+ .isEqualTo(expectedOp)
+ .as("Strict projection never runs for IN")
+ .isNotEqualTo(Expression.Operation.IN);
Transform<Object, Object> transform =
(Transform<Object, Object>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -73,11 +73,11 @@ public class TestTruncatesProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<?> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
@@ -85,14 +85,14 @@ public class TestTruncatesProjection {
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.strict(spec).project(filter);
- Assert.assertEquals(projection.op(), expectedOp);
+ assertThat(expectedOp).isEqualTo(projection.op());
}
public void assertProjectionInclusiveValue(
PartitionSpec spec, UnboundPredicate<?> filter, Expression.Operation expectedOp) {
Expression projection = Projections.inclusive(spec).project(filter);
- Assert.assertEquals(projection.op(), expectedOp);
+ assertThat(expectedOp).isEqualTo(projection.op());
}
@SuppressWarnings("unchecked")
@@ -104,10 +104,11 @@ public class TestTruncatesProjection {
Expression projection = Projections.inclusive(spec).project(filter);
UnboundPredicate<?> predicate = assertAndUnwrapUnbound(projection);
- Assert.assertEquals(predicate.op(), expectedOp);
-
- Assert.assertNotEquals(
- "Inclusive projection never runs for NOT_IN", Expression.Operation.NOT_IN, predicate.op());
+ assertThat(predicate.op())
+ .as("Operation should match")
+ .isEqualTo(expectedOp)
+ .as("Inclusive projection never runs for NOT_IN")
+ .isNotEqualTo(Expression.Operation.NOT_IN);
Transform<Object, Object> transform =
(Transform<Object, Object>) spec.getFieldsBySourceId(1).get(0).transform();
@@ -120,11 +121,11 @@ public class TestTruncatesProjection {
.map(v -> transform.toHumanString(type, v))
.collect(Collectors.toList())
.toString();
- Assert.assertEquals(expectedLiteral, actual);
+ assertThat(actual).isEqualTo(expectedLiteral);
} else {
Literal<?> literal = predicate.literal();
String output = transform.toHumanString(type, literal.value());
- Assert.assertEquals(expectedLiteral, output);
+ assertThat(output).isEqualTo(expectedLiteral);
}
}
diff --git a/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesResiduals.java b/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesResiduals.java
index 3234b09f37..f1e04e6d0d 100644
--- a/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesResiduals.java
+++ b/api/src/test/java/org/apache/iceberg/transforms/TestTruncatesResiduals.java
@@ -27,6 +27,7 @@ import static org.apache.iceberg.expressions.Expressions.lessThanOrEqual;
import static org.apache.iceberg.expressions.Expressions.notEqual;
import static org.apache.iceberg.expressions.Expressions.notStartsWith;
import static org.apache.iceberg.expressions.Expressions.startsWith;
+import static org.assertj.core.api.Assertions.assertThat;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
@@ -35,8 +36,7 @@ import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.expressions.ResidualEvaluator;
import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.types.Types;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestTruncatesResiduals {
@@ -58,7 +58,7 @@ public class TestTruncatesResiduals {
ResidualEvaluator resEval = ResidualEvaluator.of(spec, predicate, true);
Expression residual = resEval.residualFor(TestHelpers.Row.of(partitionValue));
- Assert.assertEquals(expectedOp, residual.op());
+ assertThat(residual.op()).isEqualTo(expectedOp);
}
/**
@@ -76,9 +76,9 @@ public class TestTruncatesResiduals {
Expression residual = resEval.residualFor(TestHelpers.Row.of(partitionValue));
UnboundPredicate<?> unbound = assertAndUnwrapUnbound(residual);
- Assert.assertEquals(predicate.op(), unbound.op());
- Assert.assertEquals(predicate.ref().name(), unbound.ref().name());
- Assert.assertEquals(predicate.literal().value(), unbound.literal().value());
+ assertThat(unbound.op()).isEqualTo(predicate.op());
+ assertThat(unbound.ref().name()).isEqualTo(predicate.ref().name());
+ assertThat(unbound.literal().value()).isEqualTo(predicate.literal().value());
}
@Test