Class FileAnticipator


  • public class FileAnticipator
    extends org.junit.Assert
    File anticipator. Example usage with late initialization:
    Author:
    DJ Gregor
    • Constructor Summary

      Constructors 
      Constructor Description
      FileAnticipator()
      Constructor for FileAnticipator.
      FileAnticipator​(boolean initialize)
      Constructor for FileAnticipator.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void deleteExpected()
      Delete expected files, throwing an AssertionFailedError if any of the expected files don't exist.
      void deleteExpected​(boolean ignoreNonExistantFiles)
      Delete expected files, throwing an AssertionFailedError if any of the expected files don't exist.
      java.io.File expecting​(java.io.File parent, java.lang.String name)
      expecting
      java.io.File expecting​(java.lang.String name)
      expecting
      void expectingFileWithPrefix​(java.io.File parent, java.lang.String prefix, java.lang.String... suffixesToExclude)  
      protected void finalize()
      boolean foundExpected()  
      protected static java.lang.String generateRandomHexString​(int length)
      generateRandomHexString
      java.io.File getTempDir()
      getTempDir
      void initialize()
      initialize
      boolean isInitialized()
      isInitialized
      void tearDown()
      tearDown
      java.io.File tempDir​(java.io.File parent, java.lang.String name)
      tempDir
      java.io.File tempDir​(java.lang.String name)
      tempDir
      java.io.File tempFile​(java.io.File parent, java.lang.String name)
      tempFile
      java.io.File tempFile​(java.io.File parent, java.lang.String name, java.lang.String contents)
      tempFile
      java.io.File tempFile​(java.lang.String name)
      tempFile
      java.io.File tempFile​(java.lang.String name, java.lang.String contents)
      tempFile
      • Methods inherited from class org.junit.Assert

        assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileAnticipator

        public FileAnticipator()
                        throws java.io.IOException

        Constructor for FileAnticipator.

        Throws:
        java.io.IOException - if any.
      • FileAnticipator

        public FileAnticipator​(boolean initialize)
                        throws java.io.IOException

        Constructor for FileAnticipator.

        Parameters:
        initialize - a boolean.
        Throws:
        java.io.IOException - if any.
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • tearDown

        public void tearDown()

        tearDown

      • initialize

        public void initialize()
                        throws java.io.IOException

        initialize

        Throws:
        java.io.IOException - if any.
      • generateRandomHexString

        protected static java.lang.String generateRandomHexString​(int length)

        generateRandomHexString

        Parameters:
        length - a int.
        Returns:
        a String object.
      • getTempDir

        public java.io.File getTempDir()

        getTempDir

        Returns:
        a File object.
      • tempFile

        public java.io.File tempFile​(java.lang.String name)
                              throws java.io.IOException

        tempFile

        Parameters:
        name - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • tempFile

        public java.io.File tempFile​(java.io.File parent,
                                     java.lang.String name)
                              throws java.io.IOException

        tempFile

        Parameters:
        parent - a File object.
        name - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • tempFile

        public java.io.File tempFile​(java.lang.String name,
                                     java.lang.String contents)
                              throws java.io.IOException

        tempFile

        Parameters:
        name - a String object.
        contents - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • tempFile

        public java.io.File tempFile​(java.io.File parent,
                                     java.lang.String name,
                                     java.lang.String contents)
                              throws java.io.IOException

        tempFile

        Parameters:
        parent - a File object.
        name - a String object.
        contents - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • tempDir

        public java.io.File tempDir​(java.lang.String name)
                             throws java.io.IOException

        tempDir

        Parameters:
        name - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • tempDir

        public java.io.File tempDir​(java.io.File parent,
                                    java.lang.String name)
                             throws java.io.IOException

        tempDir

        Parameters:
        parent - a File object.
        name - a String object.
        Returns:
        a File object.
        Throws:
        java.io.IOException - if any.
      • expecting

        public java.io.File expecting​(java.lang.String name)

        expecting

        Parameters:
        name - a String object.
        Returns:
        a File object.
      • expecting

        public java.io.File expecting​(java.io.File parent,
                                      java.lang.String name)

        expecting

        Parameters:
        parent - a File object.
        name - a String object.
        Returns:
        a File object.
      • expectingFileWithPrefix

        public void expectingFileWithPrefix​(java.io.File parent,
                                            java.lang.String prefix,
                                            java.lang.String... suffixesToExclude)
      • deleteExpected

        public void deleteExpected()
        Delete expected files, throwing an AssertionFailedError if any of the expected files don't exist.
      • deleteExpected

        public void deleteExpected​(boolean ignoreNonExistantFiles)
        Delete expected files, throwing an AssertionFailedError if any of the expected files don't exist.
        Parameters:
        ignoreNonExistantFiles - if true, non-existant files will be ignored and will not throw an AssertionFailedError
        Throws:
        junit.framework.AssertionFailedError - if ignoreNonExistantFiles is false and an expected file does not exist, or if a file cannot be deleted
      • isInitialized

        public boolean isInitialized()

        isInitialized

        Returns:
        a boolean.
      • foundExpected

        public boolean foundExpected()