Class Files

java.lang.Object
org.assertj.core.internal.Files

public class Files extends Object
Reusable assertions for Files.
  • Field Details

  • Constructor Details

    • Files

      Files()
  • Method Details

    • instance

      public static Files instance()
      Returns the singleton instance of this class.
      Returns:
      the singleton instance of this class.
    • assertSameContentAs

      public void assertSameContentAs(AssertionInfo info, File actual, Charset actualCharset, File expected, Charset expectedCharset)
      Asserts that the given files have same content. Adapted from FileAssert (from JUnit-addons.)
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" file.
      actualCharset - Charset of the "actual" file.
      expected - the "expected" file.
      expectedCharset - Charset of the "actual" file.
      Throws:
      NullPointerException - if expected is null.
      IllegalArgumentException - if expected is not an existing file.
      AssertionError - if actual is null.
      AssertionError - if actual is not an existing file.
      RuntimeIOException - if an I/O error occurs.
      AssertionError - if the given files do not have same content.
    • assertHasBinaryContent

      public void assertHasBinaryContent(AssertionInfo info, File actual, byte[] expected)
      Asserts that the given file has the given binary content.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" file.
      expected - the "expected" binary content.
      Throws:
      NullPointerException - if expected is null.
      AssertionError - if actual is null.
      AssertionError - if actual is not an existing file.
      RuntimeIOException - if an I/O error occurs.
      AssertionError - if the file does not have the binary content.
    • assertHasContent

      public void assertHasContent(AssertionInfo info, File actual, String expected, Charset charset)
      Asserts that the given file has the given text content.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" file.
      expected - the "expected" text content.
      charset - the charset to use to read the file.
      Throws:
      NullPointerException - if expected is null.
      AssertionError - if actual is null.
      AssertionError - if actual is not an existing file.
      RuntimeIOException - if an I/O error occurs.
      AssertionError - if the file does not have the text content.
    • verifyIsFile

      private void verifyIsFile(File expected)
    • assertIsFile

      public void assertIsFile(AssertionInfo info, File actual)
      Asserts that the given file is an existing file.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file is not an existing file.
    • assertIsDirectory

      public void assertIsDirectory(AssertionInfo info, File actual)
      Asserts that the given file is an existing directory.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file is not an existing directory.
    • assertIsAbsolute

      public void assertIsAbsolute(AssertionInfo info, File actual)
      Asserts that the given file is an absolute path.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file is not an absolute path.
    • assertIsRelative

      public void assertIsRelative(AssertionInfo info, File actual)
      Asserts that the given file is a relative path.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file is not a relative path.
    • isAbsolutePath

      private boolean isAbsolutePath(AssertionInfo info, File actual)
    • assertExists

      public void assertExists(AssertionInfo info, File actual)
      Asserts that the given file exists, regardless it's a file or directory.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file does not exist.
    • assertDoesNotExist

      public void assertDoesNotExist(AssertionInfo info, File actual)
      Asserts that the given file does not exist.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file exists.
    • assertCanWrite

      public void assertCanWrite(AssertionInfo info, File actual)
      Asserts that the given file can be modified by the application.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file can not be modified.
    • assertCanRead

      public void assertCanRead(AssertionInfo info, File actual)
      Asserts that the given file can be read by the application.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the given file is null.
      AssertionError - if the given file can not be modified.
    • assertHasParent

      public void assertHasParent(AssertionInfo info, File actual, File expected)
      Asserts that the given File has the given parent.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      expected - the expected parent File.
      Throws:
      NullPointerException - if the expected parent File is null.
      RuntimeIOException - if an I/O error occurs.
      AssertionError - if the given File is null.
      AssertionError - if the given File does not have a parent.
      AssertionError - if the given File parent is not equal to the expected one.
    • assertHasExtension

      public void assertHasExtension(AssertionInfo info, File actual, String expected)
      Asserts that the given File has the given extension.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      expected - the expected extension, it does not contains the '.'
      Throws:
      NullPointerException - if the expected extension is null.
      AssertionError - if the actual File is null.
      AssertionError - if the actual File is not a file (ie a directory).
      AssertionError - if the actual File does not have the expected extension.
    • getFileExtension

      private String getFileExtension(File file)
    • assertHasName

      public void assertHasName(AssertionInfo info, File actual, String expected)
      Asserts that the given File has the given name.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      expected - the expected file name.
      Throws:
      NullPointerException - if the expected name is null.
      AssertionError - if the actual File is null.
      AssertionError - if the actual File does not have the expected name.
    • assertNotNull

      private static void assertNotNull(AssertionInfo info, File actual)
    • assertHasNoParent

      public void assertHasNoParent(AssertionInfo info, File actual)
      Asserts that the given File does not have a parent.
      Parameters:
      info - contains information about the assertion.
      actual - the given file.
      Throws:
      AssertionError - if the actual File is null.
      AssertionError - if the actual File has a parent.