From 51f1fffd687e53c858685ec41fd3ab8cfd4fcdf1 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 1 Sep 2021 11:45:05 -0400 Subject: Fix sonars in apex-pdp #3 Fixed: - use "var" - use assertEquals instead of assertTrue(xxx.equals()) - separate assertions Issue-ID: POLICY-3093 Change-Id: Id4db62626948681cd267e68a56dda65fa355c6f8 Signed-off-by: Jim Hahn --- .../apex/context/test/concepts/TestContextDateItem.java | 3 ++- .../context/distribution/ContextInstantiation.java | 12 +++++++----- .../integration/context/distribution/ContextUpdate.java | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'testsuites/integration') diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java index 13cefaa58..a62d348f2 100644 --- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java +++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -101,7 +102,7 @@ public class TestContextDateItem implements Serializable { public void setDateValue(final long dateValue) { this.time = dateValue; - final Calendar calendar = Calendar.getInstance(); + final var calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(time); diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java index 5561dbece..fa3612fe9 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextInstantiation.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -21,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.context.distribution; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -274,16 +276,16 @@ public class ContextInstantiation { externalContextOther.setTestExternalContextItem002(new TestContextIntItem()); externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2); - assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther).equals(externalContext)); + assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther)).isEqualTo(externalContext); externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT); assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue()); - assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext).equals(externalContextOther)); + assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext)).isEqualTo(externalContextOther); externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT); assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue()); assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null)) .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()"); - assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext)); + assertThat(externalContextAlbum.get(EXTERNAL_CONTEXT)).isEqualTo(externalContext); assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null)) .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()"); @@ -477,11 +479,11 @@ public class ContextInstantiation { } private void assertFloat(final float actual, final float expected) { - assertTrue(Float.compare(actual, expected) == 0); + assertThat(actual).isEqualTo(expected); } private void assertDouble(final double actual, final double expected) { - assertTrue(Double.compare(actual, expected) == 0); + assertThat(actual).isEqualTo(expected); } private Distributor getDistributor() throws ContextException { diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java index ae662f293..b0370c5d9 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -21,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.context.distribution; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -97,10 +99,10 @@ public class ContextUpdate { .hasMessage("album \"LongContextAlbum:0.0.1\" null keys are illegal on keys for put()"); assertNull(dateContextAlbum.put("date0", tciA)); - assertTrue(dateContextAlbum.put("date0", tciA).equals(tciA)); + assertThat(dateContextAlbum.put("date0", tciA)).isEqualTo(tciA); assertNull(mapContextAlbum.put("map0", tciC)); - assertTrue(mapContextAlbum.put("map0", tciC).equals(tciC)); + assertThat(mapContextAlbum.put("map0", tciC)).isEqualTo(tciC); contextDistributor.clear(); } -- cgit 1.2.3-korg