From cf36274c5ae0bc569ec7ebe2cb4e8f579763cc14 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Thu, 28 Sep 2023 14:25:43 +0100 Subject: Fix security vulnerabilities - iq nexus vulnerabilities - sonar security hotspots and code smell Issue-ID: POLICY-4761 Issue-ID: POLICY-4833 Change-Id: Iab2e07d2ee7b90031bc5a30210ce7d3f5a47b3fd Signed-off-by: adheli.tavares --- .../event/comm/bus/internal/BusConsumerTest.java | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java') diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java index 94e7c0c7..86b32e69 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java @@ -26,6 +26,7 @@ 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.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -66,7 +67,7 @@ public class BusConsumerTest extends TopicTestBase { } @Test - public void testFetchingBusConsumer() throws InterruptedException { + public void testFetchingBusConsumer() { // should not be negative var cons = new FetchingBusConsumerImpl(makeBuilder().fetchTimeout(-1).build()); assertThat(cons.getSleepTime()).isEqualTo(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH); @@ -174,7 +175,7 @@ public class BusConsumerTest extends TopicTestBase { @Test public void testCambriaConsumerWrapperClose() { CambriaConsumerWrapper cons = new CambriaConsumerWrapper(builder.build()); - assertThatCode(() -> cons.close()).doesNotThrowAnyException(); + assertThatCode(cons::close).doesNotThrowAnyException(); } @Test @@ -183,7 +184,7 @@ public class BusConsumerTest extends TopicTestBase { } @Test - public void testDmaapConsumerWrapper() throws Exception { + public void testDmaapConsumerWrapper() { // verify that different wrappers can be built assertThatCode(() -> new DmaapAafConsumerWrapper(makeBuilder().build())).doesNotThrowAnyException(); } @@ -229,7 +230,7 @@ public class BusConsumerTest extends TopicTestBase { } @Test - public void testDmaapConsumerWrapperClose() throws Exception { + public void testDmaapConsumerWrapperClose() { assertThatCode(() -> new DmaapAafConsumerWrapper(makeBuilder().build()).close()).doesNotThrowAnyException(); } @@ -301,18 +302,18 @@ public class BusConsumerTest extends TopicTestBase { } @Test - public void testKafkaConsumerWrapper() throws Exception { + public void testKafkaConsumerWrapper() { // verify that different wrappers can be built assertThatCode(() -> new KafkaConsumerWrapper(makeKafkaBuilder().build())).doesNotThrowAnyException(); } @Test(expected = IllegalArgumentException.class) - public void testKafkaConsumerWrapper_InvalidTopic() throws Exception { + public void testKafkaConsumerWrapper_InvalidTopic() { new KafkaConsumerWrapper(makeBuilder().topic(null).build()); } - @Test(expected = java.lang.IllegalStateException.class) - public void testKafkaConsumerWrapperFetch() throws Exception { + @Test + public void testKafkaConsumerWrapperFetch() { //Setup Properties for consumer Properties kafkaProps = new Properties(); @@ -331,17 +332,17 @@ public class BusConsumerTest extends TopicTestBase { KafkaConsumer consumer = new KafkaConsumer<>(kafkaProps); kafka.consumer = consumer; - assertFalse(kafka.fetch().iterator().hasNext()); + assertThrows(java.lang.IllegalStateException.class, () -> kafka.fetch().iterator().hasNext()); consumer.close(); } @Test - public void testKafkaConsumerWrapperClose() throws Exception { + public void testKafkaConsumerWrapperClose() { assertThatCode(() -> new KafkaConsumerWrapper(makeKafkaBuilder().build()).close()).doesNotThrowAnyException(); } @Test - public void testKafkaConsumerWrapperToString() throws Exception { + public void testKafkaConsumerWrapperToString() { assertNotNull(new KafkaConsumerWrapper(makeKafkaBuilder().build()) {}.toString()); } @@ -352,7 +353,7 @@ public class BusConsumerTest extends TopicTestBase { } @Override - public Iterable fetch() throws IOException { + public Iterable fetch() { return null; } } -- cgit 1.2.3-korg