Remove unnecessary String() constructor invocations 90/35890/4
authorStephen Kitt <skitt@redhat.com>
Mon, 7 Mar 2016 17:38:26 +0000 (18:38 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 16 Mar 2016 13:57:25 +0000 (13:57 +0000)
Document legimitate uses, and clean up the containing test classes
(which mostly involves disabling IntelliJ's warnings about invalid
uses of equals()).

Clean up a few only-null variables and a couple of other small
issues.

Change-Id: I7a6177b266589c15b9b169a99a9f2a9054da94ed
Signed-off-by: Stephen Kitt <skitt@redhat.com>
common/object-cache-api/src/test/java/org/opendaylight/yangtools/objcache/spi/CacheTest.java
common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitImplTest.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImplTest.java

index 37434e5bc2790dae8e7313299ae985788d54aae9..483ef26b68db976036541ac2a6dd16c383183c94 100644 (file)
@@ -46,6 +46,8 @@ public class CacheTest {
     }
 
     @Test
+    // This test is based on using different references
+    @SuppressWarnings("RedundantStringConstructorCall")
     public void testPresentKey() {
         final String key1 = new String("abcd");
         final String key2 = new String("abcd");
index bc41da9ab31f8d2b1f1368d280bf03a17e1fdb72..b32ac84e9faf29c4b7266df94e3a17f8a3afef7c 100644 (file)
@@ -37,6 +37,8 @@ public class GuavaObjectCacheTest {
        }
 
        @Test
+       // This test is based on using different references
+       @SuppressWarnings("RedundantStringConstructorCall")
        public void testMultipleReferences() {
                final String s1 = "abcd";
                final String s2 = new String(s1);
index 778bf25a26cfa16e2c9e47368052246ab3106861..2353d3771ed8a6708ed5c252a54a06ccba19d5e1 100644 (file)
@@ -20,15 +20,14 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
             "my-other-leaf");
 
     @Test
+    // This test is based on using different references; we're testing equals()
+    @SuppressWarnings({"RedundantStringConstructorCall", "EqualsWithItself"})
     public void equalsByteTest() {
 
-        byte[] valueNull = null;
-        byte[] equalValueNull = null;
-
         LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(LEAF_QNAME,
-                valueNull);
+                null);
         LeafNode<byte[]> equalLeafNodeNull = ImmutableNodes.leafNode(
-                SAME_LEAF_QNAME, equalValueNull);
+                SAME_LEAF_QNAME, null);
 
         assertTrue(leafNodeNull.equals(leafNodeNull));
         assertTrue(leafNodeNull.equals(equalLeafNodeNull));
@@ -97,7 +96,7 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
         assertTrue(leafNode6.equals(equalLeafNode6));
         assertTrue(equalLeafNode6.equals(leafNode6));
 
-        String value5 = new String("test");
+        String value5 = "test";
         String equalValue5 = new String("test");
 
         LeafNode<String> leafNode5 = ImmutableNodes
@@ -112,6 +111,8 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
     }
 
     @Test
+    // We're testing equals()
+    @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
     public void notEqualByteTest() {
 
         byte[] value = "test".getBytes();
@@ -185,8 +186,8 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
         assertFalse(leafNode6.equals(otherLeafNode6));
         assertFalse(otherLeafNode6.equals(leafNode6));
 
-        String value5 = new String("test");
-        String otherValue5 = new String("test2");
+        String value5 = "test";
+        String otherValue5 = "test2";
 
         LeafNode<String> leafNode5 = ImmutableNodes
                 .leafNode(LEAF_QNAME, value5);
@@ -208,15 +209,12 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
         assertFalse(leafNode4.equals(leafNode5));
         assertFalse(leafNode6.equals(leafNode5));
 
-        byte[] valueNull = null;
-
         LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(
-                SAME_LEAF_QNAME, valueNull);
+                SAME_LEAF_QNAME, null);
         assertFalse(leafNodeNull.equals(leafNode));
         assertFalse(leafNode.equals(leafNodeNull));
 
-        byte[] byteValue = new byte[] { new Byte("1").byteValue(),
-                new Byte("1").byteValue() };
+        byte[] byteValue = new byte[] { 1, 1 };
 
         LeafNode<byte[]> byteLeafNode = ImmutableNodes.leafNode(
                 SAME_LEAF_QNAME, byteValue);
@@ -226,6 +224,8 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
     }
 
     @Test
+    // We're testing equals()
+    @SuppressWarnings({"EqualsWithItself", "EqualsBetweenInconvertibleTypes"})
     public void equalsOtherTypesTest() {
 
         char[] valueChar = "test".toCharArray();
index 04d086c4b69e43975c825c697a3a4d17605e81b5..274bc0d19766406963cb7b821546f9c6a006a4cc 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.yang.model.util;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -26,6 +26,8 @@ import org.opendaylight.yangtools.yang.model.api.Status;
 public class BitImplTest {
 
     @Test
+    // We're testing equals()
+    @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
     public void test() {
 
         // hashCode method test
@@ -35,7 +37,6 @@ public class BitImplTest {
         URI uriB = null;
         URI uriB1 = null;
         URI uriB2 = null;
-        boolean urisInitiallized = false;
         try {
             uriA = new URI("some:uriA");
             uriA1 = new URI("some:uriA1");
@@ -43,12 +44,8 @@ public class BitImplTest {
             uriB = new URI("some:uriB");
             uriB1 = new URI("some:uriB1");
             uriB2 = new URI("some:uriB2");
-            urisInitiallized = true;
-
         } catch (URISyntaxException e) {
-            e.printStackTrace();
-            assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
-
+            fail("Not all required uri variables were instantiated.");
         }
         QName qnameA = QName.create(uriA, new Date(5000000), "some name");
 
@@ -68,12 +65,12 @@ public class BitImplTest {
         qnamesB.add(qnameB2);
         SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
 
-        BitImpl biB = null;
+        BitImpl biB;
         BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
 
         assertEquals("biA should equals to itsefl", biA, biA);
         assertFalse("biA shouldn't equal to null", biA.equals(null));
-        assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
+        assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
 
         biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
index c4425325cba7a7a3342ee89d1d5d124030e14216..839f1e72ba8e63a602c565bdbae59499e2ea446e 100644 (file)
@@ -16,6 +16,8 @@ import org.junit.Test;
 public class MustDefinitionImplTest {
 
     @Test
+    // We're testing equals()
+    @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
     public void test() {
         MustDefinitionImpl mdiA;
         MustDefinitionImpl mdiB;
@@ -23,7 +25,7 @@ public class MustDefinitionImplTest {
 
         assertEquals("mdiA should equals to itsefl", mdiA, mdiA);
         assertFalse("mdiA shouldn't equal to null", mdiA.equals(null));
-        assertFalse("mdiA shouldn't equal to object of other type", mdiA.equals(new String("str")));
+        assertFalse("mdiA shouldn't equal to object of other type", mdiA.equals("str"));
 
         // test of equals method