Sonar Fixes policy/models, removing model-yaml
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / PfReferenceKeyTest.java
index 21b82fc..c1c13c8 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -54,7 +54,7 @@ public class PfReferenceKeyTest {
         assertEquals("NULL:0.0.0:NULL:NULL", PfReferenceKey.getNullKey().getId());
 
         assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null))
-                        .hasMessage("parameter \"localName\" is null");
+            .hasMessage("parameter \"localName\" is null");
 
         PfReferenceKey testReferenceKey = new PfReferenceKey();
         testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001));
@@ -83,7 +83,7 @@ public class PfReferenceKeyTest {
         assertEquals("NLN", testReferenceKey.getLocalName());
 
         assertThatThrownBy(() -> testReferenceKey.isCompatible(null))
-                        .hasMessage("otherKey is marked @NonNull but is null");
+            .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
 
         assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey()));
         assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey()));
@@ -101,18 +101,18 @@ public class PfReferenceKeyTest {
 
         PfReferenceKey clonedReferenceKey = new PfReferenceKey(testReferenceKey);
         assertEquals("PfReferenceKey(parentKeyName=NPKN, parentKeyVersion=0.0.1, parentLocalName=NPKLN, localName=NLN)",
-                clonedReferenceKey.toString());
+            clonedReferenceKey.toString());
 
-        assertFalse(testReferenceKey.hashCode() == 0);
+        assertNotEquals(0, testReferenceKey.hashCode());
 
-        assertTrue(testReferenceKey.equals(testReferenceKey));
-        assertTrue(testReferenceKey.equals(clonedReferenceKey));
-        assertFalse(testReferenceKey.equals("Hello"));
-        assertFalse(testReferenceKey.equals(new PfReferenceKey("PKN", VERSION002, "PLN", "LN")));
-        assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION002, "PLN", "LN")));
-        assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, "PLN", "LN")));
-        assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN")));
-        assertTrue(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN")));
+        assertEquals(testReferenceKey, testReferenceKey);
+        assertEquals(testReferenceKey, clonedReferenceKey);
+        assertNotEquals(testReferenceKey, (Object) "Hello");
+        assertNotEquals(testReferenceKey, new PfReferenceKey("PKN", VERSION002, "PLN", "LN"));
+        assertNotEquals(testReferenceKey, new PfReferenceKey("NPKN", VERSION002, "PLN", "LN"));
+        assertNotEquals(testReferenceKey, new PfReferenceKey("NPKN", VERSION001, "PLN", "LN"));
+        assertNotEquals(testReferenceKey, new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN"));
+        assertEquals(testReferenceKey, new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN"));
 
         assertEquals(0, testReferenceKey.compareTo(testReferenceKey));
         assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey));
@@ -123,16 +123,11 @@ public class PfReferenceKeyTest {
         assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN")));
         assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN")));
 
-        assertFalse(testReferenceKey.equals(null));
+        assertNotEquals(testReferenceKey, null);
 
-        assertThatThrownBy(() -> testReferenceKey.copyTo(null)).hasMessage("target may not be null");
+        assertThatThrownBy(() -> new PfReferenceKey((PfReferenceKey) null)).isInstanceOf(NullPointerException.class);
 
-        assertThatThrownBy(() -> testReferenceKey.copyTo(new PfConceptKey("Key", VERSION001)))
-                        .hasMessage("org.onap.policy.models.base.PfConceptKey"
-                                        + " is not an instance of org.onap.policy.models.base.PfReferenceKey");
-
-        PfReferenceKey targetRefKey = new PfReferenceKey();
-        assertEquals(testReferenceKey, testReferenceKey.copyTo(targetRefKey));
+        assertEquals(testReferenceKey, new PfReferenceKey(testReferenceKey));
     }
 
     @Test
@@ -149,9 +144,9 @@ public class PfReferenceKeyTest {
         parentNameField.set(testReferenceKey, "ParentName");
         parentNameField.setAccessible(false);
         assertEquals(
-                "parentKeyName invalid-parameter parentKeyName with value Parent Name "
-                        + "does not match regular expression " + PfKey.NAME_REGEXP,
-                validationResult.getMessageList().get(0).getMessage());
+            "parentKeyName invalid-parameter parentKeyName with value Parent Name "
+                + "does not match regular expression " + PfKey.NAME_REGEXP,
+            validationResult.getMessageList().get(0).getMessage());
 
         Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion");
         parentVersionField.setAccessible(true);
@@ -161,9 +156,9 @@ public class PfReferenceKeyTest {
         parentVersionField.set(testReferenceKey, VERSION001);
         parentVersionField.setAccessible(false);
         assertEquals(
-                "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
-                        + "does not match regular expression " + PfKey.VERSION_REGEXP,
-                validationResult2.getMessageList().get(0).getMessage());
+            "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
+                + "does not match regular expression " + PfKey.VERSION_REGEXP,
+            validationResult2.getMessageList().get(0).getMessage());
 
         Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName");
         parentLocalNameField.setAccessible(true);
@@ -173,9 +168,9 @@ public class PfReferenceKeyTest {
         parentLocalNameField.set(testReferenceKey, PARENT_LOCAL_NAME);
         parentLocalNameField.setAccessible(false);
         assertEquals(
-                "parentLocalName invalid-parameter parentLocalName with value "
-                        + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
-                validationResult3.getMessageList().get(0).getMessage());
+            "parentLocalName invalid-parameter parentLocalName with value "
+                + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
+            validationResult3.getMessageList().get(0).getMessage());
 
         Field localNameField = testReferenceKey.getClass().getDeclaredField("localName");
         localNameField.setAccessible(true);
@@ -185,8 +180,8 @@ public class PfReferenceKeyTest {
         localNameField.set(testReferenceKey, LOCAL_NAME);
         localNameField.setAccessible(false);
         assertEquals(
-                "localName invalid-parameter localName with value Local Name "
-                        + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
-                validationResult4.getMessageList().get(0).getMessage());
+            "localName invalid-parameter localName with value Local Name "
+                + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
+            validationResult4.getMessageList().get(0).getMessage());
     }
 }