Skip to content

Commit c5ef1c1

Browse files
pingsutwahussein
authored andcommitted
HADOOP-16512. [hadoop-tools] Fix order of actual and expected expression in assert statements
Signed-off-by: Akira Ajisaka <[email protected]>
1 parent 15a7368 commit c5ef1c1

File tree

9 files changed

+50
-29
lines changed

9 files changed

+50
-29
lines changed

hadoop-tools/hadoop-archives/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
<type>test-jar</type>
9393
<scope>test</scope>
9494
</dependency>
95+
<dependency>
96+
<groupId>org.assertj</groupId>
97+
<artifactId>assertj-core</artifactId>
98+
<scope>test</scope>
99+
</dependency>
95100
</dependencies>
96101

97102
<build>

hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.junit.Assert;
5050
import static org.junit.Assert.*;
5151
import static org.slf4j.LoggerFactory.getLogger;
52+
import static org.assertj.core.api.Assertions.assertThat;
5253

5354
import org.junit.Before;
5455
import org.junit.Test;
@@ -400,7 +401,7 @@ public void testReadFileContent() throws Exception {
400401
readFileCount++;
401402
}
402403
}
403-
assertEquals(fileList.size(), readFileCount);
404+
assertThat(fileList.size()).isEqualTo(readFileCount);
404405
} finally {
405406
harFileSystem.close();
406407
}

hadoop-tools/hadoop-distcp/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
<artifactId>mockito-core</artifactId>
104104
<scope>test</scope>
105105
</dependency>
106+
<dependency>
107+
<groupId>org.assertj</groupId>
108+
<artifactId>assertj-core</artifactId>
109+
<scope>test</scope>
110+
</dependency>
106111
</dependencies>
107112

108113
<build>

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestCopyListing.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.Assert;
3939
import org.junit.BeforeClass;
4040
import org.junit.AfterClass;
41+
import static org.assertj.core.api.Assertions.assertThat;
4142

4243
import java.io.File;
4344
import java.io.IOException;
@@ -205,8 +206,8 @@ public void testBuildListing() {
205206
Assert.fail("Duplicates not detected");
206207
} catch (DuplicateFileException ignore) {
207208
}
208-
Assert.assertEquals(listing.getBytesToCopy(), 10);
209-
Assert.assertEquals(listing.getNumberOfPaths(), 3);
209+
assertThat(listing.getBytesToCopy()).isEqualTo(10);
210+
assertThat(listing.getNumberOfPaths()).isEqualTo(3);
210211
TestDistCpUtils.delete(fs, "/tmp");
211212

212213
try {

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
package org.apache.hadoop.tools;
2020

2121
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
22+
import static org.assertj.core.api.Assertions.within;
2223
import static org.junit.Assert.fail;
24+
import static org.assertj.core.api.Assertions.assertThat;
2325

2426
import org.junit.Assert;
2527
import org.junit.Test;
@@ -106,14 +108,14 @@ public void testParsebandwidth() {
106108
DistCpOptions options = OptionsParser.parse(new String[] {
107109
"hdfs://localhost:8020/source/first",
108110
"hdfs://localhost:8020/target/"});
109-
Assert.assertEquals(options.getMapBandwidth(), 0, DELTA);
111+
assertThat(options.getMapBandwidth()).isCloseTo(0f, within(DELTA));
110112

111113
options = OptionsParser.parse(new String[] {
112114
"-bandwidth",
113115
"11.2",
114116
"hdfs://localhost:8020/source/first",
115117
"hdfs://localhost:8020/target/"});
116-
Assert.assertEquals(options.getMapBandwidth(), 11.2, DELTA);
118+
assertThat(options.getMapBandwidth()).isCloseTo(11.2f, within(DELTA));
117119
}
118120

119121
@Test(expected=IllegalArgumentException.class)
@@ -256,21 +258,21 @@ public void testParseMaps() {
256258
DistCpOptions options = OptionsParser.parse(new String[] {
257259
"hdfs://localhost:8020/source/first",
258260
"hdfs://localhost:8020/target/"});
259-
Assert.assertEquals(options.getMaxMaps(), DistCpConstants.DEFAULT_MAPS);
261+
assertThat(options.getMaxMaps()).isEqualTo(DistCpConstants.DEFAULT_MAPS);
260262

261263
options = OptionsParser.parse(new String[] {
262264
"-m",
263265
"1",
264266
"hdfs://localhost:8020/source/first",
265267
"hdfs://localhost:8020/target/"});
266-
Assert.assertEquals(options.getMaxMaps(), 1);
268+
assertThat(options.getMaxMaps()).isEqualTo(1);
267269

268270
options = OptionsParser.parse(new String[] {
269271
"-m",
270272
"0",
271273
"hdfs://localhost:8020/source/first",
272274
"hdfs://localhost:8020/target/"});
273-
Assert.assertEquals(options.getMaxMaps(), 1);
275+
assertThat(options.getMaxMaps()).isEqualTo(1);
274276

275277
try {
276278
OptionsParser.parse(new String[] {
@@ -389,13 +391,13 @@ public void testCopyStrategy() {
389391
"-f",
390392
"hdfs://localhost:8020/source/first",
391393
"hdfs://localhost:8020/target/"});
392-
Assert.assertEquals(options.getCopyStrategy(), "dynamic");
394+
assertThat(options.getCopyStrategy()).isEqualTo("dynamic");
393395

394396
options = OptionsParser.parse(new String[] {
395397
"-f",
396398
"hdfs://localhost:8020/source/first",
397399
"hdfs://localhost:8020/target/"});
398-
Assert.assertEquals(options.getCopyStrategy(), DistCpConstants.UNIFORMSIZE);
400+
assertThat(options.getCopyStrategy()).isEqualTo(DistCpConstants.UNIFORMSIZE);
399401
}
400402

401403
@Test
@@ -563,7 +565,7 @@ public void testOptionsAppendToConf() {
563565
conf = new Configuration();
564566
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
565567
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
566-
Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), null);
568+
assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isNull();
567569
options = OptionsParser.parse(new String[] {
568570
"-update",
569571
"-delete",
@@ -575,8 +577,9 @@ public void testOptionsAppendToConf() {
575577
options.appendToConf(conf);
576578
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
577579
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
578-
Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), "U");
579-
Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 11.2, DELTA);
580+
assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isEqualTo("U");
581+
assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
582+
.isCloseTo(11.2f, within(DELTA));
580583
}
581584

582585
@Test
@@ -588,9 +591,8 @@ public void testOptionsAppendToConfDoesntOverwriteBandwidth() {
588591
"hdfs://localhost:8020/source/first",
589592
"hdfs://localhost:8020/target/"});
590593
options.appendToConf(conf);
591-
Assert.assertEquals(
592-
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), -1.0,
593-
DELTA);
594+
assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
595+
.isCloseTo(-1.0f,within(DELTA));
594596

595597
conf = new Configuration();
596598
Assert.assertEquals(
@@ -800,6 +802,6 @@ public void testExclusionsOption() {
800802
"/tmp/filters.txt",
801803
"hdfs://localhost:8020/source/first",
802804
"hdfs://localhost:8020/target/"});
803-
Assert.assertEquals(options.getFiltersFile(), "/tmp/filters.txt");
805+
assertThat(options.getFiltersFile()).isEqualTo("/tmp/filters.txt");
804806
}
805807
}

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/mapred/TestCopyMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
6868
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
6969
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
70+
import static org.assertj.core.api.Assertions.assertThat;
7071

7172
public class TestCopyMapper {
7273
private static final Logger LOG = LoggerFactory.getLogger(TestCopyMapper.class);
@@ -769,7 +770,7 @@ public Integer run() {
769770
new CopyListingFileStatus(tmpFS.getFileStatus(
770771
new Path(SOURCE_PATH + "/src/file"))),
771772
context);
772-
Assert.assertEquals(stubContext.getWriter().values().size(), 1);
773+
assertThat(stubContext.getWriter().values().size()).isEqualTo(1);
773774
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().startsWith("SKIP"));
774775
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().
775776
contains(SOURCE_PATH + "/src/file"));

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/util/TestDistCpUtils.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import static org.junit.Assert.assertEquals;
6868
import static org.junit.Assert.assertFalse;
6969
import static org.junit.Assert.assertTrue;
70+
import static org.assertj.core.api.Assertions.assertThat;
7071

7172
public class TestDistCpUtils {
7273
private static final Logger LOG = LoggerFactory.getLogger(TestDistCpUtils.class);
@@ -98,39 +99,39 @@ public static void destroy() {
9899
public void testGetRelativePathRoot() {
99100
Path root = new Path("/");
100101
Path child = new Path("/a");
101-
Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/a");
102+
assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/a");
102103
}
103104

104105
@Test
105106
public void testGetRelativePath() {
106107
Path root = new Path("/tmp/abc");
107108
Path child = new Path("/tmp/abc/xyz/file");
108-
Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/xyz/file");
109+
assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/xyz/file");
109110
}
110111

111112
@Test
112113
public void testPackAttributes() {
113114
EnumSet<FileAttribute> attributes = EnumSet.noneOf(FileAttribute.class);
114-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "");
115+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("");
115116

116117
attributes.add(FileAttribute.REPLICATION);
117-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "R");
118+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("R");
118119

119120
attributes.add(FileAttribute.BLOCKSIZE);
120-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RB");
121+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RB");
121122

122123
attributes.add(FileAttribute.USER);
123124
attributes.add(FileAttribute.CHECKSUMTYPE);
124-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUC");
125+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUC");
125126

126127
attributes.add(FileAttribute.GROUP);
127-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGC");
128+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGC");
128129

129130
attributes.add(FileAttribute.PERMISSION);
130-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPC");
131+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPC");
131132

132133
attributes.add(FileAttribute.TIMES);
133-
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPCT");
134+
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPCT");
134135
}
135136

136137
@Test

hadoop-tools/hadoop-kafka/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,10 @@
111111
<artifactId>mockito-core</artifactId>
112112
<scope>test</scope>
113113
</dependency>
114+
<dependency>
115+
<groupId>org.assertj</groupId>
116+
<artifactId>assertj-core</artifactId>
117+
<scope>test</scope>
118+
</dependency>
114119
</dependencies>
115120
</project>

hadoop-tools/hadoop-kafka/src/test/java/org/apache/hadoop/metrics2/impl/TestKafkaMetrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
import java.util.StringJoiner;
4343
import java.util.concurrent.Future;
4444

45-
import static org.junit.Assert.assertEquals;
4645
import static org.mockito.ArgumentMatchers.any;
4746
import static org.mockito.Mockito.mock;
4847
import static org.mockito.Mockito.verify;
4948
import static org.mockito.Mockito.when;
49+
import static org.assertj.core.api.Assertions.assertThat;
5050

5151
/**
5252
* This tests that the KafkaSink properly formats the Kafka message.
@@ -147,7 +147,7 @@ public void visit(MetricsVisitor visitor) {
147147
if (LOG.isDebugEnabled()) {
148148
LOG.debug("kafka result: " + jsonResult);
149149
}
150-
assertEquals(jsonLines.toString(), jsonResult);
150+
assertThat(jsonLines.toString()).isEqualTo(jsonResult);
151151
}
152152

153153
StringBuilder recordToJson(MetricsRecord record) {

0 commit comments

Comments
 (0)