@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_propertyAtStart() { String invalid = "a = x\n"; IniFile.of(CharSource.wrap(invalid)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_emptyKey() { String invalid = "" + "[section]\n" + "= y\n"; IniFile.of(CharSource.wrap(invalid)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_badSection() { String invalid = "" + "[section\n" + "b\n"; IniFile.of(CharSource.wrap(invalid)); }
@VisibleForTesting static ImmutableMap<String, HolidayCalendar> loadFromIni(String filename) { List<ResourceLocator> resources = ResourceConfig.orderedResources(filename); Map<String, HolidayCalendar> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { IniFile ini = IniFile.of(resource.getCharSource()); for (String sectionName : ini.sections()) { PropertySet section = ini.section(sectionName); HolidayCalendar parsed = parseHolidayCalendar(sectionName, section); map.put(parsed.getName(), parsed); map.putIfAbsent(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Holiday Calendar INI file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_duplicateSection() { String invalid = "" + "[section]\n" + "a = y\n" + "[section]\n" + "b = y\n"; IniFile.of(CharSource.wrap(invalid)); }
@VisibleForTesting static ImmutableMap<Currency, HolidayCalendarId> loadDefaultsFromIni(String filename) { List<ResourceLocator> resources = ResourceConfig.orderedResources(filename); Map<Currency, HolidayCalendarId> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { IniFile ini = IniFile.of(resource.getCharSource()); PropertySet section = ini.section("defaultByCurrency"); for (String currencyCode : section.keys()) { map.put(Currency.of(currencyCode), HolidayCalendarId.of(section.value(currencyCode))); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Holiday Calendar Defaults INI file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
public void test_of_ioException() { assertThrows( () -> IniFile.of(Files.asCharSource(new File("src/test/resources"), StandardCharsets.UTF_8)), UncheckedIOException.class); }
public void test_equalsHashCode() { IniFile a1 = IniFile.of(CharSource.wrap(INI1)); IniFile a2 = IniFile.of(CharSource.wrap(INI1)); IniFile b = IniFile.of(CharSource.wrap(INI2)); assertEquals(a1.equals(a1), true); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(null), false); assertEquals(a1.equals(ANOTHER_TYPE), false); assertEquals(a1.hashCode(), a2.hashCode()); }
public void test_of_escaping() { IniFile test = IniFile.of(CharSource.wrap(INI4)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a=d=", "x"); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); }
public void test_of_propertyNoEquals() { IniFile test = IniFile.of(CharSource.wrap("[section]\na\n")); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", ""); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertEquals(test.section("section").valueList("a"), ImmutableList.of("")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "")); assertEquals(test.toString(), "{section={a=[]}}"); }
private TradeReportTemplate parseIni(String resourceName) { ResourceLocator locator = ResourceLocator.of("classpath:" + resourceName); IniFile ini = IniFile.of(locator.getCharSource()); TradeReportTemplateIniLoader loader = new TradeReportTemplateIniLoader(); return loader.load(ini); }
public void test_equalsHashCode_section() { IniFile a1 = IniFile.of(CharSource.wrap(INI1)); IniFile a2 = IniFile.of(CharSource.wrap(INI1)); IniFile b = IniFile.of(CharSource.wrap(INI2)); assertEquals(a1.section("name").equals(a1.section("name")), true); assertEquals(a1.section("name").equals(a2.section("name")), true); assertEquals(a1.section("name").equals(b.section("section")), false); assertEquals(a1.section("name").equals(null), false); assertEquals(a1.section("name").equals(ANOTHER_TYPE), false); assertEquals(a1.section("name").hashCode(), a2.section("name").hashCode()); }
public void test_of_list() { IniFile test = IniFile.of(CharSource.wrap(INI3)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "x", "a", "y"); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertThrowsIllegalArg(() -> test.section("section").value("a")); assertEquals(test.section("section").valueList("a"), ImmutableList.of("x", "y")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y")); assertEquals(test.toString(), "{section={a=[x, y]}}"); }
public void test_of_noLists() { IniFile test = IniFile.of(CharSource.wrap(INI1)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("c", "x", "b", "y", "a", "z"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("a", "m", "b", "n");