@Test public void testSectionNames() { ConfigurationSection section; ConfigurationSection buffer; section = new ConfigurationSection(); // Create 10 variables. buffer = null; for(int i = 0; i < 10; i++) buffer = section.addSection("sect" + i); assertSectionNames(section, 10); // Removes the last section by value, makes sure we're in a coherent state. assert section.removeSection(buffer); assertSectionNames(section, 9); // Removes the last section by name, makes sure we're in a coherent state. assert section.removeSection("sect8") != null; assertSectionNames(section, 8); for(int i = 0; i < 8; i++) assert section.removeSection("sect" + i) != null; assertSectionNames(section, 0); } }
/** * Tests the {@link ConfigurationSection#setVariable(String, String)} method. * @param first first value to which the test variable should be set. * @param second second value to which the test variable should be set. * @param expected expected return value of the second call to * {@link ConfigurationSection#setVariable(String, String)}. */ @Test(dataProvider = "setVariable") public void testSetVariable(String first, String second, boolean expected) { ConfigurationSection section; section = new ConfigurationSection(); assert section.setVariable("var", first); assertVariable(section, "var", first); assert expected == section.setVariable("var", second); assertVariable(section, "var", second); }
/** * Tests the {@link ConfigurationSection#variableNames()} method. */ @Test public void testVariableNames() { ConfigurationSection section; section = new ConfigurationSection(); // Create 10 variables. for(int i = 0; i < 10; i++) section.setVariable("var" + i, "value"); assertVariableNames(section, 10); section.setVariable("var9", ""); assertVariableNames(section, 9); section.setVariable("var8", null); assertVariableNames(section, 8); section.removeVariable("var7"); assertVariableNames(section, 7); for(int i = 0; i < 7; i++) section.removeVariable("var" + i); assertVariableNames(section, 0); }
/** * Tests the {@link ConfigurationSection#removeVariable(String)} method. * @param value value to which the variable should be set before being removed. */ @Test(dataProvider = "setVariable") public void testRemoveVariable(String value) { ConfigurationSection section; section = new ConfigurationSection(); assert section.setVariable("var", value); assertVariable(section, "var", value); assert value == null ? section.removeVariable("var") == null : section.removeVariable("var").equals(value); }