Class FileAssert

    • Constructor Detail

      • FileAssert

        protected FileAssert​(java.io.File actual)
    • Method Detail

      • exists

        public FileAssert exists()
        Verifies that the actual File exists, regardless it's a file or directory.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File does not exist.
      • doesNotExist

        public FileAssert doesNotExist()
        Verifies that the actual File does not exist.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File exists.
      • isFile

        public FileAssert isFile()
        Verifies that the actual File is an existing file.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an existing file.
      • isDirectory

        public FileAssert isDirectory()
        Verifies that the actual File is an existing directory.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an existing file.
      • isAbsolute

        public FileAssert isAbsolute()
        Verifies that the actual File is an absolute path.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an absolute path.
      • isRelative

        public FileAssert isRelative()
        Verifies that the actual File is a relative path.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not a relative path.
      • hasContentEqualTo

        public FileAssert hasContentEqualTo​(java.io.File expected)
        Verifies that the content of the actual File is equal to the content of the given one.
        Parameters:
        expected - the given File to compare the actual File to.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given File is null.
        java.lang.IllegalArgumentException - if the given File is not an existing file.
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an existing file.
        org.fest.util.FilesException - if an I/O error occurs.
        java.lang.AssertionError - if the content of the actual File is not equal to the content of the given one.
      • hasBinaryContent

        public FileAssert hasBinaryContent​(byte[] expected)
        Verifies that the binary content of the actual File is exactly equal to the given one.
        Parameters:
        expected - the expected binary content to compare the actual File's content to.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given content is null.
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an existing file.
        org.fest.util.FilesException - if an I/O error occurs.
        java.lang.AssertionError - if the content of the actual File is not equal to the given binary content.
      • usingCharset

        public FileAssert usingCharset​(java.lang.String charsetName)
        Specifies the name of the charset to use for text-based assertions on the file's contents.
        Parameters:
        charsetName - the name of the charset to use.
        Returns:
        this assertion object.
        Throws:
        java.lang.IllegalArgumentException - if the given encoding is not supported on this platform.
      • usingCharset

        public FileAssert usingCharset​(java.nio.charset.Charset charset)
        Specifies the charset to use for text-based assertions on the file's contents.
        Parameters:
        charset - the charset to use.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given charset is null.
      • hasContent

        public FileAssert hasContent​(java.lang.String expected)
        Verifies that the text content of the actual File is exactly equal to the given one.
        The charset to use when reading the file should be provided with usingCharset(Charset) or usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset.defaultCharset()) will be used.
        Parameters:
        expected - the expected text content to compare the actual File's content to.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given content is null.
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File is not an existing file.
        org.fest.util.FilesException - if an I/O error occurs.
        java.lang.AssertionError - if the content of the actual File is not equal to the given binary content.
      • canWrite

        public FileAssert canWrite()
        Verifies that the actual File can be modified by the application.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File can not be modified by the application.
      • canRead

        public FileAssert canRead()
        Verifies that the actual File can be read by the application.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual File is null.
        java.lang.AssertionError - if the actual File can not be read by the application.