### Question:
PublicSuffixListParser { public List<PublicSuffixList> parseByType(final Reader reader) throws IOException { final List<PublicSuffixList> result = new ArrayList<>(2); final BufferedReader r = new BufferedReader(reader); DomainType domainType = null; List<String> rules = null; List<String> exceptions = null; String line; while ((line = r.readLine()) != null) { if (line.isEmpty()) { continue; } if (line.startsWith(" if (domainType == null) { if (line.contains("===BEGIN ICANN DOMAINS===")) { domainType = DomainType.ICANN; } else if (line.contains("===BEGIN PRIVATE DOMAINS===")) { domainType = DomainType.PRIVATE; } } else { if (line.contains("===END ICANN DOMAINS===") || line.contains("===END PRIVATE DOMAINS===")) { if (rules != null) { result.add(new PublicSuffixList(domainType, rules, exceptions)); } domainType = null; rules = null; exceptions = null; } } continue; } if (domainType == null) { continue; } if (line.startsWith(".")) { line = line.substring(1); } final boolean isException = line.startsWith("!"); if (isException) { line = line.substring(1); } if (isException) { if (exceptions == null) { exceptions = new ArrayList<>(); } exceptions.add(line); } else { if (rules == null) { rules = new ArrayList<>(); } rules.add(line); } } return result; } PublicSuffixListParser(); PublicSuffixList parse(final Reader reader); List<PublicSuffixList> parseByType(final Reader reader);  }### Answer:
@Test public void testParseByType() throws Exception { final ClassLoader classLoader = getClass().getClassLoader(); final InputStream in = classLoader.getResourceAsStream("suffixlist2.txt"); Assert.assertNotNull(in); final List<PublicSuffixList> suffixLists; try { final PublicSuffixListParser parser = new PublicSuffixListParser(); suffixLists = parser.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8)); } finally { in.close(); } Assert.assertNotNull(suffixLists); Assert.assertEquals(2, suffixLists.size()); final PublicSuffixList publicSuffixList1 = suffixLists.get(0); Assert.assertNotNull(publicSuffixList1); Assert.assertEquals(DomainType.ICANN, publicSuffixList1.getType()); Assert.assertEquals(Arrays.asList("jp", "ac.jp", "*.tokyo.jp"), publicSuffixList1.getRules()); Assert.assertEquals(Arrays.asList("metro.tokyo.jp"), publicSuffixList1.getExceptions()); final PublicSuffixList publicSuffixList2 = suffixLists.get(1); Assert.assertNotNull(publicSuffixList2); Assert.assertEquals(DomainType.PRIVATE, publicSuffixList2.getType()); Assert.assertEquals(Arrays.asList("googleapis.com", "googlecode.com"), publicSuffixList2.getRules()); Assert.assertEquals(Collections.<String>emptyList(), publicSuffixList2.getExceptions()); }