Reduce technical debt add coverage 51/30051/2
authorPamela Dragosh <pdragosh@research.att.com>
Thu, 1 Feb 2018 20:10:57 +0000 (15:10 -0500)
committerPamela Dragosh <pdragosh@research.att.com>
Thu, 1 Feb 2018 21:34:30 +0000 (16:34 -0500)
* add empty constructor message
* remove unnecessary exception declaration
* add @FunctionalInterface declaration
* switched around public static per java conventions
* fixed up JUnit ordering
* added some trivial JUnit tests to bump coverage > 70%

Issue-ID: POLICY-460
Change-Id: I13b6de29f66d692143b06180feed76dd6332d6cf
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java [new file with mode: 0644]
policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java [new file with mode: 0644]
policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java

index 257d2da..681a2b2 100644 (file)
@@ -32,6 +32,10 @@ public class LoggerUtil {
    * Root logger
    */
   public static final String ROOT_LOGGER = "ROOT";
+  
+  private LoggerUtil() {
+         // Empty constructor
+  }
 
   /**
    * set the log level of a logger
index bd5b8aa..6734226 100644 (file)
@@ -39,6 +39,9 @@ public class NetworkUtil {
    */
   public static final String IPv4_WILDCARD_ADDRESS = "0.0.0.0";
 
+  private NetworkUtil() {
+         // Empty constructor
+  }
 
   /**
    * try to connect to $host:$port $retries times while we are getting connection failures.
index 75a3cd7..7a6ca0a 100644 (file)
@@ -25,6 +25,7 @@ package org.onap.policy.drools.utils;
  * of services (features) discovered via 'ServiceLoader'. See
  * 'OrderedServiceImpl' for more details.
  */
+@FunctionalInterface
 public interface OrderedService
 {
   /**
index 50135e8..bf59ec9 100644 (file)
@@ -45,8 +45,7 @@ public class ReflectionUtil {
         * @throws IllegalArgumentException if an invalid parameter has been passed in
         */
        public static Class<?> fetchClass(ClassLoader classLoader, 
-                                                 String className) 
-               throws IllegalArgumentException {
+                                                 String className) {
                if (classLoader == null)
                        throw new IllegalArgumentException("A class loader must be provided");
                
@@ -70,8 +69,7 @@ public class ReflectionUtil {
         * @return true if exists
         * @throws IllegalArgumentException if an invalid parameter has been passed in
         */
-       public static boolean isClass(ClassLoader classLoader, String classname) 
-           throws IllegalArgumentException {
+       public static boolean isClass(ClassLoader classLoader, String classname) {
                return fetchClass(classLoader, classname) != null;
        }
        
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java
new file mode 100644 (file)
index 0000000..d942a42
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 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.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class LoggerUtilTest {
+
+       @Test
+       public void test() {
+               assertNotNull(LoggerUtil.setLevel("foo", "warn"));
+       }
+
+}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java
new file mode 100644 (file)
index 0000000..c8b7735
--- /dev/null
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 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.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class NetworkUtilTest {
+
+       @Test
+       public void test() throws InterruptedException, IOException {
+               assertNotNull(NetworkUtil.IPv4_WILDCARD_ADDRESS);
+               assertFalse(NetworkUtil.isTcpPortOpen("localhost", 8080, 1, 5));
+       }
+
+}
index 1af831a..5063447 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.policy.drools.utils;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import org.junit.Test;
 
@@ -30,18 +31,20 @@ public class PairTripleTest {
     public void pairTest() {
         Pair<String, String> p = new Pair<String, String>("foo", "bar");
         
-       assertEquals(p.first(),"foo");
-       assertEquals(p.second(),"bar");
-       assertEquals(p.getFirst(),"foo");
-       assertEquals(p.getSecond(),"bar");
+       assertEquals("foo", p.first());
+       assertEquals("bar", p.second());
+       assertEquals("foo", p.getFirst());
+       assertEquals("bar", p.getSecond());
        
        p.first("one");
        p.second("two");
 
-       assertEquals(p.first(),"one");
-       assertEquals(p.second(),"two");
-       assertEquals(p.getFirst(),"one");
-       assertEquals(p.getSecond(),"two");
+       assertEquals("one", p.first());
+       assertEquals("two", p.second());
+       assertEquals("one", p.getFirst());
+       assertEquals("two", p.getSecond());
+       
+       assertNotNull(p.toString());
         
     } 
 
@@ -49,17 +52,17 @@ public class PairTripleTest {
     public void tripleTest() {
         Triple<String, String, String> t = new Triple<String, String,String>("foo", "bar", "fiz");
         
-       assertEquals(t.first(),"foo");
-       assertEquals(t.second(),"bar");
-       assertEquals(t.third(),"fiz");
+       assertEquals("foo", t.first());
+       assertEquals("bar", t.second());
+       assertEquals("fiz", t.third());
        
        t.first("one");
        t.second("two");
        t.third("three");
 
-       assertEquals(t.first(),"one");
-       assertEquals(t.second(),"two");
-       assertEquals(t.third(),"three");   
+       assertEquals("one", t.first());
+       assertEquals("two", t.second());
+       assertEquals("three", t.third());   
     }
 
 }
index ab4bace..0cb5106 100644 (file)
@@ -21,6 +21,7 @@ package org.onap.policy.drools.utils;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -58,5 +59,26 @@ public class ReflectionUtilTest {
             fail();
         }
     }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void testException1() {
+       ReflectionUtil.fetchClass(null, "org.onap.policy.drools.utils.ReflectionUtil");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testException2() {
+        Class<?> class1;
+               try {
+                       class1 = Class.forName("org.onap.policy.drools.utils.ReflectionUtil");
+               ClassLoader classLoader = class1.getClassLoader();
+               ReflectionUtil.fetchClass(classLoader, null);
+               } catch (ClassNotFoundException e) {
+                       fail();
+               }
+    }
 
+    @Test
+    public void testException3() throws ClassNotFoundException {
+       assertNull(ReflectionUtil.fetchClass(ClassLoader.getSystemClassLoader(), "foo.bar"));
+    }
 }