// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PersistenceController.java
// public interface PersistenceController<ROOT extends Serializable> extends AutoCloseable {
// 
//     void close();
// 
//     void shut();
// 
//     /**
//      * Query system (immutable view of it).
//      * <p>
//      * Few things to remember: 1. if operations done on system (using query) do
//      * make some changes they will not be preserved (for long) 2. it is possible
//      * to return any object from domain (including ROOT root) and perform
//      * operations later on (but the more You do inside Query the safer).
//      *
//      * @param <RESULT> result of query
//      * @param query    lambda (or query implementation) with operations
//      * @return calculated result
//      */
//     <RESULT> RESULT query(Query<ROOT, RESULT> query);
// 
//     /**
//      * Perform command on system.
//      * <p>
//      * Inside command can be any code doing any changes. Such changes are
//      * guaranteed to be preserved (if only command ended without exception).
//      *
//      * @param cmd
//      */
//     <R> R executeAndQuery(ContextCommand<ROOT, R> cmd);
// 
//     /**
//      * Perform command on system.
//      * <p>
//      * Inside command can be any code doing any changes. Such changes are
//      * guaranteed to be preserved (if only command ended without exception).
//      *
//      * @param cmd
//      */
//     <R> R executeAndQuery(Command<ROOT, R> cmd);
// 
//     void execute(VoidCommand<ROOT> cmd);
// 
//     void execute(VoidContextCommand<ROOT> cmd);
// 
//     boolean isOpen();
// 
//     void erase();
// 
//     void snapshot();
// 
//     void snapshotXML(Path xmlFile) throws IOException;
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/disk/PersistenceDiskHelper.java
// public final class PersistenceDiskHelper {
// 
//     public static final String STORAGE_FOLDER = "prevayler";
// 
//     PersistenceDiskHelper() {
//         throw new UnsupportedOperationException("do not create util classes");
//     }
// 
//     public static String calcFolderName(final Path path) {
//         return path.toString();
//     }
// 
//     /**
//      * Check if save of given name exists.
//      */
//     public static boolean exists(Path path) {
//         return Files.exists(path);
//     }
// 
//     public static void delete(Path path) {
//         if (exists(path)) {
//             Politician.beatAroundTheBush(() -> {
//                 FileUtils.deleteDirectory(path.toFile());
//             });
//         }
//     }
// 
// 
//     public static Path calcUserPath(String folderName) {
//         final String userFolder = System.getProperty("user.home");
//         return Paths.get(userFolder, STORAGE_FOLDER, folderName).toAbsolutePath();
//     }
// 
// }


import org.junit.After;
import org.junit.Before;
import pl.setblack.airomem.core.PersistenceController;
import pl.setblack.airomem.core.disk.PersistenceDiskHelper;
import java.io.File;
import java.io.Serializable;
        this.origUserHome = System.getProperty("user.home");
        System.setProperty("user.home", localFolder.getAbsolutePath());
        AbstractPrevaylerTest.deletePrevaylerFolder();
        this.persistenceController = PrevaylerBuilder
                .<T>newBuilder()
                .withinUserFolder("test")
                .forceOverwrite(true)
                .useSupplier(() -> createSystem())
                .build();

    }

    @After
    public void tearDown() {
        this.persistenceController.close();
        AbstractPrevaylerTest.deletePrevaylerFolder();
        System.setProperty("user.home", origUserHome);

    }

    protected void reloadController(Class<T> type) {
        this.persistenceController.close();
        this.persistenceController = PrevaylerBuilder
                .<T>newBuilder()
                .withinUserFolder("test")
                .forceOverwrite(false)
                .build();
    }

    static void deletePrevaylerFolder() {
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PersistenceController.java
// public interface PersistenceController<ROOT extends Serializable> extends AutoCloseable {
// 
//     void close();
// 
//     void shut();
// 
//     /**
//      * Query system (immutable view of it).
//      * <p>
//      * Few things to remember: 1. if operations done on system (using query) do
//      * make some changes they will not be preserved (for long) 2. it is possible
//      * to return any object from domain (including ROOT root) and perform
//      * operations later on (but the more You do inside Query the safer).
//      *
//      * @param <RESULT> result of query
//      * @param query    lambda (or query implementation) with operations
//      * @return calculated result
//      */
//     <RESULT> RESULT query(Query<ROOT, RESULT> query);
// 
//     /**
//      * Perform command on system.
//      * <p>
//      * Inside command can be any code doing any changes. Such changes are
//      * guaranteed to be preserved (if only command ended without exception).
//      *
//      * @param cmd
//      */
//     <R> R executeAndQuery(ContextCommand<ROOT, R> cmd);
// 
//     /**
//      * Perform command on system.
//      * <p>
//      * Inside command can be any code doing any changes. Such changes are
//      * guaranteed to be preserved (if only command ended without exception).
//      *
//      * @param cmd
//      */
//     <R> R executeAndQuery(Command<ROOT, R> cmd);
// 
//     void execute(VoidCommand<ROOT> cmd);
// 
//     void execute(VoidContextCommand<ROOT> cmd);
// 
//     boolean isOpen();
// 
//     void erase();
// 
//     void snapshot();
// 
//     void snapshotXML(Path xmlFile) throws IOException;
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/disk/PersistenceDiskHelper.java
// public final class PersistenceDiskHelper {
// 
//     public static final String STORAGE_FOLDER = "prevayler";
// 
//     PersistenceDiskHelper() {
//         throw new UnsupportedOperationException("do not create util classes");
//     }
// 
//     public static String calcFolderName(final Path path) {
//         return path.toString();
//     }
// 
//     /**
//      * Check if save of given name exists.
//      */
//     public static boolean exists(Path path) {
//         return Files.exists(path);
//     }
// 
//     public static void delete(Path path) {
//         if (exists(path)) {
//             Politician.beatAroundTheBush(() -> {
//                 FileUtils.deleteDirectory(path.toFile());
//             });
//         }
//     }
// 
// 
//     public static Path calcUserPath(String folderName) {
//         final String userFolder = System.getProperty("user.home");
//         return Paths.get(userFolder, STORAGE_FOLDER, folderName).toAbsolutePath();
//     }
// 
// }


// Path: airomem-core/src/test/java/pl/setblack/airomem/core/builders/AbstractPrevaylerTest.java
import org.junit.After;
import org.junit.Before;
import pl.setblack.airomem.core.PersistenceController;
import pl.setblack.airomem.core.disk.PersistenceDiskHelper;
import java.io.File;
import java.io.Serializable;

        this.origUserHome = System.getProperty("user.home");
        System.setProperty("user.home", localFolder.getAbsolutePath());
        AbstractPrevaylerTest.deletePrevaylerFolder();
        this.persistenceController = PrevaylerBuilder
                .<T>newBuilder()
                .withinUserFolder("test")
                .forceOverwrite(true)
                .useSupplier(() -> createSystem())
                .build();

    }

    @After
    public void tearDown() {
        this.persistenceController.close();
        AbstractPrevaylerTest.deletePrevaylerFolder();
        System.setProperty("user.home", origUserHome);

    }

    protected void reloadController(Class<T> type) {
        this.persistenceController.close();
        this.persistenceController = PrevaylerBuilder
                .<T>newBuilder()
                .withinUserFolder("test")
                .forceOverwrite(false)
                .build();
    }

    static void deletePrevaylerFolder() {
        PersistenceDiskHelper.delete(PersistenceDiskHelper.calcUserPath("test"));