+ @Override
+ protected void start() throws Exception {
+ tmp = File.createTempFile("nikiroo-utils", ".test");
+ tmp.delete();
+ tmp.mkdir();
+ b.updateFile(tmp.getAbsolutePath());
+ Bundles.setDirectory(tmp.getAbsolutePath());
+ b.reload(false);
+ }
+
+ @Override
+ protected void stop() {
+ IOUtils.deltree(tmp);
+ }
+ });
+
+ addSeries(new TestLauncher("Read/Write support", args) {
+ {
+ addTest(new TestCase("Reload") {
+ @Override
+ public void test() throws Exception {
+ String now = b.getString(E.ONE);
+ b.reload(true);
+ String def = b.getString(E.ONE);
+ b.reload(false);
+
+ assertEquals("We should not have a bundle to load",
+ null, def);
+ assertEquals("We should have reloaded the same files",
+ now, b.getString(E.ONE));
+
+ // reset values for next tests
+ b.reload(false);
+ }
+ });
+
+ addTest(new TestCase("Set/Get") {
+ @Override
+ public void test() throws Exception {
+ String val = "Newp";
+ b.setString(E.ONE, val);
+ String setGet = b.getString(E.ONE);
+
+ assertEquals(val, setGet);
+
+ // reset values for next tests
+ b.restoreChanges(null);
+ }
+ });
+
+ addTest(new TestCase("Snapshots") {
+ @Override
+ public void test() throws Exception {
+ String val = "Newp";
+ String def = b.getString(E.ONE);
+
+ b.setString(E.ONE, val);
+ Object snap = b.takeChangesSnapshot();
+
+ b.restoreChanges(null);
+ assertEquals(
+ "restoreChanges(null) should clear the changes",
+ def, b.getString(E.ONE));
+ b.restoreChanges(snap);
+ assertEquals(
+ "restoreChanges(snapshot) should restore the changes",
+ val, b.getString(E.ONE));
+
+ // reset values for next tests
+ b.restoreChanges(null);
+ }
+ });
+
+ addTest(new TestCase("updateFile with changes") {
+ @Override
+ public void test() throws Exception {
+ String val = "Go to disk! (UTF-8 test: 日本語)";
+
+ String def = b.getString(E.ONE);
+ b.setString(E.ONE, val);
+ b.updateFile(tmp.getAbsolutePath());
+ b.reload(false);
+
+ assertEquals(val, b.getString(E.ONE));
+
+ // reset values for next tests
+ b.setString(E.ONE, def);
+ b.updateFile(tmp.getAbsolutePath());
+ b.reload(false);
+ }
+ });
+ }
+
+ @Override
+ protected void start() throws Exception {
+ tmp = File.createTempFile("nikiroo-utils", ".test");
+ tmp.delete();
+ tmp.mkdir();
+ b.updateFile(tmp.getAbsolutePath());
+ Bundles.setDirectory(tmp.getAbsolutePath());
+ b.reload(false);
+ }
+
+ @Override
+ protected void stop() {
+ IOUtils.deltree(tmp);
+ }
+ });