Added test jars and the first unit test.

This commit is contained in:
akwizgran
2011-06-21 23:12:30 +01:00
parent cd4f99df3d
commit 9e76cc6a4f
10 changed files with 108 additions and 21 deletions

16
test/build.xml Normal file
View File

@@ -0,0 +1,16 @@
<project name='test' default='compile'>
<import file='../build-common.xml'/>
<target name='test' depends='depend'>
<junit haltonfailure='true' printsummary='on' showoutput='true'>
<classpath>
<fileset refid='bundled-jars'/>
<fileset refid='test-jars'/>
<path refid='api-classes'/>
<path refid='component-classes'/>
<path refid='test-classes'/>
<path refid='util-classes'/>
</classpath>
<test name='net.sf.briar.util.FileUtilsTest'/>
</junit>
</target>
</project>

View File

@@ -0,0 +1,59 @@
package net.sf.briar.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FileUtilsTest extends TestCase {
private final File testDir = new File("test.tmp");
@Before
public void setUp() {
testDir.mkdirs();
}
@Test
public void testCopy() throws IOException {
File src = new File(testDir, "src");
File dest = new File(testDir, "dest");
PrintStream out = new PrintStream(new FileOutputStream(src));
out.print("Foo bar\r\nBar foo\r\n");
out.flush();
out.close();
long length = src.length();
FileUtils.copy(src, dest);
assertEquals(length, dest.length());
Scanner in = new Scanner(dest);
assertTrue(in.hasNextLine());
assertEquals("Foo bar", in.nextLine());
assertTrue(in.hasNextLine());
assertEquals("Bar foo", in.nextLine());
assertFalse(in.hasNext());
in.close();
src.delete();
dest.delete();
}
@After
public void tearDown() throws IOException {
delete(testDir);
}
private static void delete(File f) throws IOException {
if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
f.delete();
}
}