Skip to content

Commit 58e0410

Browse files
committed
HADOOP-19425. Use AssertJ.
1 parent d2d4aa8 commit 58e0410

File tree

45 files changed

+439
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+439
-368
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import java.util.concurrent.TimeUnit;
3030

31-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
31+
import static org.assertj.core.api.Assumptions.assumeThat;
3232

3333
/**
3434
* Base class for any Wasb test with timeouts & named threads.
@@ -69,10 +69,10 @@ protected int getTestTimeoutMillis() {
6969
}
7070

7171
public static void assumeNotNull(Object objects) {
72-
assumeTrue(objects != null);
72+
assumeThat(objects).isNotNull();
7373
}
7474

7575
public static void assumeNotNull(Object objects, String message) {
76-
assumeTrue(objects != null, message);
76+
assumeThat(objects).as(message).isNotNull();
7777
}
7878
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestContainerChecks.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azure;
2020

21-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
21+
import static org.assertj.core.api.Assumptions.assumeThat;
2222

2323
import java.io.FileNotFoundException;
2424
import java.util.EnumSet;
@@ -169,7 +169,7 @@ public String call() throws Exception {
169169
@Test
170170
public void testContainerChecksWithSas() throws Exception {
171171

172-
assumeFalse(runningInSASMode);
172+
assumeThat(runningInSASMode).isFalse();
173173
testAccount = AzureBlobStorageTestAccount.create("",
174174
EnumSet.of(CreateOptions.UseSas));
175175
assumeNotNull(testAccount);

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestListPerformance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.apache.hadoop.fs.azure.integration.AzureTestUtils;
4949
import org.apache.hadoop.fs.contract.ContractTestUtils;
5050

51-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
51+
import static org.assertj.core.api.Assumptions.assumeThat;
5252

5353
/**
5454
* Test list performance.
@@ -99,7 +99,7 @@ protected AzureBlobStorageTestAccount createTestAccount() throws Exception {
9999

100100
@Test
101101
public void test_0101_CreateDirectoryWithFiles() throws Exception {
102-
assumeFalse(fs.exists(TEST_DIR_PATH), "Test path exists; skipping");
102+
assumeThat(fs.exists(TEST_DIR_PATH)).as("Test path exists; skipping").isFalse();
103103

104104
ExecutorService executorService = Executors.newFixedThreadPool(threads);
105105
CloudBlobContainer container = testAccount.getRealContainer();

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestNativeAzureFileSystemContractEmulator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azure;
2020

21-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
21+
import static org.assertj.core.api.Assumptions.assumeThat;
2222

2323
import org.apache.hadoop.fs.FileSystemContractBaseTest;
2424
import org.apache.hadoop.fs.Path;
@@ -50,7 +50,9 @@ public void setUp() throws Exception {
5050
if (testAccount != null) {
5151
fs = testAccount.getFileSystem();
5252
}
53-
assumeTrue(fs != null);
53+
assumeThat(fs)
54+
.as("FileSystem must not be null for this test")
55+
.isNotNull();
5456
basePath = fs.makeQualified(
5557
AzureTestUtils.createTestPath(
5658
new Path("ITestNativeAzureFileSystemContractEmulator")));

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestNativeAzureFileSystemContractLive.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azure;
2020

21-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
21+
import static org.assertj.core.api.Assumptions.assumeThat;
2222

2323
import org.apache.hadoop.fs.FileSystemContractBaseTest;
2424
import org.apache.hadoop.fs.Path;
@@ -53,7 +53,7 @@ public void setUp() throws Exception {
5353
if (testAccount != null) {
5454
fs = testAccount.getFileSystem();
5555
}
56-
assumeTrue(fs != null);
56+
assumeThat(fs).isNotNull();
5757
basePath = fs.makeQualified(
5858
AzureTestUtils.createTestPath(
5959
new Path("NativeAzureFileSystemContractLive")));

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestNativeAzureFileSystemContractPageBlobLive.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azure;
2020

21-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
21+
import static org.assertj.core.api.Assumptions.assumeThat;
2222

2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.fs.FileSystemContractBaseTest;
@@ -63,7 +63,7 @@ private AzureBlobStorageTestAccount createTestAccount()
6363
@BeforeEach
6464
public void setUp() throws Exception {
6565
testAccount = createTestAccount();
66-
assumeTrue(testAccount != null);
66+
assumeThat(testAccount).isNotNull();
6767
fs = testAccount.getFileSystem();
6868
basePath = AzureTestUtils.pathForTests(fs, "filesystemcontractpageblob");
6969
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbRemoteCallHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import static org.mockito.Mockito.atLeast;
4848
import static org.mockito.Mockito.times;
4949

50-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
50+
import static org.assertj.core.api.Assumptions.assumeThat;
5151

5252
/**
5353
* Test class to hold all WasbRemoteCallHelper tests.
@@ -72,8 +72,9 @@ public void setUp() throws Exception {
7272
boolean useSecureMode = fs.getConf().getBoolean(KEY_USE_SECURE_MODE, false);
7373
boolean useAuthorization = fs.getConf()
7474
.getBoolean(NativeAzureFileSystem.KEY_AZURE_AUTHORIZATION, false);
75-
assumeTrue(useSecureMode && useAuthorization,
76-
"Test valid when both SecureMode and Authorization are enabled .. skipping");
75+
assumeThat(useSecureMode && useAuthorization)
76+
.as("Test valid when both SecureMode and Authorization are enabled .. skipping")
77+
.isTrue();
7778
}
7879

7980
/**

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/ITestWasbUriAndConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
2222
import static org.apache.hadoop.fs.azure.NativeAzureFileSystem.RETURN_URI_AS_CANONICAL_SERVICE_NAME_PROPERTY_NAME;
2323
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
24-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
24+
import static org.assertj.core.api.Assumptions.assumeThat;
2525

2626
import java.io.ByteArrayInputStream;
2727
import java.io.DataInputStream;
@@ -132,7 +132,7 @@ public void testConnectUsingKey() throws Exception {
132132
@Test
133133
public void testConnectUsingSAS() throws Exception {
134134

135-
assumeFalse(runningInSASMode);
135+
assumeThat(runningInSASMode).isFalse();
136136
// Create the test account with SAS credentials.
137137
testAccount = AzureBlobStorageTestAccount.create("",
138138
EnumSet.of(CreateOptions.UseSas, CreateOptions.CreateContainer));
@@ -148,7 +148,7 @@ public void testConnectUsingSAS() throws Exception {
148148
@Test
149149
public void testConnectUsingSASReadonly() throws Exception {
150150

151-
assumeFalse(runningInSASMode);
151+
assumeThat(runningInSASMode).isFalse();
152152
// Create the test account with SAS credentials.
153153
testAccount = AzureBlobStorageTestAccount.create("", EnumSet.of(
154154
CreateOptions.UseSas, CreateOptions.CreateContainer,
@@ -378,7 +378,7 @@ public void testDefaultKeyProvider() throws Exception {
378378
public void testCredsFromCredentialProvider(@TempDir java.nio.file.Path tempDir)
379379
throws Exception {
380380

381-
assumeFalse(runningInSASMode);
381+
assumeThat(runningInSASMode).isFalse();
382382
String account = "testacct";
383383
String key = "testkey";
384384
// set up conf to have a cred provider

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestNativeAzureFileSystemAuthorization.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.apache.hadoop.security.UserGroupInformation;
3939
import org.apache.hadoop.test.GenericTestUtils;
4040
import org.apache.hadoop.test.LambdaTestUtils;
41-
import org.apache.hadoop.util.StringUtils;
4241

4342
import org.junit.jupiter.api.BeforeEach;
4443
import org.junit.jupiter.api.Test;
@@ -48,7 +47,7 @@
4847
import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_USE_SECURE_MODE;
4948
import static org.apache.hadoop.fs.azure.CachingAuthorizer.KEY_AUTH_SERVICE_CACHING_ENABLE;
5049
import static org.apache.hadoop.fs.contract.ContractTestUtils.*;
51-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
50+
import static org.assertj.core.api.Assumptions.assumeThat;
5251

5352
/**
5453
* Test class to hold all WASB authorization tests.
@@ -92,8 +91,9 @@ public void setUp() throws Exception {
9291
super.setUp();
9392
boolean useSecureMode = fs.getConf().getBoolean(KEY_USE_SECURE_MODE, false);
9493
boolean useAuthorization = fs.getConf().getBoolean(NativeAzureFileSystem.KEY_AZURE_AUTHORIZATION, false);
95-
assumeTrue((useSecureMode && useAuthorization),
96-
"Test valid when both SecureMode and Authorization are enabled .. skipping");
94+
assumeThat((useSecureMode && useAuthorization))
95+
.as("Test valid when both SecureMode and Authorization are enabled .. skipping")
96+
.isTrue();
9797

9898
authorizer = new MockWasbAuthorizerImpl(fs);
9999
authorizer.init(fs.getConf());
@@ -1544,8 +1544,9 @@ public void testSetOwnerSucceedsForAuthorisedUsers() throws Throwable {
15441544
ContractTestUtils.assertPathExists(fs, "test path does not exist", testPath);
15451545

15461546
String owner = fs.getFileStatus(testPath).getOwner();
1547-
assumeTrue(!StringUtils.equalsIgnoreCase(owner, newOwner),
1548-
"changing owner requires original and new owner to be different");
1547+
assumeThat(owner)
1548+
.as("changing owner requires original and new owner to be different")
1549+
.isNotEqualToIgnoringCase(newOwner);
15491550

15501551
authorisedUser.doAs(new PrivilegedExceptionAction<Void>() {
15511552
@Override
@@ -1587,8 +1588,9 @@ public void testSetOwnerSucceedsForAnyUserWhenWildCardIsSpecified() throws Throw
15871588
ContractTestUtils.assertPathExists(fs, "test path does not exist", testPath);
15881589

15891590
String owner = fs.getFileStatus(testPath).getOwner();
1590-
assumeTrue(!StringUtils.equalsIgnoreCase(owner, newOwner),
1591-
"changing owner requires original and new owner to be different");
1591+
assumeThat(owner)
1592+
.as("changing owner requires original and new owner to be different")
1593+
.isNotEqualToIgnoringCase(newOwner);
15921594

15931595
user.doAs(new PrivilegedExceptionAction<Void>() {
15941596
@Override

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/integration/AzureTestUtils.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@
4141
import org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount;
4242
import org.apache.hadoop.fs.azure.NativeAzureFileSystem;
4343

44-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
45-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
46-
4744
import static org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount.WASB_ACCOUNT_NAME_DOMAIN_SUFFIX_REGEX;
4845
import static org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount.WASB_TEST_ACCOUNT_NAME_WITH_DOMAIN;
4946
import static org.apache.hadoop.fs.azure.integration.AzureTestConstants.*;
5047
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT;
5148
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
5249
import static org.apache.hadoop.test.MetricsAsserts.getLongGauge;
5350
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
51+
import static org.assertj.core.api.Assumptions.assumeThat;
5452

5553
/**
5654
* Utilities for the Azure tests. Based on {@code S3ATestUtils}, so
@@ -394,7 +392,7 @@ public static void assume(String message, boolean condition) {
394392
if (!condition) {
395393
LOG.warn(message);
396394
}
397-
assumeTrue(condition, message);
395+
assumeThat(condition).as(message).isTrue();
398396
}
399397

400398
/**
@@ -495,8 +493,10 @@ public static String verifyWasbAccountNameInConfig(Configuration conf) {
495493
if (accountName == null) {
496494
accountName = conf.get(WASB_TEST_ACCOUNT_NAME_WITH_DOMAIN);
497495
}
498-
assumeTrue(accountName != null && !accountName.endsWith(WASB_ACCOUNT_NAME_DOMAIN_SUFFIX_REGEX),
499-
"Account for WASB is missing or it is not in correct format");
496+
assumeThat(accountName)
497+
.as("Account for WASB is missing or it is not in correct format")
498+
.isNotNull()
499+
.doesNotEndWith(WASB_ACCOUNT_NAME_DOMAIN_SUFFIX_REGEX);
500500
return accountName;
501501
}
502502

@@ -550,7 +550,8 @@ public static String readStringFromStream(FSDataInputStream inputStream) throws
550550
* Assume hierarchical namespace is disabled for test account.
551551
*/
552552
public static void assumeNamespaceDisabled(Configuration conf) {
553-
assumeFalse(conf.getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false),
554-
"Hierarchical namespace is enabled for test account.");
553+
assumeThat(conf.getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false))
554+
.as("Hierarchical namespace is enabled for test account.")
555+
.isFalse();
555556
}
556557
}

0 commit comments

Comments
 (0)