Home / Class/ HostsFileEntriesProviderTest Class — netty Architecture

HostsFileEntriesProviderTest Class — netty Architecture

Architecture documentation for the HostsFileEntriesProviderTest class in HostsFileEntriesProviderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a["HostsFileEntriesProviderTest"]
  2cb1378c_2023_82c5_72e2_5b94b31ec841["HostsFileEntriesProviderTest.java"]
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a -->|defined in| 2cb1378c_2023_82c5_72e2_5b94b31ec841
  d7285d3f_0f27_e448_40d2_ab8208cf4f80["testParse()"]
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a -->|method| d7285d3f_0f27_e448_40d2_ab8208cf4f80
  b63304fa_6f1e_8669_85fc_0491ae543654["testCharsetInputValidation()"]
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a -->|method| b63304fa_6f1e_8669_85fc_0491ae543654
  3e8fd531_01ec_087f_6f5a_ef2a1ead3b84["testFileInputValidation()"]
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a -->|method| 3e8fd531_01ec_087f_6f5a_ef2a1ead3b84
  6b28e550_4c7b_597b_4894_e5b69828186d["testReaderInputValidation()"]
  5b51bb65_8521_08a0_dc9a_df2dc1b8745a -->|method| 6b28e550_4c7b_597b_4894_e5b69828186d

Relationship Graph

Source Code

resolver/src/test/java/io/netty/resolver/HostsFileEntriesProviderTest.java lines 35–146

class HostsFileEntriesProviderTest {

    @Test
    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 considered
                .append("192.168.0.5  HOST7").append("\n") // uppercase host, should match lowercase host
                .append("192.168.0.6  host7").append("\n") // must be considered
                .toString();

        HostsFileEntriesProvider entries = HostsFileEntriesProvider.parser()
                .parse(new BufferedReader(new StringReader(hostsString)));
        Map<String, List<InetAddress>> inet4Entries = entries.ipv4Entries();
        Map<String, List<InetAddress>> inet6Entries = entries.ipv6Entries();

        assertEquals(7, inet4Entries.size(), "Expected 7 IPv4 entries");
        assertEquals(1, inet6Entries.size(), "Expected 1 IPv6 entries");

        assertEquals(1, inet4Entries.get("host1").size());
        assertEquals("127.0.0.1", inet4Entries.get("host1").get(0).getHostAddress());

        assertEquals(1, inet4Entries.get("host2").size());
        assertEquals("192.168.0.1", inet4Entries.get("host2").get(0).getHostAddress());

        assertEquals(1, inet4Entries.get("host3").size());
        assertEquals("192.168.0.2", inet4Entries.get("host3").get(0).getHostAddress());

        assertEquals(2, inet4Entries.get("host4").size());
        assertEquals("192.168.0.3", inet4Entries.get("host4").get(0).getHostAddress());
        assertEquals("192.168.0.4", inet4Entries.get("host4").get(1).getHostAddress());

        assertEquals(1, inet4Entries.get("host5").size());
        assertEquals("192.168.0.3", inet4Entries.get("host5").get(0).getHostAddress());

        assertEquals(1, inet4Entries.get("host6").size());
        assertEquals("192.168.0.3", inet4Entries.get("host6").get(0).getHostAddress());

        assertNotNull(inet4Entries.get("host7"), "Uppercase host doesn't resolve");
        assertEquals(2, inet4Entries.get("host7").size());
        assertEquals("192.168.0.5", inet4Entries.get("host7").get(0).getHostAddress());
        assertEquals("192.168.0.6", inet4Entries.get("host7").get(1).getHostAddress());

        assertEquals(1, inet6Entries.get("host1").size());
        assertEquals("0:0:0:0:0:0:0:1", inet6Entries.get("host1").get(0).getHostAddress());
    }

    @Test
    void testCharsetInputValidation() {
        assertThrows(NullPointerException.class, new Executable() {
            @Override
            public void execute() throws IOException {
                HostsFileEntriesProvider.parser().parse((Charset[]) null);
            }
        });

        assertThrows(NullPointerException.class, new Executable() {
            @Override
            public void execute() throws IOException {
                HostsFileEntriesProvider.parser().parse(new File(""), (Charset[]) null);
            }
        });

        assertThrows(NullPointerException.class, new Executable() {
            @Override
            public void execute() {
                HostsFileEntriesProvider.parser().parseSilently((Charset[]) null);
            }
        });

        assertThrows(NullPointerException.class, new Executable() {
            @Override
            public void execute() {
                HostsFileEntriesProvider.parser().parseSilently(new File(""), (Charset[]) null);

Frequently Asked Questions

What is the HostsFileEntriesProviderTest class?
HostsFileEntriesProviderTest is a class in the netty codebase, defined in resolver/src/test/java/io/netty/resolver/HostsFileEntriesProviderTest.java.
Where is HostsFileEntriesProviderTest defined?
HostsFileEntriesProviderTest is defined in resolver/src/test/java/io/netty/resolver/HostsFileEntriesProviderTest.java at line 35.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free