Skip to content

Commit

Permalink
updating code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlong committed Apr 1, 2010
1 parent f72f3e1 commit 43095bb
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/test/java/com/joshlong/commons/utils/FileUtilsTest.java
Expand Up @@ -50,6 +50,30 @@ public void testDeletingAFile() throws Throwable {
});
this.fileUtils.deleteFile(f);
}
@Test
public void testDeleteFilesDelProcFails() throws Throwable {
final File f = this.context.mock(File.class);
final File tmpExistingFile = File.createTempFile("aaa", "txt");
Writer w = new FileWriter(tmpExistingFile.getAbsolutePath());
IOUtils.write("hello", w);
IOUtils.closeQuietly(w);

final Process proc = this.context.mock(Process.class);
this.context.checking(new Expectations() {
{
one(f).getAbsolutePath();
one(f).exists();
will(returnValue( true)) ;

one(processUtils).execute(with(any(List.class)));
will(returnValue(proc));
one(proc).waitFor() ; will(returnValue(1));


}
});
this.fileUtils.deleteFile(f);
}

@Test
public void testDeleteFiles() throws Throwable {
Expand All @@ -62,7 +86,16 @@ public void testDeleteFiles() throws Throwable {
final Process proc = this.context.mock(Process.class);
this.context.checking(new Expectations() {
{
one(f).getAbsolutePath();
one(f).exists();
will(returnValue( true)) ;

one(processUtils).execute(with(any(List.class)));
will(returnValue(proc));
one(proc).waitFor() ; will(returnValue(0));

one(f).exists(); will(returnValue(false));

}
});
this.fileUtils.deleteFile(f);
Expand Down Expand Up @@ -145,26 +178,38 @@ public void testCopyFileThatStillFails() throws Throwable {
this.fileUtils.copyFile(a, b);
}


@Test
public void testCopyFile() throws Throwable {
final File a = this.context.mock(File.class, "a");
final File b = this.context.mock(File.class, "b");
final Process proc = this.context.mock(Process.class);
File tmpOutF = File.createTempFile("tempA","txt");
final String tmpOut =tmpOutF.getAbsolutePath();

Writer w = new FileWriter(tmpOut);
IOUtils.write("aaa", w);
IOUtils.closeQuietly(w);
this.context.checking(new Expectations() {

{
one(a).getAbsolutePath();
will(returnValue("/tmp/a.txt"));
one(b).getAbsolutePath();
will(returnValue("/tmp/b.txt"));

will(returnValue( tmpOut));
one(processUtils).execute(with(any(List.class)));
will(returnValue(proc));
one(proc).waitFor();
will(returnValue(0));



}
});
this.fileUtils.copyFile(a, b);



}

@Test
Expand Down

0 comments on commit 43095bb

Please sign in to comment.