1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.text.lookup;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24
25 import java.net.InetAddress;
26
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 class InetAddressStringLookupLoopbackAddressTest {
33
34 @Test
35 void testAddress() {
36 assertEquals(InetAddress.getLoopbackAddress().getHostAddress(), InetAddressStringLookup.LOOPACK_ADDRESS.apply("address"));
37 }
38
39 @Test
40 void testBadKey() {
41 assertThrows(IllegalArgumentException.class, () -> InetAddressStringLookup.LOOPACK_ADDRESS.apply("FOO"));
42 }
43
44 @Test
45 void testCanonicalName() {
46 assertEquals(InetAddress.getLoopbackAddress().getCanonicalHostName(), InetAddressStringLookup.LOOPACK_ADDRESS.apply("canonical-name"));
47 }
48
49 @Test
50 void testName() {
51 assertEquals(InetAddress.getLoopbackAddress().getHostName(), InetAddressStringLookup.LOOPACK_ADDRESS.apply("name"));
52 }
53
54 @Test
55 void testNull() {
56 assertNull(InetAddressStringLookup.LOOPACK_ADDRESS.apply(null));
57 }
58
59 @Test
60 void testToString() {
61
62 assertFalse(InetAddressStringLookup.LOOPACK_ADDRESS.toString().isEmpty());
63 }
64
65 }