diff options
author | Jim Hahn <jrh3@att.com> | 2021-03-24 12:41:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-03-24 12:41:04 +0000 |
commit | 2d52d7da138050735cd54d2c1c2ee03d1e473262 (patch) | |
tree | efd56c81b1a40bb6452332b0377bf0802cf92678 /models-base | |
parent | b0fc73fd9ff6d9727c0f93a7ad0a742b704b4c9d (diff) | |
parent | 7a03b4a98e74635ba9cf75ac360be0749c1d98cf (diff) |
Merge "Fix sonar issues for tests in policy-models"
Diffstat (limited to 'models-base')
-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$"); + } } |