Class FileAsserts


  • public class FileAsserts
    extends java.lang.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​(java.lang.String msg, java.lang.String str, java.io.File file)
      Assert that a given string exists in the file.
      static void assertFileContainsExactly​(java.lang.String msg, java.lang.String toMatch, java.io.File file)
      Assert that a given file contains exactly the string given.
      static void assertFileMatches​(java.lang.String msg, java.lang.String regexp, java.io.File file)
      Assert that a given pattern has a match in the file.
      static void assertFileNotContains​(java.lang.String msg, java.io.File file, java.lang.String str)
      Assert that a given string exists in the file.
      static void assertFileNumberOfLines​(java.lang.String msg, java.io.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • assertFileContains

        public static void assertFileContains​(java.lang.String msg,
                                              java.lang.String str,
                                              java.io.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​(java.lang.String msg,
                                             java.lang.String regexp,
                                             java.io.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​(java.lang.String msg,
                                                 java.io.File file,
                                                 java.lang.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​(java.lang.String msg,
                                                   java.io.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​(java.lang.String msg,
                                                     java.lang.String toMatch,
                                                     java.io.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.