diff --git a/hadoop-tools/hadoop-archives/pom.xml b/hadoop-tools/hadoop-archives/pom.xml
index a7fba81805..47c1251046 100644
--- a/hadoop-tools/hadoop-archives/pom.xml
+++ b/hadoop-tools/hadoop-archives/pom.xml
@@ -92,6 +92,11 @@
test-jar
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
index c63bc42266..b1755affa8 100644
--- a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
+++ b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java
@@ -49,6 +49,7 @@
import org.junit.Assert;
import static org.junit.Assert.*;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;
@@ -400,7 +401,7 @@ public void testReadFileContent() throws Exception {
readFileCount++;
}
}
- assertEquals(fileList.size(), readFileCount);
+ assertThat(fileList.size()).isEqualTo(readFileCount);
} finally {
harFileSystem.close();
}
diff --git a/hadoop-tools/hadoop-distcp/pom.xml b/hadoop-tools/hadoop-distcp/pom.xml
index 019ae36660..fe1681b48e 100644
--- a/hadoop-tools/hadoop-distcp/pom.xml
+++ b/hadoop-tools/hadoop-distcp/pom.xml
@@ -103,6 +103,11 @@
mockito-core
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestCopyListing.java b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestCopyListing.java
index ed7650f965..ce7d00d2bd 100644
--- a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestCopyListing.java
+++ b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestCopyListing.java
@@ -38,6 +38,7 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.AfterClass;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -205,8 +206,8 @@ public void testBuildListing() {
Assert.fail("Duplicates not detected");
} catch (DuplicateFileException ignore) {
}
- Assert.assertEquals(listing.getBytesToCopy(), 10);
- Assert.assertEquals(listing.getNumberOfPaths(), 3);
+ assertThat(listing.getBytesToCopy()).isEqualTo(10);
+ assertThat(listing.getNumberOfPaths()).isEqualTo(3);
TestDistCpUtils.delete(fs, "/tmp");
try {
diff --git a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java
index 9361fc18f3..b48355af25 100644
--- a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java
+++ b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java
@@ -19,7 +19,9 @@
package org.apache.hadoop.tools;
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
+import static org.assertj.core.api.Assertions.within;
import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Assert;
import org.junit.Test;
@@ -106,14 +108,14 @@ public void testParsebandwidth() {
DistCpOptions options = OptionsParser.parse(new String[] {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getMapBandwidth(), 0, DELTA);
+ assertThat(options.getMapBandwidth()).isCloseTo(0f, within(DELTA));
options = OptionsParser.parse(new String[] {
"-bandwidth",
"11.2",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getMapBandwidth(), 11.2, DELTA);
+ assertThat(options.getMapBandwidth()).isCloseTo(11.2f, within(DELTA));
}
@Test(expected=IllegalArgumentException.class)
@@ -256,21 +258,21 @@ public void testParseMaps() {
DistCpOptions options = OptionsParser.parse(new String[] {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getMaxMaps(), DistCpConstants.DEFAULT_MAPS);
+ assertThat(options.getMaxMaps()).isEqualTo(DistCpConstants.DEFAULT_MAPS);
options = OptionsParser.parse(new String[] {
"-m",
"1",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getMaxMaps(), 1);
+ assertThat(options.getMaxMaps()).isEqualTo(1);
options = OptionsParser.parse(new String[] {
"-m",
"0",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getMaxMaps(), 1);
+ assertThat(options.getMaxMaps()).isEqualTo(1);
try {
OptionsParser.parse(new String[] {
@@ -389,13 +391,13 @@ public void testCopyStrategy() {
"-f",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getCopyStrategy(), "dynamic");
+ assertThat(options.getCopyStrategy()).isEqualTo("dynamic");
options = OptionsParser.parse(new String[] {
"-f",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getCopyStrategy(), DistCpConstants.UNIFORMSIZE);
+ assertThat(options.getCopyStrategy()).isEqualTo(DistCpConstants.UNIFORMSIZE);
}
@Test
@@ -563,7 +565,7 @@ public void testOptionsAppendToConf() {
conf = new Configuration();
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
- Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), null);
+ assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isNull();
options = OptionsParser.parse(new String[] {
"-update",
"-delete",
@@ -575,8 +577,9 @@ public void testOptionsAppendToConf() {
options.appendToConf(conf);
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
- Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), "U");
- Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 11.2, DELTA);
+ assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isEqualTo("U");
+ assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
+ .isCloseTo(11.2f, within(DELTA));
}
@Test
@@ -588,9 +591,8 @@ public void testOptionsAppendToConfDoesntOverwriteBandwidth() {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
options.appendToConf(conf);
- Assert.assertEquals(
- conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), -1.0,
- DELTA);
+ assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
+ .isCloseTo(-1.0f,within(DELTA));
conf = new Configuration();
Assert.assertEquals(
@@ -800,6 +802,6 @@ public void testExclusionsOption() {
"/tmp/filters.txt",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
- Assert.assertEquals(options.getFiltersFile(), "/tmp/filters.txt");
+ assertThat(options.getFiltersFile()).isEqualTo("/tmp/filters.txt");
}
}
diff --git a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java
index 51eebbb2a3..bf3165765d 100644
--- a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java
+++ b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java
@@ -67,6 +67,7 @@
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
+import static org.assertj.core.api.Assertions.assertThat;
public class TestCopyMapper {
private static final Logger LOG = LoggerFactory.getLogger(TestCopyMapper.class);
@@ -769,7 +770,7 @@ public Integer run() {
new CopyListingFileStatus(tmpFS.getFileStatus(
new Path(SOURCE_PATH + "/src/file"))),
context);
- Assert.assertEquals(stubContext.getWriter().values().size(), 1);
+ assertThat(stubContext.getWriter().values().size()).isEqualTo(1);
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().startsWith("SKIP"));
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().
contains(SOURCE_PATH + "/src/file"));
diff --git a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestDistCpUtils.java b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestDistCpUtils.java
index 6ce8e3e1ea..4acb022786 100644
--- a/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestDistCpUtils.java
+++ b/hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestDistCpUtils.java
@@ -67,6 +67,7 @@
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;
public class TestDistCpUtils {
private static final Logger LOG = LoggerFactory.getLogger(TestDistCpUtils.class);
@@ -98,39 +99,39 @@ public static void destroy() {
public void testGetRelativePathRoot() {
Path root = new Path("/");
Path child = new Path("/a");
- Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/a");
+ assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/a");
}
@Test
public void testGetRelativePath() {
Path root = new Path("/tmp/abc");
Path child = new Path("/tmp/abc/xyz/file");
- Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/xyz/file");
+ assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/xyz/file");
}
@Test
public void testPackAttributes() {
EnumSet attributes = EnumSet.noneOf(FileAttribute.class);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("");
attributes.add(FileAttribute.REPLICATION);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "R");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("R");
attributes.add(FileAttribute.BLOCKSIZE);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RB");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RB");
attributes.add(FileAttribute.USER);
attributes.add(FileAttribute.CHECKSUMTYPE);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUC");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUC");
attributes.add(FileAttribute.GROUP);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGC");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGC");
attributes.add(FileAttribute.PERMISSION);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPC");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPC");
attributes.add(FileAttribute.TIMES);
- Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPCT");
+ assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPCT");
}
@Test
diff --git a/hadoop-tools/hadoop-kafka/pom.xml b/hadoop-tools/hadoop-kafka/pom.xml
index b675bd3751..a227ad4efd 100644
--- a/hadoop-tools/hadoop-kafka/pom.xml
+++ b/hadoop-tools/hadoop-kafka/pom.xml
@@ -111,5 +111,10 @@
mockito-core
test
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java b/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java
index bfaef7b74f..8d74bf2475 100644
--- a/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java
+++ b/hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java
@@ -42,11 +42,11 @@
import java.util.StringJoiner;
import java.util.concurrent.Future;
-import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* This tests that the KafkaSink properly formats the Kafka message.
@@ -147,7 +147,7 @@ public void visit(MetricsVisitor visitor) {
if (LOG.isDebugEnabled()) {
LOG.debug("kafka result: " + jsonResult);
}
- assertEquals(jsonLines.toString(), jsonResult);
+ assertThat(jsonLines.toString()).isEqualTo(jsonResult);
}
StringBuilder recordToJson(MetricsRecord record) {