RESOLVED - BATCH-1226: Add assertLineCount method to AssertFile

This commit is contained in:
dhgarrette
2009-05-01 19:08:42 +00:00
parent 1de9c71647
commit 74929408ff
2 changed files with 23 additions and 4 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.batch.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import junit.framework.Assert;
@@ -47,9 +46,6 @@ public abstract class AssertFile {
Assert.assertEquals("More lines than expected. There should not be a line number " + lineNum + ".", null,
actualLine);
}
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
expectedReader.close();
actualReader.close();
@@ -59,4 +55,22 @@ public abstract class AssertFile {
public static void assertFileEquals(Resource expected, Resource actual) throws Exception {
AssertFile.assertFileEquals(expected.getFile(), actual.getFile());
}
public static void assertLineCount(int expectedLineCount, File file) throws Exception {
BufferedReader expectedReader = new BufferedReader(new FileReader(file));
try {
int lineCount = 0;
while (expectedReader.readLine() != null) {
lineCount++;
}
Assert.assertEquals(expectedLineCount, lineCount);
}
finally {
expectedReader.close();
}
}
public static void assertLineCount(int expectedLineCount, Resource resource) throws Exception {
AssertFile.assertLineCount(expectedLineCount, resource.getFile());
}
}

View File

@@ -85,4 +85,9 @@ public class AssertFileTests {
AssertFile.assertFileEquals(new FileSystemResource(DIRECTORY + expected), new FileSystemResource(DIRECTORY
+ actual));
}
@Test
public void testAssertLineCount() throws Exception {
AssertFile.assertLineCount(5, new FileSystemResource(DIRECTORY + "input1.txt"));
}
}