use of org.evosuite.runtime.mock.java.io.MockFile 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.MockFile in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testCreateDeleteFileDirectly.
@Test
public void testCreateDeleteFileDirectly() throws IOException {
MockFile file = new MockFile("foo");
Assert.assertFalse(file.exists());
boolean created = file.createNewFile();
Assert.assertTrue(created);
Assert.assertTrue(file.exists());
boolean deleted = file.delete();
Assert.assertTrue(deleted);
Assert.assertFalse(file.exists());
}
use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testRename.
@Test
public void testRename() throws IOException {
File bla = new MockFile("bla");
File doh = new MockFile("doh");
Assert.assertFalse(bla.exists());
Assert.assertFalse(doh.exists());
boolean created = bla.createNewFile();
Assert.assertTrue(created);
Assert.assertTrue(bla.exists());
Assert.assertFalse(doh.exists());
boolean renamed = bla.renameTo(doh);
Assert.assertTrue(renamed);
Assert.assertFalse(bla.exists());
Assert.assertTrue(doh.exists());
File inAnotherFolder = new MockFile("foo/hei/hello.tmp");
Assert.assertFalse(inAnotherFolder.exists());
renamed = doh.renameTo(inAnotherFolder);
Assert.assertFalse(renamed);
Assert.assertFalse(inAnotherFolder.exists());
Assert.assertTrue(doh.exists());
File de = new MockFile("deeee");
File blup = new MockFile("blup");
Assert.assertFalse(de.exists());
Assert.assertFalse(blup.exists());
renamed = de.renameTo(blup);
Assert.assertFalse(renamed);
Assert.assertFalse(de.exists());
Assert.assertFalse(blup.exists());
}
use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class VirtualFileSystemTest method testCreateDeleteFolderDirectly.
@Test
public void testCreateDeleteFolderDirectly() throws IOException {
MockFile folder = new MockFile("foo" + File.separator + "hello");
Assert.assertFalse(folder.exists());
// parent doesn't exist, so should fail
boolean created = folder.mkdir();
Assert.assertFalse(created);
Assert.assertFalse(folder.exists());
created = folder.mkdirs();
Assert.assertTrue(created);
Assert.assertTrue(folder.exists());
MockFile file = new MockFile(folder.getAbsoluteFile() + File.separator + "evo");
created = file.createNewFile();
Assert.assertTrue(created);
Assert.assertTrue(file.exists());
// deleting non-empty folder should fail
boolean deleted = folder.delete();
Assert.assertFalse(deleted);
Assert.assertTrue(folder.exists());
deleted = file.delete();
Assert.assertTrue(deleted);
Assert.assertFalse(file.exists());
// now we can delete the folder
deleted = folder.delete();
Assert.assertTrue(deleted);
Assert.assertFalse(folder.exists());
}
use of org.evosuite.runtime.mock.java.io.MockFile in project evosuite by EvoSuite.
the class MockJFileChooserTest method testGetCurrentDirectory.
@Test
public void testGetCurrentDirectory() {
JFileChooser chooser = new MockJFileChooser();
File dir = chooser.getCurrentDirectory();
Assert.assertTrue(dir.exists());
Assert.assertTrue(dir instanceof MockFile);
}
Aggregations