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 package org.apache.hc.client5.http;
28
29 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31
32 import java.net.InetAddress;
33 import java.net.UnknownHostException;
34
35 import org.junit.jupiter.api.Test;
36
37 public class SystemDefaultDnsResolverTest {
38
39 @Test
40 void resolve() throws UnknownHostException {
41 final SystemDefaultDnsResolver resolver = SystemDefaultDnsResolver.INSTANCE;
42 final InetAddress[] result1 = resolver.resolve("127.0.0.1");
43 assertEquals(1, result1.length);
44 assertArrayEquals(new byte[]{127, 0, 0, 1}, result1[0].getAddress());
45 }
46
47 @Test
48 void resolveIPv6ZoneId() throws UnknownHostException {
49 final SystemDefaultDnsResolver resolver = SystemDefaultDnsResolver.INSTANCE;
50
51
52 final InetAddress[] result = resolver.resolve("[fe80::221:b7ff:fe8a:57d5%en4]");
53 assertEquals(1, result.length);
54 assertArrayEquals(new byte[]{(byte) 0xfe, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x21, (byte) 0xb7, (byte) 0xff, (byte) 0xfe, (byte) 0x8a, 0x57, (byte) 0xd5}, result[0].getAddress());
55
56 }
57
58 }