Class TestResources


  • public final class TestResources
    extends java.lang.Object
    Util class to help get testing resources.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File getDirectory​(java.lang.Class<?> clazz, java.lang.String path)
      Returns a file that is a directory from resources.
      static java.io.File getDirectory​(java.lang.String name)
      Variant of getDirectory(Class, String) that only works with absolute paths, so doesn't need a "context" class.
      static java.io.File getFile​(java.lang.Class<?> clazz, java.lang.String name)
      Returns a file from class resources.
      static java.io.File getFile​(java.lang.String name)
      Variant of getFile(Class, String) that only works with absolute paths, so doesn't need a "context" class.
      static void getFileInDirectory​(java.lang.Class<?> clazz, java.lang.String resourceName, java.lang.String filePath)
      Given a resourceName relative to clazz, copies the resource to a new file at filePath and registers that to be deleted when the JVM exits.
      • Methods inherited from class java.lang.Object

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

      • getFile

        public static java.io.File getFile​(java.lang.Class<?> clazz,
                                           java.lang.String name)
        Returns a file from class resources. If original resource is not file, a temp file is created and returned with resource stream content; the temp file will be deleted when program exits.
        Parameters:
        clazz - Test class.
        name - Resource name.
        Returns:
        File with resource content.
      • getFileInDirectory

        public static void getFileInDirectory​(java.lang.Class<?> clazz,
                                              java.lang.String resourceName,
                                              java.lang.String filePath)
        Given a resourceName relative to clazz, copies the resource to a new file at filePath and registers that to be deleted when the JVM exits. If there is an existing file at filePath, it does nothing.
        Parameters:
        clazz - Resource class.
        resourceName - Input name to get resource from class.
        filePath - Output file name in specific directory.
      • getDirectory

        public static java.io.File getDirectory​(java.lang.Class<?> clazz,
                                                java.lang.String path)
        Returns a file that is a directory from resources. If original resources is in a jar, the specified directory and all files beneath are copied to system temp root directory. Those copied temp files will be deleted on program exits.
        Parameters:
        clazz - Class with resources.
        path - Directory path.
        Returns:
        Directory of given path that contains resources.