Bladeren bron

HADOOP-14666. Tests use assertTrue(....equals(...)) instead of assertEquals()

Daniel Templeton 7 jaren geleden
bovenliggende
commit
c21c260392

+ 4 - 2
hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestCertificateUtil.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.security.authentication.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -86,8 +88,8 @@ public class TestCertificateUtil {
         + "Mzc1xA==";
     try {
       RSAPublicKey pk = CertificateUtil.parseRSAPublicKey(pem);
-      assertTrue(pk != null);
-      assertTrue(pk.getAlgorithm().equals("RSA"));
+      assertNotNull(pk);
+      assertEquals("RSA", pk.getAlgorithm());
     } catch (ServletException se) {
       fail("Should not have thrown ServletException");
     }

+ 1 - 1
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java

@@ -35,7 +35,7 @@ public class TestDeprecatedKeys extends TestCase {
     conf.set("topology.script.file.name", "xyz");
     conf.set("topology.script.file.name", "xyz");
     String scriptFile = conf.get(CommonConfigurationKeys.NET_TOPOLOGY_SCRIPT_FILE_NAME_KEY);
-    assertTrue(scriptFile.equals("xyz")) ;
+    assertEquals("xyz", scriptFile) ;
   }
   
   //Tests reading / writing a conf file with deprecation after setting

+ 7 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java

@@ -189,8 +189,10 @@ public class TestKeyProviderFactory {
     assertTrue("Returned Keys should have included key4.", keys.contains("key4"));
 
     List<KeyVersion> kvl = provider.getKeyVersions("key3");
-    assertTrue("KeyVersions should have been returned for key3.", kvl.size() == 1);
-    assertTrue("KeyVersions should have included key3@0.", kvl.get(0).getVersionName().equals("key3@0"));
+    assertEquals("KeyVersions should have been returned for key3.",
+        1, kvl.size());
+    assertEquals("KeyVersions should have included key3@0.",
+        "key3@0", kvl.get(0).getVersionName());
     assertArrayEquals(key3, kvl.get(0).getMaterial());
   }
 
@@ -267,7 +269,7 @@ public class TestKeyProviderFactory {
     Path path = ProviderUtils.unnestUri(new URI(ourUrl));
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertTrue(s.getPermission().toString().equals("rw-------"));
+    assertEquals("rw-------", s.getPermission().toString());
     assertTrue(file + " should exist", file.isFile());
 
     // Corrupt file and Check if JKS can reload from _OLD file
@@ -371,7 +373,8 @@ public class TestKeyProviderFactory {
 
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertTrue("Permissions should have been retained from the preexisting keystore.", s.getPermission().toString().equals("rwxrwxrwx"));
+    assertEquals("Permissions should have been retained from the preexisting "
+        + "keystore.", "rwxrwxrwx", s.getPermission().toString());
   }
 
   @Test

+ 1 - 1
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHardLink.java

@@ -320,7 +320,7 @@ public class TestHardLink {
     assertEquals(2, ("%f").length()); 
     //make sure "\\%f" was munged correctly
     assertEquals(3, ("\\%f").length()); 
-    assertTrue(win.getLinkCountCommand[1].equals("hardlink"));
+    assertEquals("hardlink", win.getLinkCountCommand[1]);
     //make sure "-c%h" was not munged
     assertEquals(4, ("-c%h").length()); 
   }

+ 5 - 5
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java

@@ -214,7 +214,7 @@ public class TestCredentialProviderFactory {
     Path path = ProviderUtils.unnestUri(new URI(ourUrl));
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertTrue(s.getPermission().toString().equals("rw-------"));
+    assertEquals("rw-------", s.getPermission().toString());
     assertTrue(file + " should exist", file.isFile());
 
     // check permission retention after explicit change
@@ -236,8 +236,8 @@ public class TestCredentialProviderFactory {
     Path path = ProviderUtils.unnestUri(new URI(ourUrl));
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertTrue("Unexpected permissions: " + s.getPermission().toString(),
-        s.getPermission().toString().equals("rw-------"));
+    assertEquals("Unexpected permissions: " + s.getPermission().toString(),
+        "rw-------", s.getPermission().toString());
     assertTrue(file + " should exist", file.isFile());
 
     // check permission retention after explicit change
@@ -267,8 +267,8 @@ public class TestCredentialProviderFactory {
 
     FileSystem fs = path.getFileSystem(conf);
     FileStatus s = fs.getFileStatus(path);
-    assertTrue("Permissions should have been retained from the preexisting " +
-    		"keystore.", s.getPermission().toString().equals("rwxrwxrwx"));
+    assertEquals("Permissions should have been retained from the preexisting " +
+        "keystore.", "rwxrwxrwx", s.getPermission().toString());
   }
 }
 

+ 4 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/authorize/TestAccessControlList.java

@@ -187,18 +187,18 @@ public class TestAccessControlList {
     AccessControlList acl;
 
     acl = new AccessControlList("*");
-    assertTrue(acl.toString().equals("All users are allowed"));
+    assertEquals("All users are allowed", acl.toString());
     validateGetAclString(acl);
 
     acl = new AccessControlList(" ");
-    assertTrue(acl.toString().equals("No users are allowed"));
+    assertEquals("No users are allowed", acl.toString());
 
     acl = new AccessControlList("user1,user2");
-    assertTrue(acl.toString().equals("Users [user1, user2] are allowed"));
+    assertEquals("Users [user1, user2] are allowed", acl.toString());
     validateGetAclString(acl);
 
     acl = new AccessControlList("user1,user2 ");// with space
-    assertTrue(acl.toString().equals("Users [user1, user2] are allowed"));
+    assertEquals("Users [user1, user2] are allowed", acl.toString());
     validateGetAclString(acl);
 
     acl = new AccessControlList(" group1,group2");

+ 3 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestReadWriteDiskValidator.java

@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.util;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -125,7 +126,7 @@ public class TestReadWriteDiskValidator {
       readWriteDiskValidator.checkStatus(testDir);
       fail("Disk check should fail.");
     } catch (DiskErrorException e) {
-      assertTrue(e.getMessage().equals("Disk Check failed!"));
+      assertEquals("Disk Check failed!", e.getMessage());
     }
 
     MetricsSource source = ms.getSource(
@@ -137,7 +138,7 @@ public class TestReadWriteDiskValidator {
       readWriteDiskValidator.checkStatus(testDir);
       fail("Disk check should fail.");
     } catch (DiskErrorException e) {
-      assertTrue(e.getMessage().equals("Disk Check failed!"));
+      assertEquals("Disk Check failed!", e.getMessage());
     }
 
     source.getMetrics(collector, true);