package file;

import static org.junit.Assert.*;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;

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

public class BinaryFileReaderTest {
	private static byte testData[] = {1,2,3,5,7,13,17};
	private static File testFile;
	
	@BeforeClass
	public static void before() throws IOException{
		testFile = Files.createTempFile("BFRtestfile","tmp").toFile();
		testFile.createNewFile();
		
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(testFile));
		bos.write(testData, 0, testData.length);
		bos.close();
	}
	
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testBinaryFileReaderInt() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetString() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetFile() {
		fail("Not yet implemented");
	}
	
	@Test
	public void testReUse() {
		fail("Not yet implemented");
	}

}

@@ -43,24 +43,56 @@
 ssert.*;%0D%0A%0D%0A
+import helper.DataGenerator;%0D%0A%0D%0A
 import java.
@@ -388,28 +388,8 @@
 ta%5B%5D
- = %7B1,2,3,5,7,13,17%7D
 ;%0D%0A%09
@@ -418,24 +418,59 @@
 stFile;%0D%0A%09%0D%0A
+%09private BinaryFileReader bfr;%0D%0A%09%0D%0A
 %09@BeforeClas
@@ -528,248 +528,125 @@
 %0D%0A%09%09
-testFile = Files.createTempFile(%22BFRtestfile%22,%22tmp%22).toFile();%0D%0A%09%09testFile.createNewFile();
+createTestFile(5120); // 5 kb%0D%0A%09%7D
 %0D%0A%09
-%09
 %0D%0A%09
-%09BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(testFile));%0D%0A%09%09bos.write(testData, 0, testData.length);%0D%0A%09%09bos.close
+@Before%0D%0A%09public void setUp() throws Exception %7B%0D%0A%09%09bfr = new BinaryFileReader
 ();%0D
@@ -646,35 +646,32 @@
 der();%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09@
-Before
+Test
 %0D%0A%09public vo
@@ -665,37 +665,49 @@
 t%0D%0A%09public void 
-setUp
+testBufferToSmall
 () throws Except
@@ -692,32 +692,34 @@
 oSmall() throws 
+IO
 Exception %7B%0D%0A%09%7D%0D
@@ -720,99 +720,96 @@
 %7B%0D%0A%09
-%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void testBinaryFileReaderInt() %7B%0D%0A%09%09fail(%22Not yet implemented%22
+%09bfr = new BinaryFileReader(5);%0D%0A%09%09assertArrayEquals(testData, bfr.get(testFile)
 );%0D%0A%09%7D%0D%0A
 %0D%0A%09@
@@ -796,32 +796,33 @@
 estFile));%0D%0A%09%7D%0D%0A
+%09
 %0D%0A%09@Test%0D%0A%09publi
@@ -836,135 +836,226 @@
 test
-GetString() %7B%0D%0A%09%09fail(%22Not yet implemented%22);%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void testGetFile() %7B%0D%0A%09%09fail(%22Not yet implemented%22
+DefaultBuffer() throws IOException %7B%0D%0A%09%09assertArrayEquals(testData, bfr.get(testFile));%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void testGetString() throws Exception %7B%0D%0A%09%09assertArrayEquals(testData, bfr.get(testFile.toString())
 );%0D%0A%09%7D%0D%0A
 %09%0D%0A%09
@@ -1042,33 +1042,32 @@
 tring()));%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09@Test%0D%0A%09publi
@@ -1089,47 +1089,578 @@
 e() 
-%7B%0D%0A%09%09fail(%22Not yet implemented%22);%0D%0A%09%7D%0D%0A
+throws IOException %7B%0D%0A%09%09assertArrayEquals(testData, bfr.get(testFile));%0D%0A%09%09%0D%0A%09%09createTestFile(512);%0D%0A%09%09%0D%0A%09%09assertArrayEquals(testData, bfr.get(testFile));%0D%0A%09%7D%0D%0A%0D%0A%09private static File createTestFile(int fileSize) throws IOException %7B%0D%0A%09%09testFile = Files.createTempFile(%22BFRtestfile%22, null).toFile();%0D%0A%09%09testFile.createNewFile();%0D%0A%09%09%0D%0A%09%09BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(testFile));%0D%0A%09%09testData = DataGenerator.generateRandomByteArray(fileSize);%0D%0A%09%09bos.write(testData, 0, testData.length);%0D%0A%09%09bos.close();%0D%0A%09%09%0D%0A%09%09return testFile;%0D%0A%09%7D
 %0D%0A%7D%0D

test for file reader done