Fix more sonar issues in models: yaml to dao
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / PfConceptGetterImplTest.java
index ae5b2ff..b373e41 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.
 
 package org.onap.policy.models.base;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
 
 import java.util.NavigableMap;
 import java.util.TreeMap;
 import java.util.TreeSet;
-
 import org.junit.Test;
 
 /**
@@ -36,6 +36,9 @@ import org.junit.Test;
  */
 public class PfConceptGetterImplTest {
 
+    private static final String VERSION002 = "0.0.2";
+    private static final String VERSION001 = "0.0.1";
+
     @Test
     public void testPfConceptGetterImpl() {
         NavigableMap<PfConceptKey, PfConceptKey> keyMap = new TreeMap<>();
@@ -43,54 +46,42 @@ public class PfConceptGetterImplTest {
         PfConceptGetterImpl<PfConceptKey> getter = new PfConceptGetterImpl<>(keyMap);
         assertNotNull(getter);
 
-        PfConceptKey keyA = new PfConceptKey("A", "0.0.1");
+        PfConceptKey keyA = new PfConceptKey("A", VERSION001);
         assertNull(getter.get(keyA));
 
-        try {
-            getter.get((String)null);
-            fail("test should throw an exception here");
-        }
-        catch (Exception getException) {
-            assertEquals("conceptKeyName may not be null", getException.getMessage());
-        }
+        assertThatThrownBy(() -> getter.get((String) null)).hasMessage("conceptKeyName may not be null");
 
         assertNull(getter.get("W"));
 
-        PfConceptKey keyZ = new PfConceptKey("Z", "0.0.1");
+        PfConceptKey keyZ = new PfConceptKey("Z", VERSION001);
         keyMap.put(keyZ, keyZ);
         assertNull(getter.get("W"));
 
-        PfConceptKey keyW001 = new PfConceptKey("W", "0.0.1");
+        PfConceptKey keyW001 = new PfConceptKey("W", VERSION001);
         keyMap.put(keyW001, keyW001);
         assertEquals(keyW001, getter.get("W"));
 
-        PfConceptKey keyW002 = new PfConceptKey("W", "0.0.2");
+        PfConceptKey keyW002 = new PfConceptKey("W", VERSION002);
         keyMap.put(keyW002, keyW002);
         assertEquals(keyW002, getter.get("W"));
 
         keyMap.remove(keyZ);
         assertEquals(keyW002, getter.get("W"));
 
-        try {
-            getter.get((String)null, "0.0.1");
-            fail("test should throw an exception here");
-        }
-        catch (Exception getException) {
-            assertEquals("conceptKeyName may not be null", getException.getMessage());
-        }
+        assertThatThrownBy(() -> getter.get((String) null, VERSION001)).hasMessage("conceptKeyName may not be null");
 
-        assertEquals(keyW002, getter.get("W", "0.0.2"));
+        assertEquals(keyW002, getter.get("W", VERSION002));
         assertEquals(keyW002, getter.get("W", (String)null));
 
         assertEquals(new TreeSet<PfConceptKey>(keyMap.values()), getter.getAll(null));
         assertEquals(new TreeSet<PfConceptKey>(keyMap.values()), getter.getAll(null, null));
 
         assertEquals(keyW001, getter.getAll("W", null).iterator().next());
-        assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
+        assertEquals(keyW002, getter.getAll("W", VERSION002).iterator().next());
         assertEquals(0, getter.getAll("A", null).size());
         assertEquals(0, getter.getAll("Z", null).size());
 
         keyMap.put(keyZ, keyZ);
-        assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
+        assertEquals(keyW002, getter.getAll("W", VERSION002).iterator().next());
     }
 }