Class 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 Detail

      • FileAsserts

        public FileAsserts()
    • 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 message
        file - the File to check
        n - 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 message
        toMatch - The string that should be the full contents of the file
        file - The file that the string should be in.