public class IniFileReaderTest extends TestCase
{
public void testLoad()
{
IniFileReader ifr = new IniFileReader();
File iniFile = null;
try
{
iniFile = File.createTempFile("temp", "ini");
iniFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new FileWriter(iniFile));
writer.write("# Global Comment1\n");
writer.write("globalprop1=globalval1\n");
writer.write("globalprop2=globalval2\n");
writer.write("\n");
writer.write("[Section1] # Comment on Section\n");
writer.write("key1=val1 # Comment on Value\n");
writer.write("key2=val2\n");
writer.write("\n");
writer.write("#Section2 Comment\n");
writer.write("[Section2]\n");
writer.write("key3=val3\n");
writer.write("key4=val4\n");
writer.write("key5=val5\n");
writer.write("\n");
writer.write("[Section3]\n");
writer.write("key6=val6\n");
writer.write("key7=val7\n");
writer.write("\n");
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
fail("Unable to create temporary File");
}
ifr.load(iniFile.getAbsolutePath());
Map<String, Properties> sections = ifr.getSections();
assertNotNull("Sections not null", sections);
assertEquals("Have 4 sections", sections.keySet().size(), 4);
assertTrue("Get globalprop1", sections.get("").getProperty("globalprop1").equals("globalval1"));
assertTrue("Get globalprop2", sections.get("").getProperty("globalprop2").equals("globalval2"));
assertNotNull("Section1 not null", sections.get("Section1"));