summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McClung <jm1364@att.com>2018-04-02 15:30:49 -0400
committerTakamune Cho <tc012c@att.com>2018-04-02 23:59:10 +0000
commitb39729ab3e620abbbb5140de2663caa29f13644e (patch)
tree3faf4398e9739e6a77c847e97c768126cce967a4
parentb32e6f295fc0aaf37b78140aedd417d8064c1020 (diff)
Add junit coverage to UnmodifiableProperties class
Introduce junit-tests for UnmodifiableProperties class Change-Id: I51f44c676a0cd8fef808ca2e33fea8afc7e52453 Issue-ID: APPC-820 Signed-off-by: John McClung <jm1364@att.com>
-rw-r--r--appc-common/src/test/java/org/onap/appc/util/UnmodifiablePropertiesTest.java174
1 files changed, 174 insertions, 0 deletions
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
index 000000000..d238dc352
--- /dev/null
+++ b/appc-common/src/test/java/org/onap/appc/util/UnmodifiablePropertiesTest.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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.appc.util;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+public class UnmodifiablePropertiesTest {
+
+ private static final String propKey1 = "testKey1";
+ private static final String propKey2 = "testKey2";
+ private static final String propValue1 = "testValue1";
+ private static final String propValue2 = "testValue2";
+ private static final String noKey = "unusedKey";
+ private static final String noValue = "unusedValue";
+ private Properties properties = new Properties();
+
+ private UnmodifiableProperties unmodifiableProperties = new UnmodifiableProperties(properties);
+ private String desiredMessage = "Property cannot be modified!";
+
+ @Before
+ public void setUp() throws Exception {
+ properties.setProperty(propKey1, propValue1);
+ properties.setProperty(propKey2, propValue2);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testClear() {
+ try {
+ unmodifiableProperties.clear();
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testClone() {
+ try {
+ unmodifiableProperties.clone();
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test
+ public final void testContainsObject() {
+ Assert.assertTrue(unmodifiableProperties.contains(propValue2));
+ Assert.assertFalse(unmodifiableProperties.contains(noValue));
+ }
+
+ @Test
+ public final void testContainsKeyObject() {
+ Assert.assertTrue(unmodifiableProperties.containsKey(propKey1));
+ Assert.assertFalse(unmodifiableProperties.containsKey(noKey));
+ }
+
+ @Test
+ public final void testContainsValueObject() {
+ Assert.assertTrue(unmodifiableProperties.containsValue(propValue1));
+ Assert.assertFalse(unmodifiableProperties.containsValue(noValue));
+ }
+
+ @Test
+ public final void testEntrySet() {
+ // Should match my properties K/V entries in setUp.
+ // Expect entrySet=[testKey2=testValue2, testKey1=testValue1].
+ Assert.assertEquals(properties.entrySet(), unmodifiableProperties.entrySet());
+ }
+
+ @Test
+ public final void testEqualsObject() {
+ Assert.assertTrue(unmodifiableProperties.equals(properties));
+ }
+
+ @Test
+ public final void testGetObject() {
+ Assert.assertEquals(propValue2, unmodifiableProperties.get(propKey2));
+ }
+
+ @Test
+ public final void testGetPropertyString() {
+ Assert.assertEquals(propValue1, unmodifiableProperties.getProperty("testKey1"));
+ }
+
+ @Test
+ public final void testGetPropertyStringString() {
+ Assert.assertEquals(propValue2, unmodifiableProperties.getProperty(propKey2, noValue));
+ Assert.assertEquals(propValue2, unmodifiableProperties.getProperty(noKey, propValue2));
+ }
+
+ @Test
+ public final void testIsEmpty() {
+ Assert.assertFalse(unmodifiableProperties.isEmpty());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public final void testPutObjectObject() {
+ try {
+ unmodifiableProperties.put(propKey2, propValue1);
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public final void testRehash() {
+ try {
+ unmodifiableProperties.rehash();
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public final void testRemoveObject() {
+ try {
+ unmodifiableProperties.remove(propKey1);
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public final void testSetPropertyStringString() {
+ try {
+ unmodifiableProperties.setProperty(propKey1, propValue2);
+ } catch (UnsupportedOperationException exceptionMessage) {
+ Assert.assertEquals(desiredMessage, exceptionMessage.getMessage());
+ throw exceptionMessage;
+ }
+ }
+
+ @Test
+ public final void testSize() {
+ Assert.assertEquals(2, unmodifiableProperties.size());
+ }
+
+ @Test
+ public final void testStringPropertyNames() {
+ Assert.assertEquals(properties.stringPropertyNames(),unmodifiableProperties.stringPropertyNames());
+ }
+
+ @Test
+ public final void testToString() {
+ // toString=[{testKey2=testValue2, testKey1=testValue1}]
+ Assert.assertEquals(properties.toString(),unmodifiableProperties.toString());
+ }
+}