@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)); }
@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)); }
@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 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 testGetAllSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertEquals(ImmutableMap.of("int", "1"), config.getAllSectionGlobal("section1")); assertEquals(ImmutableMap.of("string", "2"), config.getAllSectionGlobal("section1.subsection")); assertEquals(ImmutableMap.of("int", "1", "string", "4"), config.getAllSectionGlobal("section1.subsection.subsub")); }
@Test public void testGetAllSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertEquals(ImmutableMap.of("int", "1"), config.getAllSectionGlobal("section1")); assertEquals(ImmutableMap.of("string", "2"), config.getAllSectionGlobal("section1.subsection")); assertEquals(ImmutableMap.of("int", "1", "string", "4"), config.getAllSectionGlobal("section1.subsection.subsub")); }
@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 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 testRemoveGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeGlobal("section1.int"); assertFalse(config.getGlobal("section1.int").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); config.removeGlobal("section1.subsection.subsub.string"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); }
@Test public void testNoUserHome() { final Platform platform = mock(Platform.class); when(platform.getUserHome()).thenReturn(null); final ConfigDatabase config = createDatabase(platform); exception.expect(ConfigException.class); config.putGlobal("section.int", 1); }
@Test public void testRemoveGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeGlobal("section1.int"); assertFalse(config.getGlobal("section1.int").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); config.removeGlobal("section1.subsection.subsub.string"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); }
@Test public void testNoUserHome() { final Platform platform = mock(Platform.class); when(platform.getUserHome()).thenReturn(null); final ConfigDatabase config = createDatabase(platform); exception.expect(ConfigException.class); config.putGlobal("section.int", 1); }
@Test public void testRemoveSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.int").isPresent()); config.removeSectionGlobal("section1.subsection.subsub"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertFalse(config.getGlobal("section1.subsection.subsub.int").isPresent()); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeSectionGlobal("section1"); assertFalse(config.getGlobal("section1.int").isPresent()); } }
@Test public void testRemoveSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.int").isPresent()); config.removeSectionGlobal("section1.subsection.subsub"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertFalse(config.getGlobal("section1.subsection.subsub.int").isPresent()); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeSectionGlobal("section1"); assertFalse(config.getGlobal("section1.int").isPresent()); } }
config.putGlobal(name, value); } else { config.put(name, value);
config.putGlobal(name, value); } else { config.put(name, value);