forked from eclipse-vertx/vertx-sql-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCidrTest.java
More file actions
48 lines (39 loc) · 1.39 KB
/
CidrTest.java
File metadata and controls
48 lines (39 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package io.vertx.pgclient.data;
import org.junit.Test;
import java.net.InetAddress;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class CidrTest extends DataTypeTestBase{
@Test
public void testValidIPv4() throws Exception {
InetAddress address = InetAddress.getByName("192.168.1.1");
Cidr cidr = new Cidr();
cidr.setAddress(address);
cidr.setNetmask(24);
assertEquals(address, cidr.getAddress());
assertEquals(Integer.valueOf(24), cidr.getNetmask());
}
@Test
public void testValidIPv6() throws Exception {
InetAddress address = InetAddress.getByName("fe80::f03c:91ff:feae:e944");
Cidr cidr = new Cidr();
cidr.setAddress(address);
cidr.setNetmask(64);
assertEquals(address, cidr.getAddress());
assertEquals(Integer.valueOf(64), cidr.getNetmask());
}
@Test
public void testInvalidNetmaskIPv4() throws Exception {
InetAddress address = InetAddress.getByName("192.168.1.1");
Cidr cidr = new Cidr();
cidr.setAddress(address);
assertThrows(IllegalArgumentException.class, () -> cidr.setNetmask(33));
}
@Test
public void testInvalidNetmaskIPv6() throws Exception {
InetAddress address = InetAddress.getByName("fe80::f03c:91ff:feae:e944");
Cidr cidr = new Cidr();
cidr.setAddress(address);
assertThrows(IllegalArgumentException.class, () -> cidr.setNetmask(129));
}
}