diff options
author | 2018-02-01 15:10:57 -0500 | |
---|---|---|
committer | 2018-02-01 16:34:30 -0500 | |
commit | 8309dc93f39f8fbe5ba899f8311781ab9729986d (patch) | |
tree | 2db3c3c628a731540b4f3061d5af133467d0b7f6 /policy-utils/src/test/java/org/onap | |
parent | b8cf385b8df2ab67e345bbf16f30117dc0afe4c9 (diff) |
Reduce technical debt add coverage
* 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>
Diffstat (limited to 'policy-utils/src/test/java/org/onap')
4 files changed, 109 insertions, 14 deletions
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 index 00000000..d942a427 --- /dev/null +++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java @@ -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 index 00000000..c8b7735b --- /dev/null +++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java @@ -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)); + } + +} diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java index 1af831ad..5063447c 100644 --- a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java +++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java @@ -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()); } } diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java index ab4bace5..0cb51060 100644 --- a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java +++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java @@ -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")); + } } |