use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testWorkingDirectoryExists.
@Test
public void testWorkingDirectoryExists() {
MockFile workingDir = new MockFile(java.lang.System.getProperty("user.dir"));
Assert.assertTrue(workingDir.exists());
}
use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class FileSystemHandlingTest method createNewFileByAddingLine.
@Test
public void createNewFileByAddingLine() throws IOException {
RuntimeSettings.useVFS = true;
Runtime.getInstance().resetRuntime();
String data = "A new line to be added";
EvoSuiteFile file = new EvoSuiteFile("foo");
MockFile mf = new MockFile(file.getPath());
Assert.assertFalse(mf.exists());
FileSystemHandling.appendStringToFile(file, data);
Assert.assertTrue(mf.exists());
// try read bytes directly
MockFileInputStream in = new MockFileInputStream(file.getPath());
byte[] buffer = new byte[1024];
in.read(buffer);
in.close();
String byteString = new String(buffer);
Assert.assertTrue("Read: " + byteString, byteString.startsWith(data));
// try with InputStreamReader
InputStreamReader reader = new InputStreamReader(new MockFileInputStream(file.getPath()));
char[] cbuf = new char[1024];
reader.read(cbuf);
reader.close();
String charString = new String(cbuf);
Assert.assertTrue("Read: " + charString, charString.startsWith(data));
// try BufferedReader
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new MockFileInputStream(file.getPath())));
cbuf = new char[1024];
bufferedReader.read(cbuf);
bufferedReader.close();
charString = new String(cbuf);
Assert.assertTrue("Read: " + charString, charString.startsWith(data));
// try with Scanner
Scanner fromFile = new Scanner(new MockFileInputStream(file.getPath()));
String fileContent = fromFile.nextLine();
fromFile.close();
Assert.assertEquals(data, fileContent);
}
use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class InstrumentingAgent_IntTest method testMockFramework_noAgent.
@Test
public void testMockFramework_noAgent() {
/*
* OverrideMocks should default even if called
* directly.
*/
MockFramework.enable();
MockFile file = new MockFile("bar/foo");
File parent = file.getParentFile();
Assert.assertTrue(parent instanceof MockFile);
// now, disable
MockFramework.disable();
parent = file.getParentFile();
// should rollback to original behavior
Assert.assertFalse(parent instanceof MockFile);
}
Aggregations