summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaka Cho <takamune.cho@att.com>2020-06-09 11:21:31 -0400
committerTaka Cho <takamune.cho@att.com>2020-06-15 12:16:32 -0400
commit6e22f6ba5a83c8e55bec56798e8e4c7a3d4b002b (patch)
tree6257a46d109aae731d9f1a98c334251d6cc9d513
parent7a64baa7a15c07c2bbb90c41594b82e8c8bfc816 (diff)
reduce sonar issue - 2 rev
In some conditions for assertTrue, sonarcloud recommends using assertEquals Assert.assertTrue(a.equals(b)); Assert.assertTrue(a == b); Assert.assertTrue(a == null); Assert.assertTrue(a != null); Assert.assertFalse(a.equals(b)); Compliant Solution Assert.assertEquals(a, b); Assert.assertSame(a, b); Assert.assertNull(a); Assert.assertNotNull(a); Assert.assertNotEquals(a, b); Issue-ID: POLICY-2616 Change-Id: Ib362573bd865d1b561916bf64640c8ddeaa02546 Signed-off-by: Taka Cho <takamune.cho@att.com>
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java3
-rw-r--r--feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java11
-rw-r--r--feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java7
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java3
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java33
5 files changed, 31 insertions, 26 deletions
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
index 5a0c6f77..48152715 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
@@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -676,7 +677,7 @@ public class DistributedLockManagerTest {
// new lock should succeed
DistributedLock lock2 = getLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback, false);
- assertTrue(lock2 != lock);
+ assertNotSame(lock2, lock);
assertTrue(lock2.isWaiting());
}
diff --git a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
index c0f271cf..dfa85948 100644
--- a/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
+++ b/feature-eelf/src/test/java/org/onap/policy/drools/eelf/test/EElfTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.drools.eelf.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -76,11 +77,11 @@ public class EElfTest {
* @param slf4jLogger SLF4J Logger
*/
protected void assertLogLevels(EELFLogger eelfLogger, Logger slf4jLogger) {
- assertTrue(slf4jLogger.isDebugEnabled() == eelfLogger.isDebugEnabled());
- assertTrue(slf4jLogger.isInfoEnabled() == eelfLogger.isInfoEnabled());
- assertTrue(slf4jLogger.isErrorEnabled() == eelfLogger.isErrorEnabled());
- assertTrue(slf4jLogger.isWarnEnabled() == eelfLogger.isWarnEnabled());
- assertTrue(slf4jLogger.isTraceEnabled() == eelfLogger.isTraceEnabled());
+ assertEquals(slf4jLogger.isDebugEnabled(), eelfLogger.isDebugEnabled());
+ assertEquals(slf4jLogger.isInfoEnabled(), eelfLogger.isInfoEnabled());
+ assertEquals(slf4jLogger.isErrorEnabled(), eelfLogger.isErrorEnabled());
+ assertEquals(slf4jLogger.isWarnEnabled(), eelfLogger.isWarnEnabled());
+ assertEquals(slf4jLogger.isTraceEnabled(), eelfLogger.isTraceEnabled());
}
@Test
diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
index 62c6c951..4215aa8c 100644
--- a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
+++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.drools.healthcheck;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -142,12 +143,12 @@ public class HealthCheckTest {
reports.setDetails(lst);
reports.setHealthy(true);
- assertTrue(lst == reports.getDetails());
- assertEquals(true, reports.isHealthy());
+ assertSame(lst, reports.getDetails());
+ assertTrue(reports.isHealthy());
// flip the flag
reports.setHealthy(false);
- assertEquals(false, reports.isHealthy());
+ assertFalse(reports.isHealthy());
// toString should work with populated data
assertNotNull(reports.toString());
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java
index ed9d1c9a..f9878a9d 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.drools.pooling;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -131,7 +132,7 @@ public class PoolingFeatureTest {
String host2 = pool.getHost();
assertNotNull(host2);
- assertTrue(!host.equals(host2));
+ assertNotEquals(host, host2);
}
@Test
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
index 50cab788..5eaeddca 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.drools.pooling.message;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -298,47 +299,47 @@ public class BucketAssignmentsTest {
// slightly different values (i.e., changed "def" to "eef")
asgn = new BucketAssignments(new String[] {"abc", null, "eef"});
- assertTrue(code != asgn.hashCode());
+ assertNotEquals(code, asgn.hashCode());
}
@Test
public void testEquals() {
// null object
BucketAssignments asgn = new BucketAssignments();
- assertFalse(asgn.equals(null));
+ assertNotEquals(asgn, null);
// same object
asgn = new BucketAssignments();
- assertTrue(asgn.equals(asgn));
+ assertEquals(asgn, asgn);
// different class of object
asgn = new BucketAssignments();
- assertFalse(asgn.equals("not an assignment object"));
+ assertNotEquals(asgn, "not an assignment object");
+
+ assertNotEquals(asgn, new BucketAssignments(new String[] {"abc"}));
// with null assignments
asgn = new BucketAssignments();
- assertTrue(asgn.equals(new BucketAssignments()));
-
- assertFalse(asgn.equals(new BucketAssignments(new String[] {"abc"})));
+ assertEquals(asgn, new BucketAssignments());
// with empty array
asgn = new BucketAssignments(new String[0]);
- assertTrue(asgn.equals(asgn));
+ assertEquals(asgn, asgn);
- assertFalse(asgn.equals(new BucketAssignments()));
- assertFalse(asgn.equals(new BucketAssignments(new String[] {"abc"})));
+ assertNotEquals(asgn, new BucketAssignments());
+ assertNotEquals(asgn, new BucketAssignments(new String[] {"abc"}));
// with null items
String[] arr = {"abc", null, "def"};
asgn = new BucketAssignments(arr);
- assertTrue(asgn.equals(asgn));
- assertTrue(asgn.equals(new BucketAssignments(arr)));
- assertTrue(asgn.equals(new BucketAssignments(new String[] {"abc", null, "def"})));
+ assertEquals(asgn, asgn);
+ assertEquals(asgn, new BucketAssignments(arr));
+ assertEquals(asgn, new BucketAssignments(new String[] {"abc", null, "def"}));
- assertFalse(asgn.equals(new BucketAssignments()));
- assertFalse(asgn.equals(new BucketAssignments(new String[] {"abc", null, "XYZ"})));
+ assertNotEquals(asgn, new BucketAssignments());
+ assertNotEquals(asgn, new BucketAssignments(new String[] {"abc", null, "XYZ"}));
- assertFalse(asgn.equals(new BucketAssignments()));
+ assertNotEquals(asgn, new BucketAssignments());
}
/**