-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathIPv6ConverterTest.java
64 lines (54 loc) · 1.89 KB
/
IPv6ConverterTest.java
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.thealgorithms.conversions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.UnknownHostException;
import org.junit.jupiter.api.Test;
public class IPv6ConverterTest {
private static final String VALID_IPV4 = "192."
+ "0."
+ "2."
+ "128";
private static final String EXPECTED_IPV6_MAPPED = ":"
+ ":ff"
+ "ff"
+ ":19"
+ "2."
+ "0."
+ "2.128";
private static final String INVALID_IPV6_MAPPED = "2001:"
+ "db8"
+ ":"
+ ":1";
private static final String INVALID_IPV4 = "999."
+ "999."
+ "999."
+ "999";
private static final String INVALID_IPV6_FORMAT = "invalid:ipv6"
+ "::address";
private static final String EMPTY_STRING = "";
@Test
public void testIpv4ToIpv6ValidInput() throws UnknownHostException {
String actualIpv6 = IPv6Converter.ipv4ToIpv6(VALID_IPV4);
assertEquals(EXPECTED_IPV6_MAPPED, actualIpv6);
}
@Test
public void testIpv6ToIpv4InvalidIPv6MappedAddress() {
assertThrows(IllegalArgumentException.class, () -> IPv6Converter.ipv6ToIpv4(INVALID_IPV6_MAPPED));
}
@Test
public void testIpv4ToIpv6InvalidIPv4Address() {
assertThrows(UnknownHostException.class, () -> IPv6Converter.ipv4ToIpv6(INVALID_IPV4));
}
@Test
public void testIpv6ToIpv4InvalidFormat() {
assertThrows(UnknownHostException.class, () -> IPv6Converter.ipv6ToIpv4(INVALID_IPV6_FORMAT));
}
@Test
public void testIpv4ToIpv6EmptyString() {
assertThrows(UnknownHostException.class, () -> IPv6Converter.ipv4ToIpv6(EMPTY_STRING));
}
@Test
public void testIpv6ToIpv4EmptyString() {
assertThrows(IllegalArgumentException.class, () -> IPv6Converter.ipv6ToIpv4(EMPTY_STRING));
}
}