package com.github.mjdev.libaums.fs;

import com.eclipsesource.json.JsonObject;
import com.github.mjdev.libaums.util.Pair;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xenei.junit.contract.Contract;
import org.xenei.junit.contract.ContractTest;
import org.xenei.junit.contract.IProducer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;


/**
 * Created by magnusja on 02/08/17.
 */
@Contract(FileSystem.class)
public class FileSystemTest {
    private IProducer<Pair<FileSystem, JsonObject>> producer;
    private FileSystem fs;
    private JsonObject expectedValues;

    @Contract.Inject
    public void setFileSystem(IProducer<Pair<FileSystem, JsonObject>> producer) {
        this.producer = producer;
    }

    @Before
    public void setUp() {
        newInstance();
    }

    @After
    public void cleanup() {
        producer.cleanUp();
    }

    private void newInstance() {
        Pair<FileSystem, JsonObject> pair = producer.newInstance();
        fs = pair.getLeft();
        expectedValues = pair.getRight();
    }

    @ContractTest
    public void getRootDirectory() throws Exception {
        UsbFile root = fs.getRootDirectory();
        assertNotNull(root);
        assertEquals("/", root.getName());
        assertTrue(root.isDirectory());
        assertTrue(root.isRoot());
    }

    @ContractTest
    public void getVolumeLabel() throws Exception {
        assertEquals(expectedValues.get("volumeLabel").asString(), fs.getVolumeLabel());
    }

    @ContractTest
    public void getCapacity() throws Exception {
        assertEquals(expectedValues.get("capacity").asLong(), fs.getCapacity());
    }

    @ContractTest
    public void getOccupiedSpace() throws Exception {
        assertEquals(expectedValues.get("occupiedSpace").asLong(), fs.getOccupiedSpace());
    }

    @ContractTest
    public void getFreeSpace() throws Exception {
        assertEquals(expectedValues.get("freeSpace").asLong(), fs.getFreeSpace());
    }

    @ContractTest
    public void getChunkSize() throws Exception {
        assertEquals(expectedValues.get("chunkSize").asInt(), fs.getChunkSize());
    }

}
@@ -332,37 +332,115 @@
 ort 
-static org.junit.Assert.asser
+java.io.OutputStream;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNo
 tEqu
@@ -1991,96 +1991,707 @@
 ));%0A
-    %7D%0A%0A    @ContractTest%0A    public void getFreeSpace() throws Exception %7B%0A        asser
+%0A        UsbFile root = fs.getRootDirectory();%0A        UsbFile file = root.createFile(%22bar.txt%22);%0A%0A        OutputStream os = new UsbFileOutputStream(file);%0A        os.write(%22hello%22.getBytes());%0A        os.close();%0A%0A        assertNotEquals(expectedValues.get(%22occupiedSpace%22).asLong(), fs.getOccupiedSpace());%0A    %7D%0A%0A    @ContractTest%0A    public void getFreeSpace() throws Exception %7B%0A        assertEquals(expectedValues.get(%22freeSpace%22).asLong(), fs.getFreeSpace());%0A%0A        UsbFile root = fs.getRootDirectory();%0A        UsbFile file = root.createFile(%22bar2.txt%22);%0A%0A        OutputStream os = new UsbFileOutputStream(file);%0A        os.write(%22hello%22.getBytes());%0A        os.close();%0A%0A        assertNo
 tEqu

add failing test yayy