eabdab9522381c64ca044097592a55eab91a60bd
[mdsal.git] / 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
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.lang.reflect.Constructor;
15 import org.junit.Test;
16
17 public class IpPrefixBuilderTest {
18
19     @Test
20     public void testGetDefaultInstance() throws Exception {
21         final Constructor<IpPrefixBuilder> constructor = IpPrefixBuilder.class.getDeclaredConstructor();
22         assertFalse(constructor.isAccessible());
23         constructor.setAccessible(true);
24         final IpPrefixBuilder newInstance = constructor.newInstance();
25         assertNotNull(newInstance);
26
27         testIpv6("ff00::/8");
28         testIpv4("192.0.2.1/24");
29     }
30
31     @Test(expected = IllegalArgumentException.class)
32     public void testIllegalArgumentException1() {
33         IpPrefixBuilder.getDefaultInstance("badIp");
34     }
35
36     private static void testIpv4(final String ip) {
37         final IpPrefix defaultInstance = IpPrefixBuilder.getDefaultInstance(ip);
38         assertEquals(new IpPrefix(new Ipv4Prefix(ip)), defaultInstance);
39     }
40
41     private static void testIpv6(final String ip) {
42         final IpPrefix defaultInstance = IpPrefixBuilder.getDefaultInstance(ip);
43         assertEquals(new IpPrefix(new Ipv6Prefix(ip)), defaultInstance);
44     }
45 }