ShiroIniParser extends NonParameterizedTypeParser<Ini> { @Override public Ini doParse(String raw) throws IllegalArgumentException { Ini ini; try { ini = Ini.fromResourcePath(raw); } catch (ConfigurationException e) { throw new ShiroConfigurationException(e); } Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames()); if (presentSections.isEmpty()) { throw new MissingSectionsException(); } Set<String> extraSections = Sets.difference(presentSections, ALLOWED_SECTION_NAMES); if (!extraSections.isEmpty()) { throw new ExtraSectionsException(extraSections); } return ini; }  @Override Ini doParse(String raw);  }
@Test public void testDoParseSuccess() { assertEquals( ShiroIniParser.ALLOWED_SECTION_NAMES, parser.doParse( ShiroIniParserTest.class.getResource(EXAMPLE_RESOURCE).toString()).getSectionNames()); }
@Test public void testDoParseOptionalSections() { assertEquals( ImmutableSet.of(IniRealm.ROLES_SECTION_NAME), parser .doParse(ShiroIniParserTest.class.getResource(MISSING_SECTIONS_SHIRO_INI).toString()) .getSectionNames()); }
@Test(expected = ShiroConfigurationException.class) public void testDoParseNonexistent() { parser.doParse(ResourceUtils.CLASSPATH_PREFIX + NONEXISTENT_RESOURCE); }
@Test(expected = ExtraSectionsException.class) public void testDoParseExtraSections() { parser.doParse(getClass().getResource(EXTRA_SECTIONS_SHIRO_INI).toString()); }
@Test(expected = MissingSectionsException.class) public void testDoParseMissingSections() { parser.doParse(getClass().getResource(NO_SECTIONS_SHURO_INI).toString()); }