diff options
author | lapentafd <francesco.lapenta@est.tech> | 2021-03-18 12:06:14 +0000 |
---|---|---|
committer | lapentafd <francesco.lapenta@est.tech> | 2021-03-19 11:04:35 +0000 |
commit | 7a03b4a98e74635ba9cf75ac360be0749c1d98cf (patch) | |
tree | 3d43bcd2733d475c4590c64cf48b75b759d7e4b4 /models-base/src/test/java/org | |
parent | 78ff3ea9ac44ea53db673376d67841ad7f411c43 (diff) |
Fix sonar issues for tests in policy-models
Tests refactoring to reduce number of assertions
Issue-ID: POLICY-3094
Change-Id: I445462f0ec5d49474b10c1940c7fa12e687636de
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'models-base/src/test/java/org')
-rw-r--r-- | models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java | 23 | ||||
-rw-r--r-- | models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java | 24 |
2 files changed, 34 insertions, 13 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index de328e9f2..ce1c3e888 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,7 +42,7 @@ public class PfReferenceKeyTest { private static final String VERSION001 = "0.0.1"; @Test - public void testPfReferenceKey() { + public void testPfReferenceKeyNotNull() { assertNotNull(new PfReferenceKey()); assertNotNull(new PfReferenceKey(new PfConceptKey())); assertNotNull(new PfReferenceKey(new PfConceptKey(), LOCAL_NAME)); @@ -57,7 +57,10 @@ public class PfReferenceKeyTest { assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null)) .hasMessage("parameter \"localName\" is null"); + } + @Test + public void testPfReferenceKey() { PfReferenceKey testReferenceKey = new PfReferenceKey(); testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId()); @@ -96,7 +99,11 @@ public class PfReferenceKeyTest { assertEquals(PfKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey)); assertTrue(testReferenceKey.validate("").isValid()); + } + @Test + public void testMultiplePfReferenceKey() { + PfReferenceKey testReferenceKey = setTestReferenceKey(); testReferenceKey.clean(); PfReferenceKey clonedReferenceKey = new PfReferenceKey(testReferenceKey); @@ -172,4 +179,16 @@ public class PfReferenceKeyTest { assertThat(validationResult4.getResult()).contains("\"localName\"") .contains("does not match regular expression [A-Za-z0-9\\-_\\.]+|^$"); } + + private PfReferenceKey setTestReferenceKey() { + PfReferenceKey testReferenceKey = new PfReferenceKey(); + testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); + testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001, "LN")); + testReferenceKey.setParentKeyName("NPKN"); + testReferenceKey.setParentKeyVersion(VERSION001); + testReferenceKey.setParentLocalName(NPKLN); + testReferenceKey.setLocalName("NLN"); + + return testReferenceKey; + } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java index 4afdadff3..79f271c9c 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java @@ -59,17 +59,6 @@ public class PfTimestampKeyTest { assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); - - assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class) - .hasMessageMatching(CONCEPT_IS_NULL); - assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class) - .hasMessageMatching(NAME_IS_NULL); - assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class) - .hasMessageMatching(VERSION_IS_NULL); - assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null)) - .isInstanceOf(NullPointerException.class) - .hasMessageMatching("^instant is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) .hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) @@ -94,4 +83,17 @@ public class PfTimestampKeyTest { assertFalse(someKey4.isNullKey()); assertFalse(someKey1.isNullKey()); } + + @Test + public void testTimestampKeyErrors() { + assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class) + .hasMessageMatching(CONCEPT_IS_NULL); + assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class) + .hasMessageMatching(NAME_IS_NULL); + assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class) + .hasMessageMatching(VERSION_IS_NULL); + assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null)) + .isInstanceOf(NullPointerException.class) + .hasMessageMatching("^instant is marked .*on.*ull but is null$"); + } } |