@Test public void testGlobal() { // Test integer and string config.putGlobal("section.int", 1); config.putGlobal("section.string", "2"); final int one = config.getGlobal("section.int", Integer.class).or(-1); assertEquals(one, 1); final String two = config.getGlobal("section.string").or("-1"); assertEquals(two, "2"); // Test overwriting a value that already exists config.putGlobal("section.string", "3"); final String three = config.getGlobal("section.string").or("-1"); assertEquals(three, "3"); }
@Test public void testGetAllGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section2.int", 3); config.putGlobal("section2.subsection.string", "4"); Map<String, String> all = config.getAllGlobal(); Map<String, String> expected = ImmutableMap.of( "section1.int", "1", "section1.subsection.string", "2", "section1.subsection.subsub.int", "1", "section2.int", "3", "section2.subsection.string", "4"); assertEquals(expected, all); }
@Test public void testGetAllSubsectionsGlobal() { // Test integer and string config.putGlobal("section1.subsection1.int", 1); config.putGlobal("section1.subsection2.string", "2"); config.putGlobal("section1.subsection1.subsub1.int", 1); config.putGlobal("section1.subsection2.subsub2.string", "2"); config.putGlobal("section2.subsection3.int", 3); config.putGlobal("section2.subsection4.string", "4"); List<String> allSubsections = config.getAllSubsectionsGlobal("section1"); Set<String> expected = ImmutableSet.of("subsection1", "subsection2", "subsection1.subsub1", "subsection2.subsub2"); assertEquals(expected, new HashSet<String>(allSubsections)); }