Bug 5947: additional tests for mdsal project #10 62/46662/6
authorPeter Nosal <peter.nosal@pantheon.tech>
Fri, 7 Oct 2016 10:04:55 +0000 (12:04 +0200)
committerPeter Nosal <peter.nosal@pantheon.sk>
Tue, 18 Oct 2016 07:10:38 +0000 (07:10 +0000)
- added additional tests
- refactored some util classes
- properly fixed some issues and checkstyle validations

Change-Id: Ibd483985bfc5bed23d61c7c81695398abdd427ae
Signed-off-by: Peter Nosal <peter.nosal@pantheon.tech>
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfInetUtilTest.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfYangUtilTest.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/IpClass.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/IpUtil.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/Ipv4UtilsTest.java [new file with mode: 0644]
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/Ipv6UtilsTest.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/MacClass.java
model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/MacUtil.java

index a83fab91198cafa139674461f674cd9da433566f..3f7a6f82b340688638c65c0117c941cae85ebb33 100644 (file)
@@ -5,6 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.mdsal.model.ietf.util;
 
 import static org.junit.Assert.assertArrayEquals;
 package org.opendaylight.mdsal.model.ietf.util;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -12,12 +13,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 
 import com.google.common.net.InetAddresses;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import static org.mockito.Mockito.mock;
 
 import com.google.common.net.InetAddresses;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import org.junit.Test;
 
 public class AbstractIetfInetUtilTest {
 import org.junit.Test;
 
 public class AbstractIetfInetUtilTest {
@@ -45,25 +48,29 @@ public class AbstractIetfInetUtilTest {
         assertV4Equals("255.254.253.252", "%5");
         assertV4Equals("128.16.0.127", "%5");
 
         assertV4Equals("255.254.253.252", "%5");
         assertV4Equals("128.16.0.127", "%5");
 
-        assertEquals(new IpClass("1.2.3.4")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.ipv4AddressBytes(new IpClass("1.2.3.4")))._value.toLowerCase());
-        assertNotEquals(new IpClass("2.3.4.5")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.ipv4AddressBytes(new IpClass("1.2.3.4")))._value.toLowerCase());
-
-        assertEquals(new IpClass("FE80::2002:B3FF:FE1E:8329")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.ipv6AddressBytes(new IpClass("FE80::2002:B3FF:FE1E:8329")))._value.toLowerCase());
-        assertNotEquals(new IpClass("FEFF::2002:B3FF:FE1E:8329")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.ipv6AddressBytes(new IpClass("FE80::2002:B3FF:FE1E:8329")))._value.toLowerCase());
-
-        assertEquals(new IpClass("1.2.3.4")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("1.2.3.4")))._value.toLowerCase());
-        assertNotEquals(new IpClass("2.3.4.5")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("1.2.3.4")))._value.toLowerCase());
-
-        assertEquals(new IpClass("FE80::2002:B3FF:FE1E:8329")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329")))._value.toLowerCase());
-        assertNotEquals(new IpClass("FEFF::2002:B3FF:FE1E:8329")._value.toLowerCase(),
-                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329")))._value.toLowerCase());
+        assertEquals(new IpClass("1.2.3.4").getValue().toLowerCase(),
+                UTIL.ipAddressFor(UTIL.ipv4AddressBytes(new IpClass("1.2.3.4"))).getValue().toLowerCase());
+        assertNotEquals(new IpClass("2.3.4.5").getValue().toLowerCase(),
+                UTIL.ipAddressFor(UTIL.ipv4AddressBytes(new IpClass("1.2.3.4"))).getValue().toLowerCase());
+
+        assertEquals(new IpClass("FE80::2002:B3FF:FE1E:8329").getValue().toLowerCase(),
+                UTIL.ipAddressFor(
+                        UTIL.ipv6AddressBytes(new IpClass("FE80::2002:B3FF:FE1E:8329"))).getValue().toLowerCase());
+        assertNotEquals(new IpClass("FEFF::2002:B3FF:FE1E:8329").getValue().toLowerCase(),
+                UTIL.ipAddressFor(
+                        UTIL.ipv6AddressBytes(new IpClass("FE80::2002:B3FF:FE1E:8329"))).getValue().toLowerCase());
+
+        assertEquals(new IpClass("1.2.3.4").getValue().toLowerCase(),
+                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("1.2.3.4"))).getValue().toLowerCase());
+        assertNotEquals(new IpClass("2.3.4.5").getValue().toLowerCase(),
+                UTIL.ipAddressFor(UTIL.inetAddressFor(new IpClass("1.2.3.4"))).getValue().toLowerCase());
+
+        assertEquals(new IpClass("FE80::2002:B3FF:FE1E:8329").getValue().toLowerCase(),
+                UTIL.ipAddressFor(
+                        UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329"))).getValue().toLowerCase());
+        assertNotEquals(new IpClass("FEFF::2002:B3FF:FE1E:8329").getValue().toLowerCase(),
+                UTIL.ipAddressFor(
+                        UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329"))).getValue().toLowerCase());
     }
 
     @Test(expected = IllegalArgumentException.class)
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -93,20 +100,21 @@ public class AbstractIetfInetUtilTest {
     @Test
     public void ipv4Tests() throws Exception {
         IpClass ipClass = new IpClass("1.2.3.4/16");
     @Test
     public void ipv4Tests() throws Exception {
         IpClass ipClass = new IpClass("1.2.3.4/16");
-        assertEquals("1.2.3.4", UTIL.ipv4AddressFrom(ipClass)._value);
-        assertTrue(UTIL.ipv4PrefixFor(UTIL.ipv4AddressBytes(ipClass))._value.contains("/32"));
+        assertEquals("1.2.3.4", UTIL.ipv4AddressFrom(ipClass).getValue());
+        assertTrue(UTIL.ipv4PrefixFor(UTIL.ipv4AddressBytes(ipClass)).getValue().contains("/32"));
         ipClass = new IpClass("1.2.3.4");
         ipClass = new IpClass("1.2.3.4");
-        assertTrue(UTIL.ipv4PrefixFor(UTIL.inetAddressFor(ipClass))._value.contains("/32"));
-        assertTrue(UTIL.ipv4PrefixFor(ipClass)._value.contains("/32"));
-        assertTrue(UTIL.ipv4PrefixFor(ipClass, 16)._value.contains("/16"));
-
-        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0)._value.equals("0.0.0.0/0"));
-        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 32)._value.equals("1.2.3.4/32"));
-        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0, 0)._value.equals("0.0.0.0/0"));
-        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0, 32)._value.equals("1.2.3.4/32"));
-        assertTrue(UTIL.ipv4PrefixForShort(new byte[] { 1, 2, 3, 4, 5 }, 1, 32)._value.equals("2.3.4.5/32"));
-
-        assertTrue(UTIL.splitIpv4Prefix(new IpClass("1.2.3.4/16")).getKey()._value.equals("1.2.3.4"));
+        assertTrue(UTIL.ipv4PrefixFor(UTIL.inetAddressFor(ipClass)).getValue().contains("/32"));
+        assertTrue(UTIL.ipv4PrefixFor(ipClass).getValue().contains("/32"));
+        assertTrue(UTIL.ipv4PrefixFor(ipClass, 16).getValue().contains("/16"));
+
+        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0).getValue().equals("0.0.0.0/0"));
+        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 32).getValue().equals("1.2.3.4/32"));
+        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0, 0).getValue().equals("0.0.0.0/0"));
+        assertTrue(UTIL.ipv4PrefixForShort(UTIL.ipv4AddressBytes(ipClass), 0, 32).getValue().equals("1.2.3.4/32"));
+        assertTrue(UTIL.ipv4PrefixForShort(new byte[] { 1, 2, 3, 4, 5 }, 1, 32).getValue().equals("2.3.4.5/32"));
+        assertTrue(UTIL.ipv4PrefixForShort(new byte[] { 1, 2, 3, 4, 5 }, 0, 1).getValue().equals("1.0.0.0/1"));
+
+        assertTrue(UTIL.splitIpv4Prefix(new IpClass("1.2.3.4/16")).getKey().getValue().equals("1.2.3.4"));
         assertTrue(UTIL.splitIpv4Prefix(new IpClass("1.2.3.4/16")).getValue().equals(16));
         assertArrayEquals(new byte[] { 1,2,3,4,16 }, UTIL.ipv4PrefixToBytes(new IpClass("1.2.3.4/16")));
     }
         assertTrue(UTIL.splitIpv4Prefix(new IpClass("1.2.3.4/16")).getValue().equals(16));
         assertArrayEquals(new byte[] { 1,2,3,4,16 }, UTIL.ipv4PrefixToBytes(new IpClass("1.2.3.4/16")));
     }
@@ -114,19 +122,19 @@ public class AbstractIetfInetUtilTest {
     @Test
     public void ipv6Tests() throws Exception {
         IpClass ipClass = new IpClass("::0/128");
     @Test
     public void ipv6Tests() throws Exception {
         IpClass ipClass = new IpClass("::0/128");
-        assertEquals("::0", UTIL.ipv6AddressFrom(ipClass)._value);
+        assertEquals("::0", UTIL.ipv6AddressFrom(ipClass).getValue());
         ipClass = new IpClass("::0");
         ipClass = new IpClass("::0");
-        assertTrue(UTIL.ipv6PrefixFor(UTIL.ipv6AddressBytes(ipClass))._value.contains("/128"));
-        assertTrue(UTIL.ipv6PrefixFor(UTIL.inetAddressFor(ipClass))._value.contains("/128"));
-        assertTrue(UTIL.ipv6PrefixFor(ipClass)._value.contains("/128"));
-        assertTrue(UTIL.ipv6PrefixFor(ipClass, 16)._value.contains("/16"));
+        assertTrue(UTIL.ipv6PrefixFor(UTIL.ipv6AddressBytes(ipClass)).getValue().contains("/128"));
+        assertTrue(UTIL.ipv6PrefixFor(UTIL.inetAddressFor(ipClass)).getValue().contains("/128"));
+        assertTrue(UTIL.ipv6PrefixFor(ipClass).getValue().contains("/128"));
+        assertTrue(UTIL.ipv6PrefixFor(ipClass, 16).getValue().contains("/16"));
 
 
-        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0)._value.equals("::0/0"));
-        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 64)._value.equals("::/64"));
-        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0, 0)._value.equals("::0/0"));
-        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0, 32)._value.equals("::/32"));
+        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0).getValue().equals("::0/0"));
+        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 64).getValue().equals("::/64"));
+        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0, 0).getValue().equals("::0/0"));
+        assertTrue(UTIL.ipv6PrefixForShort(UTIL.ipv6AddressBytes(ipClass), 0, 32).getValue().equals("::/32"));
 
 
-        assertTrue(UTIL.splitIpv6Prefix(new IpClass("::/32")).getKey()._value.equals("::"));
+        assertTrue(UTIL.splitIpv6Prefix(new IpClass("::/32")).getKey().getValue().equals("::"));
         assertTrue(UTIL.splitIpv6Prefix(new IpClass("::/32")).getValue().equals(32));
         assertArrayEquals(new byte[] { 0, 10, 0, 0, 0, 0, 0, 0, 0, 11, 0, 12, 0, 13, 0, 14, 64 },
                 UTIL.ipv6PrefixToBytes(new IpClass("A::B:C:D:E/64")));
         assertTrue(UTIL.splitIpv6Prefix(new IpClass("::/32")).getValue().equals(32));
         assertArrayEquals(new byte[] { 0, 10, 0, 0, 0, 0, 0, 0, 0, 11, 0, 12, 0, 13, 0, 14, 64 },
                 UTIL.ipv6PrefixToBytes(new IpClass("A::B:C:D:E/64")));
@@ -134,13 +142,13 @@ public class AbstractIetfInetUtilTest {
 
     @Test
     public void prefixTest() throws Exception {
 
     @Test
     public void prefixTest() throws Exception {
-        assertTrue(UTIL.ipPrefixFor(UTIL.inetAddressFor(new IpClass("0.0.0.0")), 16)._value.equals("0.0.0.0/16"));
+        assertTrue(UTIL.ipPrefixFor(UTIL.inetAddressFor(new IpClass("0.0.0.0")), 16).getValue().equals("0.0.0.0/16"));
         assertTrue(UTIL.ipPrefixFor(UTIL.inetAddressFor(new IpClass("::")), 64)
         assertTrue(UTIL.ipPrefixFor(UTIL.inetAddressFor(new IpClass("::")), 64)
-                ._value.equals("::/64"));
+                .getValue().equals("::/64"));
 
 
-        assertTrue(UTIL.ipPrefixFor(new byte[] { 0, 0, 0, 0 }, 16)._value.equals("0.0.0.0/16"));
+        assertTrue(UTIL.ipPrefixFor(new byte[] { 0, 0, 0, 0 }, 16).getValue().equals("0.0.0.0/16"));
         assertTrue(UTIL.ipPrefixFor(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 64)
         assertTrue(UTIL.ipPrefixFor(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 64)
-                ._value.equals("::/64"));
+                .getValue().equals("::/64"));
     }
 
     @Test
     }
 
     @Test
@@ -148,4 +156,20 @@ public class AbstractIetfInetUtilTest {
         assertTrue(UTIL.inetAddressFor(new IpClass("1.2.3.4")) instanceof Inet4Address);
         assertTrue(UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329")) instanceof Inet6Address);
     }
         assertTrue(UTIL.inetAddressFor(new IpClass("1.2.3.4")) instanceof Inet4Address);
         assertTrue(UTIL.inetAddressFor(new IpClass("FE80::2002:B3FF:FE1E:8329")) instanceof Inet6Address);
     }
-}
+
+    @Test(expected = IllegalArgumentException.class)
+    public void inet4AddressForWithExceptionTest() throws Exception {
+        final IpClass ipClass = mock(IpClass.class);
+        doReturn("testClass").when(ipClass).toString();
+        doThrow(UnknownHostException.class).when(ipClass).getValue();
+        UTIL.inet4AddressFor(ipClass);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void inet6AddressForWithExceptionTest() throws Exception {
+        final IpClass ipClass = mock(IpClass.class);
+        doReturn("testClass").when(ipClass).toString();
+        doThrow(UnknownHostException.class).when(ipClass).getValue();
+        UTIL.inet6AddressFor(ipClass);
+    }
+}
\ No newline at end of file
index 7b3780aab588a31c495cce370e9a7fa4ceab2524..fa9484e7a4d687e9ff301af416d26e52fda85752 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.mdsal.model.ietf.util;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.util.Arrays;
 import org.junit.Test;
 
 import java.util.Arrays;
 import org.junit.Test;
@@ -21,13 +22,13 @@ public class AbstractIetfYangUtilTest {
     private static final String CANON = "01:02:1e:5a:fb:88";
 
     @Test
     private static final String CANON = "01:02:1e:5a:fb:88";
 
     @Test
-    public void testBytesToMac() {
+    public void testBytesToMac() throws Exception {
         final MacClass mac = UTIL.macAddressFor(BYTES);
         final MacClass mac = UTIL.macAddressFor(BYTES);
-        assertEquals(CANON, mac._value);
+        assertEquals(CANON, mac.getValue());
     }
 
     @Test
     }
 
     @Test
-    public void testMacToBytes() {
+    public void testMacToBytes() throws Exception {
         final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
         assertTrue(Arrays.equals(BYTES, bytes1));
 
         final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
         assertTrue(Arrays.equals(BYTES, bytes1));
 
@@ -37,7 +38,13 @@ public class AbstractIetfYangUtilTest {
 
     @Test
     public void canonizeMACTest() throws Exception {
 
     @Test
     public void canonizeMACTest() throws Exception {
-        assertFalse(UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88"))._value
-                .equals(UTIL.canonizeMacAddress(new MacClass(CANON))._value));
+        assertFalse(UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue()
+                .equals(UTIL.canonizeMacAddress(new MacClass(CANON)).getValue()));
     }
     }
-}
+
+    @Test(expected = IllegalArgumentException.class)
+    public void hexValueWithExceptionTest() throws Exception {
+        AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
+        fail("Expected invalid character exception");
+    }
+}
\ No newline at end of file
index 2f588e15f4f16e00beb0746290abf8a3148638d3..012fb3231fcf93cb97786b4b17bfa41dc69dedd7 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.mdsal.model.ietf.util;
 
 import com.google.common.base.Preconditions;
 
 
 import com.google.common.base.Preconditions;
 
-public final class IpClass {
-    final String _value;
+public class IpClass {
+    private final String _value;
 
     public IpClass(final String value) {
         this._value = Preconditions.checkNotNull(value);
 
     public IpClass(final String value) {
         this._value = Preconditions.checkNotNull(value);
@@ -20,4 +20,8 @@ public final class IpClass {
     public IpClass(final IpClass template) {
         this._value = template._value;
     }
     public IpClass(final IpClass template) {
         this._value = template._value;
     }
+
+    String getValue() {
+        return this._value;
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file
index d7286b0416c675b84ceca43fdff01842a6271793..ca4d227f7d820303c207f31c8c7c666306426888 100644 (file)
@@ -5,9 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.mdsal.model.ietf.util;
 
 import java.util.regex.Pattern;
 package org.opendaylight.mdsal.model.ietf.util;
 
 import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
 import javax.annotation.RegEx;
 
 final class IpUtil extends AbstractIetfInetUtil<IpClass, IpClass, IpClass, IpClass, IpClass, IpClass> {
 import javax.annotation.RegEx;
 
 final class IpUtil extends AbstractIetfInetUtil<IpClass, IpClass, IpClass, IpClass, IpClass, IpClass> {
@@ -21,52 +23,60 @@ final class IpUtil extends AbstractIetfInetUtil<IpClass, IpClass, IpClass, IpCla
     }
 
     @Override
     }
 
     @Override
+    @Nonnull
     protected IpClass ipv4Address(final IpClass addr) {
         return addr;
     }
 
     @Override
     protected IpClass ipv4Address(final IpClass addr) {
         return addr;
     }
 
     @Override
+    @Nonnull
     protected IpClass ipv6Address(final IpClass addr) {
         return addr;
     }
 
     @Override
     protected IpClass ipv6Address(final IpClass addr) {
         return addr;
     }
 
     @Override
+    @Nonnull
     protected IpClass ipv4Prefix(IpClass addr) {
         return addr;
     }
 
     @Override
     protected IpClass ipv4Prefix(IpClass addr) {
         return addr;
     }
 
     @Override
+    @Nonnull
     protected IpClass ipv6Prefix(IpClass addr) {
         return addr;
     }
 
     @Override
     protected IpClass ipv6Prefix(IpClass addr) {
         return addr;
     }
 
     @Override
+    @Nonnull
     protected String ipv4AddressString(final IpClass addr) {
     protected String ipv4AddressString(final IpClass addr) {
-        return addr._value;
+        return addr.getValue();
     }
 
     @Override
     }
 
     @Override
+    @Nonnull
     protected String ipv6AddressString(final IpClass addr) {
     protected String ipv6AddressString(final IpClass addr) {
-        return addr._value;
+        return addr.getValue();
     }
 
     @Override
     }
 
     @Override
+    @Nonnull
     protected String ipv4PrefixString(final IpClass prefix) {
     protected String ipv4PrefixString(final IpClass prefix) {
-        return prefix._value;
+        return prefix.getValue();
     }
 
     @Override
     }
 
     @Override
+    @Nonnull
     protected String ipv6PrefixString(final IpClass prefix) {
     protected String ipv6PrefixString(final IpClass prefix) {
-        return prefix._value;
+        return prefix.getValue();
     }
 
     @Override
     protected IpClass maybeIpv4Address(IpClass addr) {
     }
 
     @Override
     protected IpClass maybeIpv4Address(IpClass addr) {
-        return IP_V4_PATTERN.matcher(addr._value).matches() ? addr : null;
+        return IP_V4_PATTERN.matcher(addr.getValue()).matches() ? addr : null;
     }
 
     @Override
     protected IpClass maybeIpv6Address(IpClass addr) {
     }
 
     @Override
     protected IpClass maybeIpv6Address(IpClass addr) {
-        return addr._value.indexOf(':') != -1 ? addr : null;
+        return addr.getValue().indexOf(':') != -1 ? addr : null;
     }
     }
-}
+}
\ No newline at end of file
diff --git a/model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/Ipv4UtilsTest.java b/model/ietf/ietf-type-util/src/test/java/org/opendaylight/mdsal/model/ietf/util/Ipv4UtilsTest.java
new file mode 100644 (file)
index 0000000..a7ac8a8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.model.ietf.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Constructor;
+import org.junit.Test;
+
+public class Ipv4UtilsTest {
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void privateConstructTest() throws Throwable {
+        final Constructor constructor = Ipv4Utils.class.getDeclaredConstructor();
+        assertFalse(constructor.isAccessible());
+        constructor.setAccessible(true);
+        try {
+            constructor.newInstance();
+            fail("Exception should be thrown");
+        } catch (Exception e) {
+            throw e.getCause();
+        }
+    }
+}
\ No newline at end of file
index 80ccbe525bbeee191d448539d833da1e12b19623..114561051092d37d9f1de2e3c6d2bcdc6d1bad3d 100644 (file)
@@ -5,14 +5,20 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.mdsal.model.ietf.util;
 
 import static com.google.common.net.InetAddresses.forString;
 import static org.junit.Assert.assertArrayEquals;
 package org.opendaylight.mdsal.model.ietf.util;
 
 import static com.google.common.net.InetAddresses.forString;
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
 import static org.opendaylight.mdsal.model.ietf.util.Ipv6Utils.fillIpv6Bytes;
 import static org.opendaylight.mdsal.model.ietf.util.Ipv6Utils.fillIpv6Bytes;
+
+import java.lang.reflect.Constructor;
 import org.junit.Test;
 
 public class Ipv6UtilsTest {
 import org.junit.Test;
 
 public class Ipv6UtilsTest {
+
     @Test
     public void testDiscards() {
         assertEqualResult("2001:0000:3238:DFE1:63:0000:0000:FEFB");
     @Test
     public void testDiscards() {
         assertEqualResult("2001:0000:3238:DFE1:63:0000:0000:FEFB");
@@ -22,9 +28,6 @@ public class Ipv6UtilsTest {
         assertEqualResult("::");
     }
 
         assertEqualResult("::");
     }
 
-    /**
-     * @author Anton Ivanov aivanov@brocade.com
-     */
     @Test
     public void testFullQuads() {
         assertEqualResult("0000:0000:0000:0000:0000:0000:0000:0001");
     @Test
     public void testFullQuads() {
         assertEqualResult("0000:0000:0000:0000:0000:0000:0000:0001");
@@ -110,4 +113,17 @@ public class Ipv6UtilsTest {
     private static void assertEqualResult(final String str) {
         assertArrayEquals(forString(str).getAddress(), bytesForString(str));
     }
     private static void assertEqualResult(final String str) {
         assertArrayEquals(forString(str).getAddress(), bytesForString(str));
     }
-}
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void privateConstructTest() throws Throwable {
+        final Constructor constructor = Ipv6Utils.class.getDeclaredConstructor();
+        assertFalse(constructor.isAccessible());
+        constructor.setAccessible(true);
+        try {
+            constructor.newInstance();
+            fail("Exception should be thrown");
+        } catch (Exception e) {
+            throw e.getCause();
+        }
+    }
+}
\ No newline at end of file
index d1ceefbe0a9724934b916c6b7356081fde28510b..13577d665e1582739053aa52b7140d3aa54d931e 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.mdsal.model.ietf.util;
 import com.google.common.base.Preconditions;
 
 public final class MacClass {
 import com.google.common.base.Preconditions;
 
 public final class MacClass {
-    final String _value;
+    private final String _value;
 
     public MacClass(final String value) {
         this._value = Preconditions.checkNotNull(value);
 
     public MacClass(final String value) {
         this._value = Preconditions.checkNotNull(value);
@@ -20,4 +20,8 @@ public final class MacClass {
     public MacClass(final MacClass template) {
         this._value = template._value;
     }
     public MacClass(final MacClass template) {
         this._value = template._value;
     }
+
+    String getValue() {
+        return _value;
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file
index c1b4a7764e5466b0b73dc175beea9b72c438dcab..e5ca1a75538f461758bff031d17c725ff99c8271 100644 (file)
@@ -15,6 +15,6 @@ final class MacUtil extends AbstractIetfYangUtil<MacClass> {
 
     @Override
     protected String getValue(final MacClass macAddress) {
 
     @Override
     protected String getValue(final MacClass macAddress) {
-        return macAddress._value;
+        return macAddress.getValue();
     }
 }
\ No newline at end of file
     }
 }
\ No newline at end of file