package net.simplestorage.storage.impl.indexed;

import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;

import static org.junit.Assert.*;

public class IndexedStorageFileTest {

    private IndexedStorageFile storageFile;

    @Before
    public void setUp() throws URISyntaxException, FileNotFoundException {
        File testFile = new File(ExistingIndexedStorageIntegrationTest.class.getResource("testIndexFile.txt").toURI());
        storageFile = new IndexedStorageFile(testFile.getAbsolutePath());
    }

    @Test
    public void testRead() throws Exception {
        String data = storageFile.read(0,7);
        assertEquals("test001", data);
        data = storageFile.read(7,7);
        assertEquals("test002", data);
    }

    @Test
    public void testWrite() throws Exception {
        assertEquals(14,storageFile.length());
        storageFile.write("test003", 14);
        assertEquals(21,storageFile.length());
        storageFile.clear(14,7);
    }


    @Test
    public void testAppend() throws Exception {
            assertEquals(14,storageFile.length());
            storageFile.append("test003");
            assertEquals(21,storageFile.length());
            storageFile.clear(14,7);
    }

    @Test
    public void testClear() throws Exception {

    }
}
@@ -42,16 +42,40 @@
 dexed;%0A%0A
+import org.junit.After;%0A
 import o
@@ -134,41 +134,101 @@
 .io.
-File;%0Aimport java.io.FileNotFound
+BufferedOutputStream;%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IO
 Exce
@@ -306,9 +306,20 @@
 ert.
-*
+assertEquals
 ;%0A%0Ap
@@ -401,16 +401,44 @@
 eFile;%0A%0A
+    private File testFile;%0A%0A
     @Bef
@@ -496,20 +496,10 @@
 on, 
-FileNotFound
+IO
 Exce
@@ -514,21 +514,16 @@
         
-File 
 testFile
@@ -633,71 +633,334 @@
     
-storageFile = new IndexedStorageFile(testFile.getAbsolutePath()
+BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(testFile));%0A        stream.write(%22test001test002%22.toString().getBytes(%22UTF-8%22));%0A        stream.close();%0A        storageFile = new IndexedStorageFile(testFile.getAbsolutePath());%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A        testFile.delete(
 );%0A 
@@ -1672,71 +1672,6 @@
    %7D
-%0A%0A    @Test%0A    public void testClear() throws Exception %7B%0A%0A    %7D
 %0A%7D

Fix length problem in test.