Enforce findbug and checkstyle under bgp concepts 80/66580/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 18 Dec 2017 16:17:20 +0000 (17:17 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Wed, 20 Dec 2017 14:27:48 +0000 (14:27 +0000)
Change-Id: I16ef040f415e742f94751f57ebd965c51f3747ce
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/concepts/pom.xml
bgp/concepts/src/main/java/org/opendaylight/bgp/concepts/NextHopUtil.java
bgp/concepts/src/main/java/org/opendaylight/bgp/concepts/RouteDistinguisherUtil.java
bgp/concepts/src/test/java/org/opendaylight/bgp/concepts/NextHopUtilTest.java
bgp/concepts/src/test/java/org/opendaylight/bgp/concepts/RouteDistinguisherUtilTest.java

index 33cc07dc9e7d1cb46c1147bd62dd2fc771895140..d13787c16561a7f4ca19a14761897a1f2877c7c6 100644 (file)
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>findbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
     <scm>
         <connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
         <developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
index 1b8e69a1e7c74a6bae5f2e1db4245f492ff155e6..a2a6c22cba7bbcc4a8be1e248bd4b24295395122 100644 (file)
@@ -33,15 +33,17 @@ public final class NextHopUtil {
     /**
      * Writes serialized cnextHop IP address as byte value into ByteBuf.
      *
-     * @param cnextHop next hop to be serialized
+     * @param cnextHop       next hop to be serialized
      * @param byteAggregator where the next hop will be written
      */
     public static void serializeNextHop(final CNextHop cnextHop, final ByteBuf byteAggregator) {
         if (cnextHop instanceof Ipv4NextHopCase) {
-            byteAggregator.writeBytes(Ipv4Util.bytesForAddress(((Ipv4NextHopCase) cnextHop).getIpv4NextHop().getGlobal()));
+            byteAggregator.writeBytes(Ipv4Util.bytesForAddress(((Ipv4NextHopCase) cnextHop)
+                    .getIpv4NextHop().getGlobal()));
         } else if (cnextHop instanceof Ipv6NextHopCase) {
             final Ipv6NextHop nextHop = ((Ipv6NextHopCase) cnextHop).getIpv6NextHop();
-            Preconditions.checkArgument(nextHop.getGlobal() != null, "Ipv6 Next Hop is missing Global address.");
+            Preconditions.checkArgument(nextHop.getGlobal() != null,
+                    "Ipv6 Next Hop is missing Global address.");
             byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHop.getGlobal()));
             if (nextHop.getLinkLocal() != null) {
                 byteAggregator.writeBytes(Ipv6Util.bytesForAddress(nextHop.getLinkLocal()));
@@ -59,15 +61,19 @@ public final class NextHopUtil {
      */
     public static CNextHop parseNextHop(final ByteBuf buffer) {
         switch (buffer.writerIndex()) {
-        case Ipv4Util.IP4_LENGTH:
-            return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(Ipv4Util.addressForByteBuf(buffer)).build()).build();
-        case Ipv6Util.IPV6_LENGTH:
-            return new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForByteBuf(buffer)).build()).build();
-        case Ipv6Util.IPV6_LENGTH * 2:
-            return new Ipv6NextHopCaseBuilder().setIpv6NextHop(
-                    new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForByteBuf(buffer)).setLinkLocal(Ipv6Util.addressForByteBuf(buffer)).build()).build();
-        default:
-            throw new IllegalArgumentException("Cannot parse NEXT_HOP attribute. Wrong bytes length: " + buffer.writerIndex());
+            case Ipv4Util.IP4_LENGTH:
+                return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+                        .setGlobal(Ipv4Util.addressForByteBuf(buffer)).build()).build();
+            case Ipv6Util.IPV6_LENGTH:
+                return new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder()
+                        .setGlobal(Ipv6Util.addressForByteBuf(buffer)).build()).build();
+            case Ipv6Util.IPV6_LENGTH * 2:
+                return new Ipv6NextHopCaseBuilder().setIpv6NextHop(
+                        new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForByteBuf(buffer))
+                                .setLinkLocal(Ipv6Util.addressForByteBuf(buffer)).build()).build();
+            default:
+                throw new IllegalArgumentException("Cannot parse NEXT_HOP attribute. Wrong bytes length: "
+                        + buffer.writerIndex());
         }
     }
 }
index b5d7d1b6342051ffe1fc70797071761820e76fb2..99a9627fb3f01e3cba89d1a45536e6f7a973b70c 100644 (file)
@@ -31,32 +31,9 @@ import org.slf4j.LoggerFactory;
  * https://tools.ietf.org/html/rfc4364#section-4.2
  */
 public final class RouteDistinguisherUtil {
+    public static final int RD_LENGTH = 8;
     private static final Logger LOG = LoggerFactory.getLogger(RouteDistinguisherUtil.class);
-
-    private enum RD_TYPE {
-        AS_2BYTE(0),
-        IPV4(1),
-        AS_4BYTE(2),
-        INVALID(-1);
-
-        public final int value;
-
-        RD_TYPE(int val) {
-            this.value = val;
-        }
-
-        public static RD_TYPE valueOf(final int value) {
-            for (RD_TYPE type : values()) {
-                if (type.value == value) {
-                    return type;
-                }
-            }
-            return INVALID;
-        }
-    }
-
     private static final String SEPARATOR = ":";
-    public static final int RD_LENGTH = 8;
 
     private RouteDistinguisherUtil() {
         throw new UnsupportedOperationException();
@@ -64,29 +41,28 @@ public final class RouteDistinguisherUtil {
 
     /**
      * Serializes route distinguisher according to type and writes into ByteBuf.
-     *
-     * @param distinguisher
-     * @param byteAggregator
      */
-    public static void serializeRouteDistinquisher(final RouteDistinguisher distinguisher, final ByteBuf byteAggregator) {
+    public static void serializeRouteDistinquisher(final RouteDistinguisher distinguisher,
+            final ByteBuf byteAggregator) {
         requireNonNull(distinguisher);
-        Preconditions.checkState(byteAggregator != null && byteAggregator.isWritable(RD_LENGTH), "Cannot write Route Distinguisher to provided buffer.");
+        Preconditions.checkState(byteAggregator != null && byteAggregator.isWritable(RD_LENGTH),
+                "Cannot write Route Distinguisher to provided buffer.");
         if (distinguisher.getRdTwoOctetAs() != null) {
             final String[] values = distinguisher.getRdTwoOctetAs().getValue().split(SEPARATOR);
-            byteAggregator.writeShort(RD_TYPE.AS_2BYTE.value);
+            byteAggregator.writeShort(RDType.AS_2BYTE.value);
             ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
             final long assignedNumber = Integer.parseUnsignedInt(values[2]);
             ByteBufWriteUtil.writeUnsignedInt(assignedNumber, byteAggregator);
         } else if (distinguisher.getRdAs() != null) {
             final String[] values = distinguisher.getRdAs().getValue().split(SEPARATOR);
-            byteAggregator.writeShort(RD_TYPE.AS_4BYTE.value);
+            byteAggregator.writeShort(RDType.AS_4BYTE.value);
             final long admin = Integer.parseUnsignedInt(values[0]);
             ByteBufWriteUtil.writeUnsignedInt(admin, byteAggregator);
             ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
         } else if (distinguisher.getRdIpv4() != null) {
             final String[] values = distinguisher.getRdIpv4().getValue().split(SEPARATOR);
             final Ipv4Address ip = new Ipv4Address(values[0]);
-            byteAggregator.writeShort(RD_TYPE.IPV4.value);
+            byteAggregator.writeShort(RDType.IPV4.value);
             ByteBufWriteUtil.writeIpv4Address(ip, byteAggregator);
             ByteBufWriteUtil.writeUnsignedShort(Integer.parseInt(values[1]), byteAggregator);
         } else {
@@ -96,41 +72,40 @@ public final class RouteDistinguisherUtil {
 
     /**
      * Parses three types of route distinguisher from given ByteBuf.
-     *
-     * @param buffer
-     * @return RouteDistinguisher
      */
     public static RouteDistinguisher parseRouteDistinguisher(final ByteBuf buffer) {
-        Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH), "Cannot read Route Distinguisher from provided buffer.");
+        Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH),
+                "Cannot read Route Distinguisher from provided buffer.");
         final int type = buffer.readUnsignedShort();
-        final RD_TYPE rdType = RD_TYPE.valueOf(type);
+        final RDType rdType = RDType.valueOf(type);
         final StringBuilder routeDistiguisher = new StringBuilder();
         switch (rdType) {
-        case AS_2BYTE:
-            routeDistiguisher.append(type);
-            routeDistiguisher.append(SEPARATOR);
-            routeDistiguisher.append(buffer.readUnsignedShort());
-            routeDistiguisher.append(SEPARATOR);
-            routeDistiguisher.append(buffer.readUnsignedInt());
-            return new RouteDistinguisher(new RdTwoOctetAs(routeDistiguisher.toString()));
-        case IPV4:
-            routeDistiguisher.append(Ipv4Util.addressForByteBuf(buffer).getValue());
-            routeDistiguisher.append(SEPARATOR);
-            routeDistiguisher.append(buffer.readUnsignedShort());
-            return new RouteDistinguisher(new RdIpv4(routeDistiguisher.toString()));
-        case AS_4BYTE:
-            routeDistiguisher.append(buffer.readUnsignedInt());
-            routeDistiguisher.append(SEPARATOR);
-            routeDistiguisher.append(buffer.readUnsignedShort());
-            return new RouteDistinguisher(new RdAs(routeDistiguisher.toString()));
-        default:
-            // now that this RD type is not supported, we want to read the remain 6 bytes
-            // in order to get the byte index correct
-            for (int i = 0; i < 6; i++) {
-                routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(" ");
-            }
-            LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type, routeDistiguisher.toString());
-            throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
+            case AS_2BYTE:
+                routeDistiguisher.append(type);
+                routeDistiguisher.append(SEPARATOR);
+                routeDistiguisher.append(buffer.readUnsignedShort());
+                routeDistiguisher.append(SEPARATOR);
+                routeDistiguisher.append(buffer.readUnsignedInt());
+                return new RouteDistinguisher(new RdTwoOctetAs(routeDistiguisher.toString()));
+            case IPV4:
+                routeDistiguisher.append(Ipv4Util.addressForByteBuf(buffer).getValue());
+                routeDistiguisher.append(SEPARATOR);
+                routeDistiguisher.append(buffer.readUnsignedShort());
+                return new RouteDistinguisher(new RdIpv4(routeDistiguisher.toString()));
+            case AS_4BYTE:
+                routeDistiguisher.append(buffer.readUnsignedInt());
+                routeDistiguisher.append(SEPARATOR);
+                routeDistiguisher.append(buffer.readUnsignedShort());
+                return new RouteDistinguisher(new RdAs(routeDistiguisher.toString()));
+            default:
+                // now that this RD type is not supported, we want to read the remain 6 bytes
+                // in order to get the byte index correct
+                for (int i = 0; i < 6; i++) {
+                    routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(" ");
+                }
+                LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type,
+                        routeDistiguisher.toString());
+                throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
         }
     }
 
@@ -148,11 +123,34 @@ public final class RouteDistinguisherUtil {
         }
     }
 
-    public static RouteDistinguisher extractRouteDistinguisher(final DataContainerNode<?> route, final NodeIdentifier rdNid) {
+    public static RouteDistinguisher extractRouteDistinguisher(final DataContainerNode<?> route,
+            final NodeIdentifier rdNid) {
         final NormalizedNode<?, ?> rdNode = NormalizedNodes.findNode(route, rdNid).orNull();
         if (rdNode != null) {
             return parseRouteDistinguisher(rdNode.getValue());
         }
         return null;
     }
+
+    private enum RDType {
+        AS_2BYTE(0),
+        IPV4(1),
+        AS_4BYTE(2),
+        INVALID(-1);
+
+        public final int value;
+
+        RDType(int val) {
+            this.value = val;
+        }
+
+        public static RDType valueOf(final int value) {
+            for (RDType type : values()) {
+                if (type.value == value) {
+                    return type;
+                }
+            }
+            return INVALID;
+        }
+    }
 }
index 997897d52df67bd83e0f7f3baa1b667c35c928db..0839ddb68f0b9a912908fc8c48dfd9a10236223a 100644 (file)
@@ -14,8 +14,6 @@ import static org.junit.Assert.fail;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import org.junit.Test;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -30,35 +28,37 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 
 public class NextHopUtilTest {
 
-    private static final byte[] ipv4B = { 42, 42, 42, 42 };
-    private static final byte[] ipv6B = { 0x20, 1, 0x0d, (byte) 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
-    private static final byte[] ipv6lB = { 0x20, 1, 0x0d, (byte) 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-        1, (byte) 0xfe, (byte) 0x80, 0, 0, 0, 0, 0, 0, (byte) 0xc0, 1, 0x0b, (byte) 0xff, (byte) 0xfe, 0x7e, 0, 0 };
+    private static final byte[] IPV4B = {42, 42, 42, 42};
+    private static final byte[] IPV6B = {0x20, 1, 0x0d, (byte) 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+    private static final byte[] IPV6LB = {0x20, 1, 0x0d, (byte) 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        1, (byte) 0xfe, (byte) 0x80, 0, 0, 0, 0, 0, 0, (byte) 0xc0, 1, 0x0b, (byte) 0xff, (byte) 0xfe, 0x7e, 0, 0};
 
-    private static final Ipv4Address ipv4 = new Ipv4Address("42.42.42.42");
-    private static final Ipv6Address ipv6 = new Ipv6Address("2001:db8::1");
-    private static final Ipv6Address ipv6l = new Ipv6Address("fe80::c001:bff:fe7e:0");
+    private static final Ipv4Address IPV4 = new Ipv4Address("42.42.42.42");
+    private static final Ipv6Address IPV6 = new Ipv6Address("2001:db8::1");
+    private static final Ipv6Address IPV6L = new Ipv6Address("fe80::c001:bff:fe7e:0");
 
     @Test
     public void testSerializeNextHop() {
-        CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(ipv4).build()).build();
+        CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+                .setGlobal(IPV4).build()).build();
         final ByteBuf buffer = Unpooled.buffer();
         NextHopUtil.serializeNextHop(hop, buffer);
-        assertArrayEquals(ipv4B, ByteArray.readAllBytes(buffer));
+        assertArrayEquals(IPV4B, ByteArray.readAllBytes(buffer));
 
-        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(ipv6).build()).build();
+        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).build()).build();
         buffer.clear();
         NextHopUtil.serializeNextHop(hop, buffer);
-        assertArrayEquals(ipv6B, ByteArray.readAllBytes(buffer));
+        assertArrayEquals(IPV6B, ByteArray.readAllBytes(buffer));
 
-        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(ipv6).setLinkLocal(ipv6l).build()).build();
+        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6)
+                .setLinkLocal(IPV6L).build()).build();
         buffer.clear();
         NextHopUtil.serializeNextHop(hop, buffer);
-        assertArrayEquals(ipv6lB, ByteArray.readAllBytes(buffer));
+        assertArrayEquals(IPV6LB, ByteArray.readAllBytes(buffer));
 
         buffer.clear();
 
-        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(ipv6l).build()).build();
+        hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(IPV6L).build()).build();
         buffer.clear();
         try {
             NextHopUtil.serializeNextHop(hop, buffer);
@@ -77,29 +77,29 @@ public class NextHopUtilTest {
     public void testParseNextHop() {
         CNextHop hop = null;
         try {
-            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(ipv4B));
+            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV4B));
         } catch (final IllegalArgumentException e) {
             fail("This exception should not happen");
         }
-        assertEquals(ipv4, ((Ipv4NextHopCase) hop).getIpv4NextHop().getGlobal());
+        assertEquals(IPV4, ((Ipv4NextHopCase) hop).getIpv4NextHop().getGlobal());
 
         try {
-            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(ipv6B));
+            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV6B));
         } catch (final IllegalArgumentException e) {
             fail("This exception should not happen");
         }
-        assertEquals(ipv6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
+        assertEquals(IPV6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
         assertNull(((Ipv6NextHopCase) hop).getIpv6NextHop().getLinkLocal());
 
         try {
-            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(ipv6lB));
+            hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV6LB));
         } catch (final IllegalArgumentException e) {
             fail("This exception should not happen");
         }
-        assertEquals(ipv6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
-        assertEquals(ipv6l, ((Ipv6NextHopCase) hop).getIpv6NextHop().getLinkLocal());
+        assertEquals(IPV6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
+        assertEquals(IPV6L, ((Ipv6NextHopCase) hop).getIpv6NextHop().getLinkLocal());
 
-        final byte[] wrong = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d };
+        final byte[] wrong = new byte[]{(byte) 0x20, (byte) 0x01, (byte) 0x0d};
         try {
             NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(wrong));
             fail("Exception should happen");
@@ -107,15 +107,4 @@ public class NextHopUtilTest {
             assertEquals("Cannot parse NEXT_HOP attribute. Wrong bytes length: 3", e.getMessage());
         }
     }
-
-    @Test(expected=UnsupportedOperationException.class)
-    public void testPrivateConstructor() throws Throwable {
-        final Constructor<NextHopUtil> c = NextHopUtil.class.getDeclaredConstructor();
-        c.setAccessible(true);
-        try {
-            c.newInstance();
-        } catch (InvocationTargetException e) {
-            throw e.getCause();
-        }
-    }
 }
index 82ff8903c6b0c594c2488675c10d78560206a32b..c62d7f9ff3897556984f587b4ff1642bbf80b5be 100644 (file)
@@ -12,8 +12,6 @@ import static org.junit.Assert.assertEquals;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisherBuilder;
@@ -25,39 +23,59 @@ public class RouteDistinguisherUtilTest {
     private static final String ADMIN = "55";
     private static final String ASSIGNED_NUMBER = "65535";
     private static final String ASSIGNED_NUMBER_BIG = "4294967295";
-    private static final byte[] AS_2B_BYTES = { 0, 0, 0, 55, 0, 0, (byte)0xff, (byte)0xff};
-    private static final byte[] AS_2B_BYTES_BIG = { 0, 0, 0, 55, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff};
-    private static final byte[] IP_BYTES = { 0, 1, 1, 2, 3, 4, 0, 10 };
-    private static final byte[] AS_4B_BYTES = { 0, 2, 0, 0, 0, 55, (byte)0xff, (byte)0xff};
-    private static final byte[] INVALID_RD_TYPE_BYTES = { 0, 3, 0, 0, 0, 55, (byte)0xff, (byte)0xff};
+    private static final byte[] AS_2B_BYTES = {0, 0, 0, 55, 0, 0, (byte) 0xff, (byte) 0xff};
+    private static final byte[] AS_2B_BYTES_BIG = {0, 0, 0, 55, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
+    private static final byte[] IP_BYTES = {0, 1, 1, 2, 3, 4, 0, 10};
+    private static final byte[] AS_4B_BYTES = {0, 2, 0, 0, 0, 55, (byte) 0xff, (byte) 0xff};
+    private static final byte[] INVALID_RD_TYPE_BYTES = {0, 3, 0, 0, 0, 55, (byte) 0xff, (byte) 0xff};
     private static final char SEPARATOR = ':';
 
+    /**
+     * Create 4-octet AS RD or IPv4 RD, 2-octet AS RD cannot be created with this function.
+     */
+    private static RouteDistinguisher createRouteDistinguisher(final int type, final String administratorSubfield,
+            final String assignedNumberSubfield) {
+        final StringBuilder routeDistiguisher = new StringBuilder();
+        if (type == 0) {
+            routeDistiguisher.append(type).append(SEPARATOR);
+        }
+        routeDistiguisher.append(administratorSubfield);
+        routeDistiguisher.append(SEPARATOR);
+        routeDistiguisher.append(assignedNumberSubfield);
+        return RouteDistinguisherBuilder.getDefaultInstance(routeDistiguisher.toString());
+    }
+
     @Test
     public void testAs2BRouteDistinguisher() {
         final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER);
-        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES));
+        final RouteDistinguisher parsed = RouteDistinguisherUtil
+            .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES));
         assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs());
         final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES.length);
         RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
         assertArrayEquals(AS_2B_BYTES, byteAggregator.array());
-        assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdTwoOctetAs().getValue());
+        assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER,
+                parsed.getRdTwoOctetAs().getValue());
     }
 
     @Test
     public void testAs2BLongRouteDistinguisher() {
         final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER_BIG);
-        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES_BIG));
+        final RouteDistinguisher parsed = RouteDistinguisherUtil
+            .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES_BIG));
         assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs());
         final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES_BIG.length);
         RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
         assertArrayEquals(AS_2B_BYTES_BIG, byteAggregator.array());
-        assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER_BIG, parsed.getRdTwoOctetAs().getValue());
+        assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER_BIG,
+                parsed.getRdTwoOctetAs().getValue());
     }
 
     @Test
     public void testIpv4RouteDistinguisher() {
         final RouteDistinguisher expected = createRouteDistinguisher(1, IP_ADDRESS, IP_PORT);
-        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(IP_BYTES));
+        final RouteDistinguisher parsed = RouteDistinguisherUtil
+            .parseRouteDistinguisher(Unpooled.copiedBuffer(IP_BYTES));
         assertEquals(expected.getRdIpv4(), parsed.getRdIpv4());
         final ByteBuf byteAggregator = Unpooled.buffer(IP_BYTES.length);
         RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
@@ -68,7 +86,8 @@ public class RouteDistinguisherUtilTest {
     @Test
     public void testAs4BRouteDistinguisher() {
         final RouteDistinguisher expected = createRouteDistinguisher(2, ADMIN, ASSIGNED_NUMBER);
-        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
+        final RouteDistinguisher parsed = RouteDistinguisherUtil
+            .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
         assertEquals(expected.getRdAs(), parsed.getRdAs());
         final ByteBuf byteAggregator = Unpooled.buffer(AS_4B_BYTES.length);
         RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator);
@@ -78,48 +97,22 @@ public class RouteDistinguisherUtilTest {
 
     @Test
     public void testParseRouteDistinguisher() {
-        final RouteDistinguisher expected = RouteDistinguisherUtil.parseRouteDistinguisher(ADMIN + SEPARATOR + ASSIGNED_NUMBER);
-        final RouteDistinguisher parsed = RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
+        final RouteDistinguisher expected = RouteDistinguisherUtil
+            .parseRouteDistinguisher(ADMIN + SEPARATOR + ASSIGNED_NUMBER);
+        final RouteDistinguisher parsed = RouteDistinguisherUtil
+            .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES));
         assertEquals(expected.getRdAs(), parsed.getRdAs());
 
         final RouteDistinguisher expectedRD = RouteDistinguisherUtil.parseRouteDistinguisher(expected);
         assertEquals(expectedRD.getRdAs(), parsed.getRdAs());
 
-        final RouteDistinguisher expectedObj = RouteDistinguisherUtil.parseRouteDistinguisher((Object) (ADMIN + SEPARATOR + ASSIGNED_NUMBER));
+        final RouteDistinguisher expectedObj = RouteDistinguisherUtil
+            .parseRouteDistinguisher((Object) (ADMIN + SEPARATOR + ASSIGNED_NUMBER));
         assertEquals(expectedObj.getRdAs(), parsed.getRdAs());
     }
 
-    @Test(expected=UnsupportedOperationException.class)
-    public void testPrivateConstructor() throws Throwable {
-        final Constructor<RouteDistinguisherUtil> c = RouteDistinguisherUtil.class.getDeclaredConstructor();
-        c.setAccessible(true);
-        try {
-            c.newInstance();
-        } catch (final InvocationTargetException e) {
-            throw e.getCause();
-        }
-    }
-
-    @Test(expected=IllegalArgumentException.class)
-    public void testInvalidRDType() throws Throwable {
+    @Test(expected = IllegalArgumentException.class)
+    public void testInvalidRDType() {
         RouteDistinguisherUtil.parseRouteDistinguisher(Unpooled.copiedBuffer(INVALID_RD_TYPE_BYTES));
     }
-
-    /**
-     * Create 4-octet AS RD or IPv4 RD, 2-octet AS RD cannot be created with this function
-     * @param administratorSubfield
-     * @param assignedNumberSubfield
-     * @return
-     */
-    private static RouteDistinguisher createRouteDistinguisher(final int type, final String administratorSubfield,
-            final String assignedNumberSubfield) {
-        final StringBuilder routeDistiguisher = new StringBuilder();
-        if (type == 0) {
-            routeDistiguisher.append(type).append(SEPARATOR);
-        }
-        routeDistiguisher.append(administratorSubfield);
-        routeDistiguisher.append(SEPARATOR);
-        routeDistiguisher.append(assignedNumberSubfield);
-        return RouteDistinguisherBuilder.getDefaultInstance(routeDistiguisher.toString());
-    }
 }