Class FileTester


  • public class FileTester
    extends java.lang.Object
    The Class FileTester.
    Since:
    1.1 (06.04.2011)
    Author:
    oliver
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertContentEquals​(java.io.File file1, java.io.File file2)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, int from, int to)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, int from, int to, java.lang.String encoding)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, int from, int to, java.nio.charset.Charset encoding)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.lang.String encoding)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.nio.charset.Charset encoding)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.nio.charset.Charset encoding, java.util.regex.Pattern... ignores)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.nio.charset.Charset charset, StringConverter converter)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.nio.charset.Charset encoding, StringConverter converter, java.util.regex.Pattern... ignores)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, java.util.regex.Pattern... ignores)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, StringConverter converter)
      Asserts that the content of two files are equal.
      static void assertContentEquals​(java.io.File file1, java.io.File file2, StringConverter converter, java.util.regex.Pattern... ignores)
      Asserts that the content of two files are equal.
      static void assertEquals​(java.io.File file1, java.io.File file2)
      Two files are considered equals if the would point to the same file location on the disk.
      • Methods inherited from class java.lang.Object

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

      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.
        Parameters:
        file1 - the first file
        file2 - the second file
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               int from,
                                               int to)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.
        Parameters:
        file1 - the first file
        file2 - the second file
        from - the line number from which the comparison is started (starting with 1)
        to - the last line number where the comparison ends.
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               java.lang.String encoding)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.

        The encoding is only important for the output if the two files are not equals.

        Parameters:
        file1 - the first file
        file2 - the second file
        encoding - the encoding
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               int from,
                                               int to,
                                               java.lang.String encoding)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.

        The encoding is only important for the output if the two files are not equals.

        Parameters:
        file1 - the first file
        file2 - the second file
        from - the line number from which the comparison is started (starting with 1)
        to - the last line number where the comparison ends.
        encoding - the encoding
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               java.nio.charset.Charset encoding)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.

        The encoding is only important for the output if the two files are not equals.

        Parameters:
        file1 - the first file
        file2 - the second file
        encoding - the encoding
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               int from,
                                               int to,
                                               java.nio.charset.Charset encoding)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. If they are not equals the first different line or byte will be shown.

        The encoding is only important for the output if the two files are not equals.

        Parameters:
        file1 - the first file
        file2 - the second file
        from - the line number from which the comparison is started (starting with 1)
        to - the last line number where the comparison ends.
        encoding - the encoding
        Throws:
        java.lang.AssertionError - if the check fails
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               StringConverter converter)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. For comparison the lines are converted before by the given StringConverter. This allows you e.g. to ignore white spaces (by using StringConverter.IGNORE_WHITESPACES as parameter) or to ignore upper / lower case problems (StringConverter.LOWER_CASE).

        The StringConverter implementation allows you also to combine different converters for some exotic problems.

         FileTester.assertContentEquals(f1, f2, StringConverter.IGNORE_WHITESPACES)
         

        This is e.g. the call for you if whitespaces can be ignored for comparison.

        Parameters:
        file1 - the first file
        file2 - the second file
        converter - the converter
        Throws:
        java.lang.AssertionError - if the check fails
        Since:
        1.6
        See Also:
        assertContentEquals(File, File, Charset, Pattern...)
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               java.nio.charset.Charset encoding,
                                               StringConverter converter,
                                               java.util.regex.Pattern... ignores)
        Asserts that the content of two files are equal. For comparison the lines are converted before by the given StringConverter. This allows you e.g. to ignore white spaces (by using StringConverter.IGNORE_WHITESPACES as parameter) or to ignore upper / lower case problems (StringConverter.LOWER_CASE).

        Lines which matches the given 'ignores' pattern will be ignored for comparison. This is done before the converter is executed. E.g. the 'ignores' pattern must match the original line.

        Parameters:
        file1 - the first file
        file2 - the second file
        encoding - the encoding
        converter - the converter
        ignores - the ignores
        Since:
        1.6
        See Also:
        assertContentEquals(File, File, Charset, Pattern...)
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               java.util.regex.Pattern... ignores)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. Lines which matches the given 'ignores' pattern will be ignored for comparison. E.g. if you want to ignore two property files and want to ignore the comments and empty lines you could use
             Pattern.compile("#.*"), Pattern.compile("[ \\t]*"
         
        as ignores parameters.

        If the two files are not equals the first different line or byte will be shown.

        Parameters:
        file1 - the first file
        file2 - the second file
        ignores - the line pattern which should be ignored
        Throws:
        java.lang.AssertionError - if the check fails
        Since:
        1.4
        See Also:
        assertContentEquals(File, File, Charset, Pattern...)
      • assertContentEquals

        public static void assertContentEquals​(java.io.File file1,
                                               java.io.File file2,
                                               java.nio.charset.Charset encoding,
                                               java.util.regex.Pattern... ignores)
                                        throws java.lang.AssertionError
        Asserts that the content of two files are equal. Lines which matches the given 'ignores' pattern will be ignored for comparison. E.g. if you want to ignore two property files and want to ignore the comments and empty lines you could use
             Pattern.compile("#.*"), Pattern.compile("[ \\t]*"
         
        as ignores parameters.

        If the two files are not equals the first different line or byte will be shown.

        Parameters:
        file1 - the first file
        file2 - the second file
        encoding - the file encoding
        ignores - the line pattern which should be ignored
        Throws:
        java.lang.AssertionError - if the check fails
        Since:
        1.4
      • assertEquals

        public static void assertEquals​(java.io.File file1,
                                        java.io.File file2)
        Two files are considered equals if the would point to the same file location on the disk.
        Parameters:
        file1 - e.g. file "/a/b/c"
        file2 - e.g. file "/a/b/../b/c"