From 63d23a4aa0f3aeae9d6470b95dfa8f87b2d85aa8 Mon Sep 17 00:00:00 2001 From: waynedunican Date: Mon, 12 Aug 2024 21:18:12 +0100 Subject: Fix sonar issues in common - SONAR Fix instanceOf issues - SONAR Remove public modifiers - SONAR Remove unused imports - SONAR Remove exceptions that can't be thrown from method body Issue-ID: POLICY-5106 Change-Id: I745d0101036d3421f02db22481514be0b79f5103 Signed-off-by: waynedunican --- .../onap/policy/common/utils/io/SerializerTest.java | 2 +- .../utils/security/SelfSignedKeyStoreTest.java | 12 ++++++------ .../policy/common/utils/time/TestTimeMultiTest.java | 12 ++++++------ .../onap/policy/common/utils/time/TestTimeTest.java | 4 ++-- .../onap/policy/common/utils/time/WorkItemTest.java | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) (limited to 'utils-test/src/test') diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java index 25461daf..602df359 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java @@ -361,7 +361,7 @@ class SerializerTest { @Test void testRoundTrip() throws Exception { - MyObject obj1 = new MyObject(3); + MyObject obj1 = new MyObject(4); MyObject obj2 = Serializer.roundTrip(obj1); assertEquals(obj1.value, obj2.value); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java index 8a3dfe39..1af69cd0 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java @@ -57,7 +57,7 @@ public class SelfSignedKeyStoreTest { } @Test - public void testSelfSignedKeyStore() throws Exception { + void testSelfSignedKeyStore() throws Exception { SelfSignedKeyStore ks = new SelfSignedKeyStore(); assertThat(ks.getKeystoreName()).isEqualTo(defaultName); @@ -65,7 +65,7 @@ public class SelfSignedKeyStoreTest { } @Test - public void testSelfSignedKeyStoreString() throws IOException, InterruptedException { + void testSelfSignedKeyStoreString() throws IOException, InterruptedException { String relName = "target/my-keystore"; String altName = saveUserDir + "/" + relName; File altFile = new File(altName); @@ -82,7 +82,7 @@ public class SelfSignedKeyStoreTest { * Tests the constructor, when the keystore already exists. */ @Test - public void testSelfSignedKeyStoreStringExists() throws Exception { + void testSelfSignedKeyStoreStringExists() throws Exception { new SelfSignedKeyStore(); assertThat(defaultKeystore).exists(); @@ -109,7 +109,7 @@ public class SelfSignedKeyStoreTest { * Tests the constructor, when the SAN file is not found. */ @Test - public void testSelfSignedKeyStoreStringNoSanFile() { + void testSelfSignedKeyStoreStringNoSanFile() { assertThatThrownBy(() -> new SelfSignedKeyStore() { @Override protected String getKeystoreSanName() { @@ -122,13 +122,13 @@ public class SelfSignedKeyStoreTest { * Tests the constructor, when write fails. */ @Test - public void testSelfSignedKeyStoreStringWriteFailure() { + void testSelfSignedKeyStoreStringWriteFailure() { assertThatThrownBy(() -> new SelfSignedKeyStore("target/unknown/path/to/keystore")) .isInstanceOf(IOException.class); } @Test - public void testGetKeystoreName() throws Exception { + void testGetKeystoreName() throws Exception { String relpath = SelfSignedKeyStore.RELATIVE_PATH; // append the first part of the relative path to user.dir diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java index f6d1e6a4..1b9728d4 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java @@ -115,7 +115,7 @@ class TestTimeMultiTest { } @Test - void testDestroy() throws InterruptedException { + void testDestroy() { // this won't interrupt multi.enqueue(new WorkItem(multi, DELAY_MS)); @@ -193,7 +193,7 @@ class TestTimeMultiTest { } @Test - void testWaitUntilCallable() throws InterruptedException { + void testWaitUntilCallable() { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); @@ -238,7 +238,7 @@ class TestTimeMultiTest { } @Test - void testWaitUntilCallable_ConditionThrowsEx() throws InterruptedException { + void testWaitUntilCallable_ConditionThrowsEx() { multi = new TestTimeMulti(); Callable callable = () -> { @@ -253,7 +253,7 @@ class TestTimeMultiTest { } @Test - void testWaitUntilCallable_NeverSatisfied() throws InterruptedException { + void testWaitUntilCallable_NeverSatisfied() { multi = new TestTimeMulti(SHORT_WAIT_MS); final long realBegin = System.currentTimeMillis(); @@ -263,7 +263,7 @@ class TestTimeMultiTest { } @Test - void testWaitUntilLongTimeUnitCallable() throws InterruptedException { + void testWaitUntilLongTimeUnitCallable() { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); @@ -280,7 +280,7 @@ class TestTimeMultiTest { } @Test - void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() throws InterruptedException { + void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java index c3b69eb3..dbf077c5 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java @@ -26,10 +26,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; -public class TestTimeTest { +class TestTimeTest { @Test - public void test() throws Exception { + void test() throws Exception { TestTime tm = new TestTime(); TestTime tm2 = new TestTime(); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java index f0229ca9..a5683a64 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java @@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class WorkItemTest { +class WorkItemTest { private TestTime currentTime; private WorkItem item; @@ -40,7 +40,7 @@ public class WorkItemTest { } @Test - public void testWorkItem() { + void testWorkItem() { assertThatIllegalArgumentException().isThrownBy(() -> new WorkItem(currentTime, -1)); // should not throw an exception @@ -48,22 +48,22 @@ public class WorkItemTest { } @Test - public void testGetDelay() { + void testGetDelay() { assertEquals(1, item.getDelay()); } @Test - public void testWasCancelled() { + void testWasCancelled() { assertFalse(item.wasCancelled()); } @Test - public void testBumpNextTime() { + void testBumpNextTime() { assertFalse(item.bumpNextTime()); } @Test - public void testBumpNextTimeLong() { + void testBumpNextTimeLong() { assertThatIllegalArgumentException().isThrownBy(() -> item.bumpNextTime(-1)); long cur = currentTime.getMillis(); @@ -77,24 +77,24 @@ public class WorkItemTest { } @Test - public void testInterrupt() { + void testInterrupt() { item.interrupt(); assertFalse(Thread.interrupted()); } @Test - public void testIsAssociatedWith() { + void testIsAssociatedWith() { assertFalse(item.isAssociatedWith(this)); } @Test - public void testFire() { + void testFire() { // ensure no exception is thrown assertThatCode(() -> item.fire()).doesNotThrowAnyException(); } @Test - public void testGetNextMs() { + void testGetNextMs() { assertEquals(currentTime.getMillis() + 1, item.getNextMs()); assertEquals(currentTime.getMillis() + 10, new WorkItem(currentTime, 10).getNextMs()); } -- cgit 1.2.3-korg