From ea262e6da52fd4da0733f02998f87aebaf502ddb Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 12 Jun 2019 14:32:25 -0400 Subject: Apply simple sonar fixes Note: A number of these were identified, by SonarLint, in the Test classes, which are not typically scanned by Sonar. Removed unnecessary imports. Removed unneeded "throws Xxx". Replaced lambda with method references. Replaced duplicate strings with constants. Replaced try-fail-catch with assert-j methods to eliminate sonar complaints about duplicate failure messages. Added missing @Override annotations. Use map.computeIfAbsent() where appropriate. Also fixed some minor checkstyle issues. Removed unneeded "volatile" declarations. Replaced some if-else constructs with "?:" construct, per sonar. Replaced Object.wait() with CountDownLatch.await(); according to sonar (and javadocs), Object.wait() can return due to "spurious wakeups". Fixed issue whereby CryptoUtilsTest wouldn't run in my Eclipse. Change-Id: Ib6b71ed65662cfd6209400dac57ed69279bf29ec Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn --- .../endpoints/event/comm/bus/BusTopicFactoryTestBase.java | 6 +++--- .../endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java | 8 +++++++- .../endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java | 10 ++++++++-- .../endpoints/event/comm/bus/internal/BusConsumerTest.java | 11 ++++++++--- .../endpoints/event/comm/bus/internal/BusPublisherTest.java | 9 +++++---- .../endpoints/event/comm/bus/internal/BusTopicBaseTest.java | 1 + .../endpoints/event/comm/bus/internal/BusTopicParamsTest.java | 3 ++- .../event/comm/bus/internal/InlineBusTopicSinkTest.java | 1 + .../event/comm/bus/internal/InlineDmaapTopicSinkTest.java | 1 + .../event/comm/bus/internal/InlineUebTopicSinkTest.java | 1 + 10 files changed, 37 insertions(+), 14 deletions(-) (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event') diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java index 919397d9..b5c9e614 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java @@ -34,7 +34,7 @@ import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperti import java.util.Arrays; import java.util.List; import java.util.Properties; -import java.util.function.Function; +import java.util.function.Predicate; import org.onap.policy.common.endpoints.event.comm.Topic; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; @@ -192,7 +192,7 @@ public abstract class BusTopicFactoryTestBase extends TopicFact * @param values the values to which the property should be set, defaults to * {@code null} and "" */ - protected void checkDefault(String builderName, Function validate, Object... values) { + protected void checkDefault(String builderName, Predicate validate, Object... values) { Object[] values2 = (values.length > 0 ? values : new Object[] {null, ""}); for (Object value : values2) { @@ -209,7 +209,7 @@ public abstract class BusTopicFactoryTestBase extends TopicFact } assertEquals("size for default " + value, 1, buildTopics(builder.build()).size()); - assertTrue("default for " + value, validate.apply(getLastParams())); + assertTrue("default for " + value, validate.test(getLastParams())); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java index b4c7fff8..6c9dfcbd 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -41,6 +41,7 @@ public class DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase params2.getFetchLimit() == DmaapTopicSource.DEFAULT_LIMIT_FETCH, null, "", "invalid-limit-number"); - + checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX, params2 -> params2.getFetchTimeout() == DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, null, "", "invalid-timeout-number"); @@ -99,6 +102,7 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase