Add junit coverage to UnmodifiableProperties class 61/40561/3
authorJohn McClung <jm1364@att.com>
Mon, 2 Apr 2018 19:30:49 +0000 (15:30 -0400)
committerTakamune Cho <tc012c@att.com>
Mon, 2 Apr 2018 23:59:10 +0000 (23:59 +0000)
Introduce junit-tests for UnmodifiableProperties class

Change-Id: I51f44c676a0cd8fef808ca2e33fea8afc7e52453
Issue-ID: APPC-820
Signed-off-by: John McClung <jm1364@att.com>
appc-common/src/test/java/org/onap/appc/util/UnmodifiablePropertiesTest.java [new file with mode: 0644]

diff --git a/appc-common/src/test/java/org/onap/appc/util/UnmodifiablePropertiesTest.java b/appc-common/src/test/java/org/onap/appc/util/UnmodifiablePropertiesTest.java
new file mode 100644 (file)
index 0000000..d238dc3
--- /dev/null
@@ -0,0 +1,174 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : APPC\r
+ * ================================================================================\r
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * =============================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.appc.util;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import java.util.Properties;\r
+\r
+public class UnmodifiablePropertiesTest {\r
+\r
+    private static final String propKey1 = "testKey1";\r
+    private static final String propKey2 = "testKey2";\r
+    private static final String propValue1 = "testValue1";\r
+    private static final String propValue2 = "testValue2";\r
+    private static final String noKey = "unusedKey";\r
+    private static final String noValue = "unusedValue";\r
+    private Properties properties = new Properties();\r
+\r
+    private UnmodifiableProperties unmodifiableProperties = new UnmodifiableProperties(properties);\r
+    private String desiredMessage = "Property cannot be modified!";\r
+\r
+    @Before\r
+    public void setUp() throws Exception {\r
+        properties.setProperty(propKey1, propValue1);\r
+        properties.setProperty(propKey2, propValue2);\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public void testClear() {\r
+        try {\r
+            unmodifiableProperties.clear();\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public void testClone() {\r
+        try {\r
+            unmodifiableProperties.clone();\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public final void testContainsObject() {\r
+        Assert.assertTrue(unmodifiableProperties.contains(propValue2));\r
+        Assert.assertFalse(unmodifiableProperties.contains(noValue));\r
+    }\r
+\r
+    @Test\r
+    public final void testContainsKeyObject() {\r
+        Assert.assertTrue(unmodifiableProperties.containsKey(propKey1));\r
+        Assert.assertFalse(unmodifiableProperties.containsKey(noKey));\r
+    }\r
+\r
+    @Test\r
+    public final void testContainsValueObject() {\r
+        Assert.assertTrue(unmodifiableProperties.containsValue(propValue1));\r
+        Assert.assertFalse(unmodifiableProperties.containsValue(noValue));\r
+    }\r
+\r
+    @Test\r
+    public final void testEntrySet() {\r
+        // Should match my properties K/V entries in setUp.\r
+        // Expect entrySet=[testKey2=testValue2, testKey1=testValue1].\r
+        Assert.assertEquals(properties.entrySet(), unmodifiableProperties.entrySet());\r
+    }\r
+\r
+    @Test\r
+    public final void testEqualsObject() {\r
+        Assert.assertTrue(unmodifiableProperties.equals(properties));\r
+    }\r
+\r
+    @Test\r
+    public final void testGetObject() {\r
+        Assert.assertEquals(propValue2, unmodifiableProperties.get(propKey2));\r
+    }\r
+\r
+    @Test\r
+    public final void testGetPropertyString() {\r
+        Assert.assertEquals(propValue1, unmodifiableProperties.getProperty("testKey1"));\r
+    }\r
+\r
+    @Test\r
+    public final void testGetPropertyStringString() {\r
+        Assert.assertEquals(propValue2, unmodifiableProperties.getProperty(propKey2, noValue));\r
+        Assert.assertEquals(propValue2, unmodifiableProperties.getProperty(noKey, propValue2));\r
+    }\r
+\r
+    @Test\r
+    public final void testIsEmpty() {\r
+        Assert.assertFalse(unmodifiableProperties.isEmpty());\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public final void testPutObjectObject() {\r
+        try {\r
+            unmodifiableProperties.put(propKey2, propValue1);\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public final void testRehash() {\r
+        try {\r
+            unmodifiableProperties.rehash();\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public final void testRemoveObject() {\r
+        try {\r
+            unmodifiableProperties.remove(propKey1);\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public final void testSetPropertyStringString() {\r
+        try {\r
+            unmodifiableProperties.setProperty(propKey1, propValue2);\r
+        } catch (UnsupportedOperationException exceptionMessage) {\r
+            Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());\r
+            throw exceptionMessage;\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public final void testSize() {\r
+        Assert.assertEquals(2, unmodifiableProperties.size());\r
+    }\r
+\r
+    @Test\r
+    public final void testStringPropertyNames() {\r
+        Assert.assertEquals(properties.stringPropertyNames(),unmodifiableProperties.stringPropertyNames());\r
+    }\r
+\r
+    @Test\r
+    public final void testToString() {\r
+        // toString=[{testKey2=testValue2, testKey1=testValue1}]\r
+        Assert.assertEquals(properties.toString(),unmodifiableProperties.toString());\r
+    }\r
+}\r