summaryrefslogtreecommitdiffstats
path: root/utils-test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-29 10:16:44 -0400
committerJim Hahn <jrh3@att.com>2020-06-29 11:09:58 -0400
commitff0842117fba4dfe675a8b87af3a1098cde023bd (patch)
tree1dde66fc3323e9bb3edec8bf83df1456cbf6fffd /utils-test
parent4cdfdf4fa218a3b4f7e9690355db85976bc1888d (diff)
Fix issues in common for new sonar rules
Addressed issues reported due to updates to the sonar rules: - invoke only one method in a junit lambda - complete the assertion - add DOCTYPE to html Issue-ID: POLICY-2650 Change-Id: Ib8b8a2e4736cc23849c0f7aef972ffa3365a3e00 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils-test')
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java9
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java12
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java16
3 files changed, 22 insertions, 15 deletions
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
index 11ee63c0..f16764c9 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
@@ -76,10 +76,11 @@ public class GsonTestUtilsTest {
utils.compareGson(data, GsonTestUtilsTest.class);
// file not found
- assertThatThrownBy(() -> utils.compareGson(data,
- new File(GsonTestUtilsTest.class.getSimpleName() + "-NotFound.json")))
- .isInstanceOf(JsonParseException.class)
- .hasCauseInstanceOf(FileNotFoundException.class);
+ File file = new File(GsonTestUtilsTest.class.getSimpleName() + "-NotFound.json");
+
+ assertThatThrownBy(() -> utils.compareGson(data, file))
+ .isInstanceOf(JsonParseException.class)
+ .hasCauseInstanceOf(FileNotFoundException.class);
// force I/O error while reading file
GsonTestUtils utils2 = new GsonTestUtils() {
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java
index 70820c44..745e989f 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
+import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
@@ -37,6 +38,7 @@ import org.junit.Test;
public class PseudoScheduledExecutorServiceTest {
private static final long DELAY_MS = 100L;
private static final long PERIOD_MS = 200L;
+ private static final List<Callable<Object>> EMPTY_CALLABLES = Collections.emptyList();
private int ran;
private int called;
@@ -135,25 +137,25 @@ public class PseudoScheduledExecutorServiceTest {
@Test
public void testInvokeAllCollectionOfQextendsCallableOfT() {
- assertThatThrownBy(() -> svc.invokeAll(Collections.emptyList()))
+ assertThatThrownBy(() -> svc.invokeAll(EMPTY_CALLABLES))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
public void testInvokeAllCollectionOfQextendsCallableOfTLongTimeUnit() {
- assertThatThrownBy(() -> svc.invokeAll(Collections.emptyList(), 1, TimeUnit.MILLISECONDS))
+ assertThatThrownBy(() -> svc.invokeAll(EMPTY_CALLABLES, 1, TimeUnit.MILLISECONDS))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
public void testInvokeAnyCollectionOfQextendsCallableOfT() {
- assertThatThrownBy(() -> svc.invokeAny(Collections.emptyList()))
+ assertThatThrownBy(() -> svc.invokeAny(EMPTY_CALLABLES))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
public void testInvokeAnyCollectionOfQextendsCallableOfTLongTimeUnit() {
- assertThatThrownBy(() -> svc.invokeAny(Collections.emptyList(), 1, TimeUnit.MILLISECONDS))
+ assertThatThrownBy(() -> svc.invokeAny(EMPTY_CALLABLES, 1, TimeUnit.MILLISECONDS))
.isInstanceOf(UnsupportedOperationException.class);
}
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java
index 49710538..d7316c1f 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,8 +83,9 @@ public class PseudoTimerTest {
@Test
public void testScheduleTimerTaskDate() {
- assertThatThrownBy(() -> timer.schedule(new MyTask(), new Date()))
- .isInstanceOf(UnsupportedOperationException.class);
+ MyTask task = new MyTask();
+ Date curdate = new Date();
+ assertThatThrownBy(() -> timer.schedule(task, curdate)).isInstanceOf(UnsupportedOperationException.class);
}
@Test
@@ -105,8 +106,9 @@ public class PseudoTimerTest {
@Test
public void testScheduleTimerTaskDateLong() {
- assertThatThrownBy(() -> timer.schedule(new MyTask(), new Date(), 1L))
- .isInstanceOf(UnsupportedOperationException.class);
+ MyTask task = new MyTask();
+ Date curdate = new Date();
+ assertThatThrownBy(() -> timer.schedule(task, curdate, 1L)).isInstanceOf(UnsupportedOperationException.class);
}
@Test
@@ -127,7 +129,9 @@ public class PseudoTimerTest {
@Test
public void testScheduleAtFixedRateTimerTaskDateLong() {
- assertThatThrownBy(() -> timer.scheduleAtFixedRate(new MyTask(), new Date(), 1L))
+ MyTask task = new MyTask();
+ Date curdate = new Date();
+ assertThatThrownBy(() -> timer.scheduleAtFixedRate(task, curdate, 1L))
.isInstanceOf(UnsupportedOperationException.class);
}