package com.unidev.zerostorage;

import com.unidev.zerostorage.index.IndexStorage;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;

/**
 * Storage index tests
 */
public class TestIndexStorage {

    @Rule
    public TemporaryFolder folder= new TemporaryFolder();

    @Test
    public void testBlankIndexStorageSave() {
        IndexStorage indexStorage = new IndexStorage();

        Storage blankIndex = new Storage();
        indexStorage.index(blankIndex);

        File root = folder.getRoot();

        indexStorage.storageRoot(root);
        indexStorage.save();

    }

    @Test
    public void testIndexStorageSave() {
        IndexStorage indexStorage = new IndexStorage();

        Storage index = new Storage();
        index.details().put("Potato", "Tomato");
        index.details().put("Tomato", null);
        indexStorage.index(index);

        File root = folder.getRoot();

        indexStorage.storageRoot(root);
        indexStorage.save();

    }

}

@@ -183,16 +183,100 @@
 io.File;
+%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.nio.file.Files;
 %0A%0A/**%0A *
@@ -1109,10 +1109,456 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testLoadIndexStorage() throws IOException %7B%0A        InputStream inputStream = TestStorage.class.getResourceAsStream(%22/blankIndex.json%22);%0A        File root = folder.getRoot();%0A%0A        File index = new File(root, IndexStorage.INDEX_FILE);%0A        Files.copy(inputStream, index.toPath());%0A%0A        IndexStorage indexStorage = new IndexStorage();%0A        indexStorage.storageRoot(root);%0A        indexStorage.load();%0A    %7D%0A%0A
 %7D%0A

Test loading of blank index file