Package dk.netarkivet.testutils
Class FileAsserts
- java.lang.Object
-
- dk.netarkivet.testutils.FileAsserts
-
public class FileAsserts extends Object
Utility functions for asserting statements about files. Notice that using these may cause the files to be re-read several times. This ought to be cheap, but may not be for big files.
-
-
Constructor Summary
Constructors Constructor Description FileAsserts()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertFileContains(String msg, String str, File file)
Assert that a given string exists in the file.static void
assertFileContainsExactly(String msg, String toMatch, File file)
Assert that a given file contains exactly the string given.static void
assertFileMatches(String msg, String regexp, File file)
Assert that a given pattern has a match in the file.static void
assertFileNotContains(String msg, File file, String str)
Assert that a given string exists in the file.static void
assertFileNumberOfLines(String msg, File file, int n)
Assert that a given file has the expected number of lines If it doesn't, fail and print the file contents.
-
-
-
Method Detail
-
assertFileContains
public static void assertFileContains(String msg, String str, File file)
Assert that a given string exists in the file. If it doesn't, fail and print the file contents. If the file couldn't be read, fail and print the error message.- Parameters:
msg
- An explanatory message.str
- A string to find in the file.file
- A file to scan.
-
assertFileMatches
public static void assertFileMatches(String msg, String regexp, File file)
Assert that a given pattern has a match in the file. If it doesn't, fail and print the file contents. If the file couldn't be read, fail and print the error message.- Parameters:
msg
- An explanatory message.regexp
- A pattern to search for in the file.file
- A file to scan.
-
assertFileNotContains
public static void assertFileNotContains(String msg, File file, String str)
Assert that a given string exists in the file. If it doesn't, fail and print the file contents. If the file couldn't be read, fail and print the error message.- Parameters:
msg
- An explanatory message.file
- A file to scan.str
- A string to find in the file.
-
assertFileNumberOfLines
public static void assertFileNumberOfLines(String msg, File file, int n)
Assert that a given file has the expected number of lines If it doesn't, fail and print the file contents. If the file couldn't be read, fail and print the error message.- Parameters:
msg
- an explanatory messagefile
- the File to checkn
- the expected number of lines
-
assertFileContainsExactly
public static void assertFileContainsExactly(String msg, String toMatch, File file)
Assert that a given file contains exactly the string given. This will read the given file's contents into a string.- Parameters:
msg
- An explanatory messagetoMatch
- The string that should be the full contents of the filefile
- The file that the string should be in.
-
-