Changes for Checkstyle 8.32
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / persistence / concepts / JpaPdpGroupTest.java
index c0545fa..1daadcf 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 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.
@@ -31,7 +32,6 @@ import static org.junit.Assert.assertTrue;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
-
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
@@ -47,87 +47,90 @@ import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
  */
 public class JpaPdpGroupTest {
 
+    private static final String NULL_ERROR = " is marked .*ull but is null";
+    private static final String NULL_KEY_ERROR = "key" + NULL_ERROR;
+    private static final String PDP_GROUP0 = "PDPGroup0";
+    private static final String VERSION = "1.0.0";
+
     @Test
     public void testJpaPdpGroup() {
         assertThatThrownBy(() -> {
             new JpaPdpGroup((JpaPdpGroup) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        }).hasMessageMatching("copyConcept" + NULL_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup((PfConceptKey) null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup((PdpGroup) null);
-        }).hasMessage("authorativeConcept is marked @NonNull but is null");
+        }).hasMessageMatching("authorativeConcept" + NULL_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup((JpaPdpGroup) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        }).hasMessageMatching("copyConcept" + NULL_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(null, null, null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(new PfConceptKey(), null, null);
-        }).hasMessage("pdpGroupState is marked @NonNull but is null");
+        }).hasMessageMatching("pdpGroupState" + NULL_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(new PfConceptKey(), PdpState.PASSIVE, null);
-        }).hasMessage("pdpSubGroups is marked @NonNull but is null");
+        }).hasMessageMatching("pdpSubGroups" + NULL_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(null, PdpState.PASSIVE, null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(null, PdpState.PASSIVE, new ArrayList<>());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpGroup(null, null, new ArrayList<>());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertNotNull(new JpaPdpGroup((new PfConceptKey())));
         assertNotNull(new JpaPdpGroup((new JpaPdpGroup())));
 
         PdpGroup testPdpGroup = new PdpGroup();
-        testPdpGroup.setName("PDPGroup0");
+        testPdpGroup.setName(PDP_GROUP0);
         testPdpGroup.setPdpSubgroups(new ArrayList<>());
         JpaPdpGroup testJpaPdpGroup = new JpaPdpGroup();
         testJpaPdpGroup.setKey(null);
 
         testJpaPdpGroup.setKey(new PfConceptKey());
 
-        testPdpGroup.setVersion("1.0.0");
+        testPdpGroup.setVersion(VERSION);
         testJpaPdpGroup.fromAuthorative(testPdpGroup);
 
-        assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
+        assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
         testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
         testJpaPdpGroup.fromAuthorative(testPdpGroup);
 
         assertThatThrownBy(() -> {
             testJpaPdpGroup.fromAuthorative(null);
-        }).hasMessage("pdpGroup is marked @NonNull but is null");
+        }).hasMessageMatching("pdpGroup" + NULL_ERROR);
 
-        testJpaPdpGroup.setKey(new PfConceptKey("PDPGroup0", "1.0.0"));
+        testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION));
         testJpaPdpGroup.fromAuthorative(testPdpGroup);
 
-        assertThatThrownBy(() -> {
-            testJpaPdpGroup.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaPdpGroup((JpaPdpGroup) null)).isInstanceOf(NullPointerException.class);
 
-        assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
-        assertEquals("PDPGroup0", new JpaPdpGroup(testPdpGroup).getKey().getName());
-        assertEquals("PDPGroup0", ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName());
+        assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
+        assertEquals(PDP_GROUP0, new JpaPdpGroup(testPdpGroup).getKey().getName());
+        assertEquals(PDP_GROUP0, ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName());
 
         testJpaPdpGroup.clean();
-        assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
+        assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
 
         assertThatThrownBy(() -> {
             testJpaPdpGroup.validate(null);
-        }).hasMessage("resultIn is marked @NonNull but is null");
+        }).hasMessageMatching("resultIn" + NULL_ERROR);
 
         assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
         testJpaPdpGroup.setPdpGroupState(PdpState.PASSIVE);
@@ -135,7 +138,7 @@ public class JpaPdpGroupTest {
 
         testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
         assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
-        testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", "1.0.0"));
+        testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", VERSION));
         assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
 
         testJpaPdpGroup.setDescription("   ");
@@ -225,5 +228,7 @@ public class JpaPdpGroupTest {
         assertEquals(2, testJpaPdpGroup.getKeys().size());
         testJpaPdpGroup.clean();
         assertEquals(2, testJpaPdpGroup.getKeys().size());
+
+        assertEquals(testJpaPdpGroup, new JpaPdpGroup(testJpaPdpGroup));
     }
 }