HostsFileParserTest Class — netty Architecture
Architecture documentation for the HostsFileParserTest class in HostsFileParserTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9bffb4cb_e8fd_2d8f_6c96_65319f649e97["HostsFileParserTest"] 84da173f_8412_68f8_06d1_770b19aaaf2a["HostsFileParserTest.java"] 9bffb4cb_e8fd_2d8f_6c96_65319f649e97 -->|defined in| 84da173f_8412_68f8_06d1_770b19aaaf2a eabbca6d_9baf_512a_04f9_17cdb7577d70["testParse()"] 9bffb4cb_e8fd_2d8f_6c96_65319f649e97 -->|method| eabbca6d_9baf_512a_04f9_17cdb7577d70 23565682_0cb3_4313_9726_34efe18aa650["testParseUnicode()"] 9bffb4cb_e8fd_2d8f_6c96_65319f649e97 -->|method| 23565682_0cb3_4313_9726_34efe18aa650 e5d0663f_f1b3_73f1_601c_3b21d5d95190["testParseMultipleCharsets()"] 9bffb4cb_e8fd_2d8f_6c96_65319f649e97 -->|method| e5d0663f_f1b3_73f1_601c_3b21d5d95190 32fc28fd_feca_383d_44f0_6ceb966502a4["testParseFile()"] 9bffb4cb_e8fd_2d8f_6c96_65319f649e97 -->|method| 32fc28fd_feca_383d_44f0_6ceb966502a4
Relationship Graph
Source Code
resolver/src/test/java/io/netty/resolver/HostsFileParserTest.java lines 34–103
public class HostsFileParserTest {
@Test
public void testParse() throws IOException {
String hostsString = new StringBuilder()
.append("127.0.0.1 host1").append("\n") // single hostname, separated with blanks
.append("::1 host1").append("\n") // same as above, but IPv6
.append("\n") // empty line
.append("192.168.0.1\thost2").append("\n") // single hostname, separated with tabs
.append("#comment").append("\n") // comment at the beginning of the line
.append(" #comment ").append("\n") // comment in the middle of the line
.append("192.168.0.2 host3 #comment").append("\n") // comment after hostname
.append("192.168.0.3 host4 host5 host6").append("\n") // multiple aliases
.append("192.168.0.4 host4").append("\n") // host mapped to a second address, must be ignored
.append("192.168.0.5 HOST7").append("\n") // uppercase host, should match lowercase host
.append("192.168.0.6 host7").append("\n") // should be ignored since we have the uppercase host already
.toString();
HostsFileEntries entries = HostsFileParser.parse(new BufferedReader(new StringReader(hostsString)));
Map<String, Inet4Address> inet4Entries = entries.inet4Entries();
Map<String, Inet6Address> inet6Entries = entries.inet6Entries();
assertEquals(7, inet4Entries.size(), "Expected 7 IPv4 entries");
assertEquals(1, inet6Entries.size(), "Expected 1 IPv6 entries");
assertEquals("127.0.0.1", inet4Entries.get("host1").getHostAddress());
assertEquals("192.168.0.1", inet4Entries.get("host2").getHostAddress());
assertEquals("192.168.0.2", inet4Entries.get("host3").getHostAddress());
assertEquals("192.168.0.3", inet4Entries.get("host4").getHostAddress());
assertEquals("192.168.0.3", inet4Entries.get("host5").getHostAddress());
assertEquals("192.168.0.3", inet4Entries.get("host6").getHostAddress());
assertNotNull(inet4Entries.get("host7"), "uppercase host doesn't resolve");
assertEquals("192.168.0.5", inet4Entries.get("host7").getHostAddress());
assertEquals("0:0:0:0:0:0:0:1", inet6Entries.get("host1").getHostAddress());
}
@Test
public void testParseUnicode() throws IOException {
final Charset unicodeCharset;
try {
unicodeCharset = Charset.forName("unicode");
} catch (UnsupportedCharsetException e) {
return;
}
testParseFile(HostsFileParser.parse(
ResourcesUtil.getFile(getClass(), "hosts-unicode"), unicodeCharset));
}
@Test
public void testParseMultipleCharsets() throws IOException {
final Charset unicodeCharset;
try {
unicodeCharset = Charset.forName("unicode");
} catch (UnsupportedCharsetException e) {
return;
}
testParseFile(HostsFileParser.parse(ResourcesUtil.getFile(getClass(), "hosts-unicode"),
CharsetUtil.UTF_8, CharsetUtil.ISO_8859_1, unicodeCharset));
}
private static void testParseFile(HostsFileEntries entries) throws IOException {
Map<String, Inet4Address> inet4Entries = entries.inet4Entries();
Map<String, Inet6Address> inet6Entries = entries.inet6Entries();
assertEquals(2, inet4Entries.size(), "Expected 2 IPv4 entries");
assertEquals(1, inet6Entries.size(), "Expected 1 IPv6 entries");
assertEquals("127.0.0.1", inet4Entries.get("localhost").getHostAddress());
assertEquals("255.255.255.255", inet4Entries.get("broadcasthost").getHostAddress());
assertEquals("0:0:0:0:0:0:0:1", inet6Entries.get("localhost").getHostAddress());
}
}
Source
Frequently Asked Questions
What is the HostsFileParserTest class?
HostsFileParserTest is a class in the netty codebase, defined in resolver/src/test/java/io/netty/resolver/HostsFileParserTest.java.
Where is HostsFileParserTest defined?
HostsFileParserTest is defined in resolver/src/test/java/io/netty/resolver/HostsFileParserTest.java at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free