RESOLVED - BATCH-1226: Add assertLineCount method to AssertFile
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user