use of org.evosuite.runtime.mock.java.io.MockFileOutputStream in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testReadAfterWriteToFile.
@Test
public void testReadAfterWriteToFile() throws IOException {
File file = MockFile.createTempFile("foo", ".tmp");
Assert.assertTrue(file.exists());
byte[] data = new byte[] { 42, 66 };
MockFileOutputStream out = new MockFileOutputStream(file);
out.write(data);
out.close();
MockFileInputStream in = new MockFileInputStream(file);
byte[] buffer = new byte[4];
int count = in.read(buffer);
in.close();
Assert.assertEquals("End of stream should had been reached", data.length, count);
Assert.assertEquals(data[0], buffer[0]);
Assert.assertEquals(data[1], buffer[1]);
Assert.assertEquals(0, buffer[2]);
Assert.assertEquals(0, buffer[3]);
}
use of org.evosuite.runtime.mock.java.io.MockFileOutputStream in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testWriteToFile.
@Test
public void testWriteToFile() throws IOException {
String fileName = "foo_written_with_FOS";
File realFile = new File(fileName);
// be sure to get it deleted in case we accidently create it
realFile.deleteOnExit();
Assert.assertFalse(realFile.exists());
File file = new MockFile(fileName);
Assert.assertFalse(file.exists());
byte[] data = new byte[] { 42 };
MockFileOutputStream out = new MockFileOutputStream(file);
out.write(data);
// writing to such file should create it
Assert.assertTrue(file.exists());
out.close();
try {
out.write(data);
Assert.fail();
} catch (Exception e) {
// this is expected, as the stream is closed
}
// be sure that no real file was created
Assert.assertFalse(realFile.exists());
}
use of org.evosuite.runtime.mock.java.io.MockFileOutputStream in project evosuite by EvoSuite.
the class CharByteReadWriteTest method testReadWriteByte.
@Test
public void testReadWriteByte() throws Throwable {
String file = "FileOutputStream_file.tmp";
String expected = "testReadWriteByte";
byte[] data = expected.getBytes();
MockFileOutputStream out = new MockFileOutputStream(file);
out.write(data, 0, data.length);
out.flush();
out.close();
byte[] buffer = new byte[1024];
MockFileInputStream in = new MockFileInputStream(file);
int read = in.read(buffer);
in.close();
String result = new String(buffer, 0, read);
Assert.assertEquals(expected, result);
}
Aggregations