use of org.evosuite.runtime.mock.java.io.MockFileInputStream in project evosuite by EvoSuite.
the class FileSystemHandlingTest method createNewFileByAddingData.
@Test
public void createNewFileByAddingData() throws IOException {
RuntimeSettings.useVFS = true;
Runtime.getInstance().resetRuntime();
byte[] data = new byte[] { 42, 66 };
EvoSuiteFile file = new EvoSuiteFile("foo");
MockFile mf = new MockFile(file.getPath());
Assert.assertFalse(mf.exists());
FileSystemHandling.appendDataToFile(file, data);
Assert.assertTrue(mf.exists());
MockFileInputStream in = new MockFileInputStream(file.getPath());
byte[] buffer = new byte[4];
int count = in.read(buffer);
in.close();
Assert.assertEquals(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.MockFileInputStream 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.MockFileInputStream in project evosuite by EvoSuite.
the class CharByteReadWriteTest method testPrintWriter.
@Test
public void testPrintWriter() throws Throwable {
String file = "PrintWriter_file.tmp";
String expected = "testPrintWriter";
MockPrintWriter out = new MockPrintWriter(file);
out.println(expected);
out.close();
Scanner in = new Scanner(new MockFileInputStream(file));
String result = in.nextLine();
in.close();
Assert.assertEquals(expected, result);
}
use of org.evosuite.runtime.mock.java.io.MockFileInputStream in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testReadingNonExistingFile.
@Test
public void testReadingNonExistingFile() throws IOException {
String fileName = "this_file_should_not_exist";
File realFile = new File(fileName);
Assert.assertFalse(realFile.exists());
try {
MockFileInputStream in = new MockFileInputStream(realFile);
// real file does not exist
Assert.fail();
} catch (FileNotFoundException e) {
}
File mockFile = new MockFile(fileName);
Assert.assertFalse(mockFile.exists());
try {
MockFileInputStream in = new MockFileInputStream(mockFile);
// also the mock file does not exist (yet)
Assert.fail();
} catch (FileNotFoundException e) {
}
boolean created = mockFile.createNewFile();
Assert.assertTrue(created);
Assert.assertTrue(mockFile.exists());
// real file shouldn's have been created
Assert.assertFalse(realFile.exists());
// following should work even if real file does not exist
MockFileInputStream in = new MockFileInputStream(mockFile);
}
use of org.evosuite.runtime.mock.java.io.MockFileInputStream in project evosuite by EvoSuite.
the class CharByteReadWriteTest method testPrintStream.
@Test
public void testPrintStream() throws Throwable {
String file = "PrintStream_file.tmp";
String expected = "testPrintStream";
MockPrintStream out = new MockPrintStream(file);
out.println(expected);
out.close();
Scanner in = new Scanner(new MockFileInputStream(file));
String result = in.nextLine();
in.close();
Assert.assertEquals(expected, result);
}
Aggregations