Migrate rfc6991-ietf-inet-types to JUnit5 01/108501/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Oct 2023 16:04:42 +0000 (18:04 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Oct 2023 16:04:42 +0000 (18:04 +0200)
This is a trivial migration, except we also migrate hamcrest assertions
to assertInstanceOf().

Change-Id: I812ec1c4a885c9912afea41135ed767ce6436c0c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IetfInetUtilTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilderTest.java

index d8e878f3e3fc4cba09ea724904625036c235b55b..0c1d955d43cf632970afb498031b8a1802eaf5d3 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class HostBuilderTest {
+class HostBuilderTest {
     @Test
-    public void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() throws Exception {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
@@ -36,27 +36,27 @@ public class HostBuilderTest {
     }
 
     @Test
-    public void testIllegalArgumentException1() {
+    void testIllegalArgumentException1() {
         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.hostFor("2001:0DB8::CD3/60"));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testIllegalArgumentException2() {
-        testDomain("test.invalid.domain.name?");
+    @Test
+    void testIllegalArgumentException2() {
+        assertThrows(IllegalArgumentException.class, () -> testDomain("test.invalid.domain.name?"));
     }
 
     private static void testIpv4(final String ip) {
-        final Host defaultInstance = IetfInetUtil.hostFor(ip);
+        final var defaultInstance = IetfInetUtil.hostFor(ip);
         assertEquals(new Host(new IpAddress(new Ipv4Address(ip))), defaultInstance);
     }
 
     private static void testIpv6(final String ip) {
-        final Host defaultInstance = IetfInetUtil.hostFor(ip);
+        final var defaultInstance = IetfInetUtil.hostFor(ip);
         assertEquals(new Host(new IpAddress(new Ipv6Address(ip))), defaultInstance);
     }
 
     private static void testDomain(final String ip) {
-        final Host defaultInstance = IetfInetUtil.hostFor(ip);
+        final var defaultInstance = IetfInetUtil.hostFor(ip);
         assertEquals(new Host(new DomainName(ip)), defaultInstance);
     }
 }
\ No newline at end of file
index 85c124d71f297cd308e5cdc1935d18deae9a0c78..053ebd163ffbe90083f66aef9ce1427333f0b501 100644 (file)
@@ -7,13 +7,12 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -24,63 +23,63 @@ import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class IetfInetUtilTest {
+class IetfInetUtilTest {
     @Test
-    public void testIpv4Address() {
-        final Ipv4AddressNoZone ipv4Address = new Ipv4AddressNoZone("192.168.1.1");
-        final Ipv4Prefix ipv4Prefix = new Ipv4Prefix("192.0.2.1/24");
-        final IpAddress ipAddress = new IpAddress(ipv4Address);
-        final IpPrefix ipPrefix = new IpPrefix(ipv4Prefix);
+    void testIpv4Address() {
+        final var ipv4Address = new Ipv4AddressNoZone("192.168.1.1");
+        final var ipv4Prefix = new Ipv4Prefix("192.0.2.1/24");
+        final var ipAddress = new IpAddress(ipv4Address);
+        final var ipPrefix = new IpPrefix(ipv4Prefix);
 
         assertEquals(ipv4Prefix, ipPrefix.getIpv4Prefix());
         assertEquals(ipAddress, new IpAddress(ipv4Address));
     }
 
     @Test
-    public void testIpv6Address() {
-        final Ipv6AddressNoZone ipv6Address = new Ipv6AddressNoZone("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
-        final Ipv6Prefix ipv6Prefix = new Ipv6Prefix("ff00::/8");
-        final IpAddress ipAddress = new IpAddress(ipv6Address);
-        final IpPrefix ipPrefix = new IpPrefix(ipv6Prefix);
+    void testIpv6Address() {
+        final var ipv6Address = new Ipv6AddressNoZone("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
+        final var ipv6Prefix = new Ipv6Prefix("ff00::/8");
+        final var ipAddress = new IpAddress(ipv6Address);
+        final var ipPrefix = new IpPrefix(ipv6Prefix);
 
         assertEquals(ipv6Prefix, ipPrefix.getIpv6Prefix());
         assertEquals(ipAddress, new IpAddress(ipv6Address));
     }
 
     @Test
-    public void testAddressToString() {
+    void testAddressToString() {
         assertEquals(new Ipv4Prefix("1.2.3.4/8"), IetfInetUtil.ipv4PrefixFor(new Ipv4Address("1.2.3.4%1"), 8));
         assertEquals(new Ipv6Prefix("ff00::/8"), IetfInetUtil.ipv6PrefixFor(new Ipv6Address("ff00::%bar"), 8));
     }
 
     @Test
-    public void testIpv4ZoneStripping() {
-        final Ipv4AddressNoZone noZone = new Ipv4AddressNoZone("1.2.3.4");
+    void testIpv4ZoneStripping() {
+        final var noZone = new Ipv4AddressNoZone("1.2.3.4");
         assertSame(noZone, IetfInetUtil.ipv4AddressNoZoneFor(noZone));
 
-        final Ipv4Address withoutZone = new Ipv4Address(noZone);
-        final Ipv4AddressNoZone stripped = IetfInetUtil.ipv4AddressNoZoneFor(withoutZone);
+        final var withoutZone = new Ipv4Address(noZone);
+        final var stripped = IetfInetUtil.ipv4AddressNoZoneFor(withoutZone);
         assertSame(withoutZone.getValue(), stripped.getValue());
 
         assertEquals(noZone, IetfInetUtil.ipv4AddressNoZoneFor(new Ipv4Address("1.2.3.4%1")));
     }
 
     @Test
-    public void testIpv6ZoneStripping() {
-        final Ipv6AddressNoZone noZone = new Ipv6AddressNoZone("ff00::");
+    void testIpv6ZoneStripping() {
+        final var noZone = new Ipv6AddressNoZone("ff00::");
         assertSame(noZone, IetfInetUtil.ipv6AddressNoZoneFor(noZone));
 
-        final Ipv6Address withoutZone = new Ipv6Address(noZone);
-        final Ipv6AddressNoZone stripped = IetfInetUtil.ipv6AddressNoZoneFor(withoutZone);
+        final var withoutZone = new Ipv6Address(noZone);
+        final var stripped = IetfInetUtil.ipv6AddressNoZoneFor(withoutZone);
         assertSame(withoutZone.getValue(), stripped.getValue());
 
         assertEquals(noZone, IetfInetUtil.ipv6AddressNoZoneFor(new Ipv6Address("ff00::%1")));
     }
 
     @Test
-    public void testIpToBytesAndBack() {
+    void testIpToBytesAndBack() {
         assertV4Equals("1.2.3.4");
         assertV4Equals("12.23.34.45");
         assertV4Equals("255.254.253.252");
@@ -115,40 +114,38 @@ public class IetfInetUtilTest {
     }
 
     @Test
-    public void illegalArrayLengthForAddressTest() {
+    void illegalArrayLengthForAddressTest() {
         final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
             () -> IetfInetUtil.ipAddressFor(new byte[] { 0, 0, 0 }));
         assertEquals("Invalid array length 3", ex.getMessage());
     }
 
     @Test
-    public void unhandledAddressTest() {
-        final InetAddress adr = mock(InetAddress.class);
+    void unhandledAddressTest() {
+        final var adr = mock(InetAddress.class);
         doReturn("testAddress").when(adr).toString();
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
-            () -> IetfInetUtil.ipAddressFor(adr));
+        final var ex = assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressFor(adr));
         assertEquals("Unhandled address testAddress", ex.getMessage());
     }
 
     @Test
-    public void illegalArrayLengthforPrefixTest() {
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+    void illegalArrayLengthforPrefixTest() {
+        final var ex = assertThrows(IllegalArgumentException.class,
             () -> IetfInetUtil.ipPrefixFor(new byte[] { 0, 0, 0 }, 0));
         assertEquals("Invalid array length 3", ex.getMessage());
     }
 
     @Test
-    public void illegalAddressforPrefixTest() {
-        final InetAddress adr = mock(InetAddress.class);
+    void illegalAddressforPrefixTest() {
+        final var adr = mock(InetAddress.class);
         doReturn("testAddress").when(adr).toString();
 
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
-            () -> IetfInetUtil.ipPrefixFor(adr, 0));
+        final var ex = assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipPrefixFor(adr, 0));
         assertEquals("Unhandled address testAddress", ex.getMessage());
     }
 
     @Test
-    public void ipv4Tests() {
+    void ipv4Tests() {
         assertEquals("1.2.3.4", IetfInetUtil.ipv4AddressFrom(new Ipv4Prefix("1.2.3.4/16")).getValue());
         final var ipv4address = new Ipv4Address("1.2.3.4");
         final var ipAddress = new IpAddress(ipv4address);
@@ -175,7 +172,7 @@ public class IetfInetUtilTest {
     }
 
     @Test
-    public void ipv6Tests() {
+    void ipv6Tests() {
         assertEquals("::0", IetfInetUtil.ipv6AddressFrom(new Ipv6Prefix("::0/128")).getValue());
         final var ipv6address = new Ipv6Address("::0");
         final var ipAddress = new IpAddress(ipv6address);
@@ -205,7 +202,7 @@ public class IetfInetUtilTest {
     }
 
     @Test
-    public void prefixTest() {
+    void prefixTest() {
         assertEquals(new IpPrefix(new Ipv4Prefix("0.0.0.0/16")),
             IetfInetUtil.ipPrefixFor(IetfInetUtil.inetAddressFor(new IpAddress(new Ipv4Address("0.0.0.0"))), 16));
         assertEquals(new IpPrefix(new Ipv6Prefix("::/64")),
@@ -218,53 +215,50 @@ public class IetfInetUtilTest {
     }
 
     @Test
-    public void inetAddressTest() {
-        assertThat(IetfInetUtil.inetAddressFor(new IpAddress(new Ipv4Address("1.2.3.4"))),
-            instanceOf(Inet4Address.class));
-        assertThat(IetfInetUtil.inetAddressFor(new IpAddress(new Ipv6Address("FE80::2002:B3FF:FE1E:8329"))),
-            instanceOf(Inet6Address.class));
+    void inetAddressTest() {
+        assertInstanceOf(Inet4Address.class, IetfInetUtil.inetAddressFor(new IpAddress(new Ipv4Address("1.2.3.4"))));
+        assertInstanceOf(Inet6Address.class,
+            IetfInetUtil.inetAddressFor(new IpAddress(new Ipv6Address("FE80::2002:B3FF:FE1E:8329"))));
     }
 
     @Test
-    public void inet4AddressForWithExceptionTest() {
-        final Ipv4Address ipClass = mock(Ipv4Address.class);
+    void inet4AddressForWithExceptionTest() {
+        final var ipClass = mock(Ipv4Address.class);
         doReturn("testClass").when(ipClass).toString();
         doAnswer(inv -> {
             throw new UnknownHostException();
         }).when(ipClass).getValue();
 
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
-            () -> IetfInetUtil.inet4AddressFor(ipClass));
+        final var ex = assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.inet4AddressFor(ipClass));
         assertEquals("Invalid address testClass", ex.getMessage());
     }
 
     @Test
-    public void inet6AddressForWithExceptionTest() {
-        final Ipv6Address ipClass = mock(Ipv6Address.class);
+    void inet6AddressForWithExceptionTest() {
+        final var ipClass = mock(Ipv6Address.class);
         doReturn("testClass").when(ipClass).toString();
         doAnswer(inv -> {
             throw new UnknownHostException();
         }).when(ipClass).getValue();
 
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
-            () -> IetfInetUtil.inet6AddressFor(ipClass));
+        final var ex = assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.inet6AddressFor(ipClass));
         assertEquals("Invalid address testClass", ex.getMessage());
     }
 
     @Test
-    public void testIpv4AddressForBits() {
+    void testIpv4AddressForBits() {
         assertEquals("1.2.3.4", IetfInetUtil.ipv4AddressFor(0x01020304).getValue());
         assertEquals("255.255.255.255", IetfInetUtil.ipv4AddressFor(0xFFFFFFFF).getValue());
     }
 
     @Test
-    public void testIpv4AddressBits() {
+    void testIpv4AddressBits() {
         assertEquals(0x01020304, IetfInetUtil.ipv4AddressBits(new Ipv4Address("1.2.3.4")));
         assertEquals(0xFFFFFFFF, IetfInetUtil.ipv4AddressBits(new Ipv4Address("255.255.255.255")));
     }
 
     @Test
-    public void testIpv4AddressNoZoneBits() {
+    void testIpv4AddressNoZoneBits() {
         assertEquals(0x01020304, IetfInetUtil.ipv4AddressNoZoneBits(new Ipv4AddressNoZone("1.2.3.4")));
         assertEquals(0xFFFFFFFF, IetfInetUtil.ipv4AddressNoZoneBits(new Ipv4AddressNoZone("255.255.255.255")));
     }
index 2793731f137711d589ba4ecab305074d8e37d904..ff1689b9e5f00291e559f9e04177648d77e00a1a 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class IpAddressBuilderTest {
+class IpAddressBuilderTest {
     @Test
-    public void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() throws Exception {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
@@ -33,22 +33,22 @@ public class IpAddressBuilderTest {
     }
 
     @Test
-    public void testIllegalArgumentException1() {
+    void testIllegalArgumentException1() {
         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressFor("badIp"));
     }
 
     @Test
-    public void testIllegalArgumentException2() {
+    void testIllegalArgumentException2() {
         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressFor("2001:0DB8::CD3/60"));
     }
 
     private static void testIpv4(final String ip) {
-        final IpAddress defaultInstance = IetfInetUtil.ipAddressFor(ip);
+        final var defaultInstance = IetfInetUtil.ipAddressFor(ip);
         assertEquals(new IpAddress(new Ipv4Address(ip)), defaultInstance);
     }
 
     private static void testIpv6(final String ip) {
-        final IpAddress defaultInstance = IetfInetUtil.ipAddressFor(ip);
+        final var defaultInstance = IetfInetUtil.ipAddressFor(ip);
         assertEquals(new IpAddress(new Ipv6Address(ip)), defaultInstance);
     }
 }
\ No newline at end of file
index d55793698dfe5b695a6ddcfbb2b1e47bf467d117..bf4ea48bab4b337e9821e6b53359d12d061731d3 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class IpAddressNoZoneBuilderTest {
+class IpAddressNoZoneBuilderTest {
     @Test
-    public void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() throws Exception {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
@@ -33,7 +33,7 @@ public class IpAddressNoZoneBuilderTest {
     }
 
     @Test
-    public void testIllegalArgumentException() {
+    void testIllegalArgumentException() {
         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressNoZoneFor("2001:0DB8::CD3/60"));
     }
 
index 68b3b22344c0b492a7f3f05466a7e1d537470197..fb2ddb498375e832a048b2ee83502a8764d6ad81 100644 (file)
@@ -7,20 +7,20 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class IpPrefixBuilderTest {
+class IpPrefixBuilderTest {
     @Test
-    public void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() throws Exception {
         testIpv6("ff00::/8");
         testIpv4("192.0.2.1/24");
     }
 
     @Test
-    public void testIllegalArgumentException1() {
+    void testIllegalArgumentException1() {
         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipPrefixFor("badIp"));
     }