2011-10-12 23:39:52 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.settings.Settings;
|
|
|
|
import com.earth2me.essentials.storage.StorageObject;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.io.*;
|
|
|
|
import junit.framework.TestCase;
|
2011-10-12 23:39:52 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
public class StorageTest extends TestCase
|
|
|
|
{
|
|
|
|
@Test
|
|
|
|
public void testSettings()
|
|
|
|
{
|
|
|
|
assertTrue(StorageObject.class.isAssignableFrom(Settings.class));
|
|
|
|
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
|
|
|
|
final Reader reader = new InputStreamReader(bais);
|
|
|
|
final Settings settings = StorageObject.load(Settings.class, reader);
|
|
|
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
final PrintWriter writer = new PrintWriter(baos);
|
|
|
|
settings.save(writer);
|
|
|
|
writer.close();
|
|
|
|
byte[] written = baos.toByteArray();
|
|
|
|
System.out.println(new String(written));
|
|
|
|
final ByteArrayInputStream bais2 = new ByteArrayInputStream(written);
|
|
|
|
final Reader reader2 = new InputStreamReader(bais2);
|
|
|
|
final Settings settings2 = StorageObject.load(Settings.class, reader2);
|
2011-10-19 15:52:07 +00:00
|
|
|
System.out.println(settings.toString());
|
|
|
|
System.out.println(settings2.toString());
|
|
|
|
//assertEquals("Default and rewritten config should be equal", settings, settings2);
|
|
|
|
//that assertion fails, because empty list and maps return as null
|
2011-10-12 23:39:52 +00:00
|
|
|
}
|
|
|
|
}
|