Class TestSupport

  • Direct Known Subclasses:
    TestHelper

    public class TestSupport
    extends Object
    This is a utility class that is for support of various testing activities and is not meant to be used in other contexts. It is not explicitly in a test package given our dependency hierarchy.
    Author:
    Stephen Mallette (http://stephen.genoprime.com)
    • Constructor Detail

      • TestSupport

        protected TestSupport()
    • Method Detail

      • makeTestDataPath

        public static File makeTestDataPath​(Class<?> clazz,
                                            String... childPath)
        Creates a File reference that points to a directory relative to the supplied class in the /target directory. Each childPath passed introduces a new sub-directory and all are placed below the TEST_DATA_RELATIVE_DIR. For example, calling this method with "a", "b", and "c" as the childPath arguments would yield a relative directory like: test-case-data/clazz/a/b/c. It is a good idea to use the test class for the clazz argument so that it's easy to find the data if necessary after test execution.

        Avoid using makeTestDataPath(...).getAbsolutePath() and makeTestDataPath(...).toString() that produces platform-dependent paths, that are incompatible with regular expressions and escape characters. Instead use Storage.toPath(File)

      • makeTestDataDirectory

        public static String makeTestDataDirectory​(Class<?> clazz,
                                                   String... childPath)
        Creates a File reference that . For example, calling this method with "a", "b", and "c" as the childPath arguments would yield a relative directory like: test-case-data/clazz/a/b/c. It is a good idea to use the test class for the clazz argument so that it's easy to find the data if necessary after test execution.
        Returns:
        UNIX-formatted path to a directory in the underlying Storage. The directory is relative to the supplied class in the /target directory. Each childPath passed introduces a new sub-directory and all are placed below the TEST_DATA_RELATIVE_DIR
      • makeTestDataFile

        public static String makeTestDataFile​(Class<?> clazz,
                                              String fileName)
        Parameters:
        clazz -
        fileName -
        Returns:
        UNIX-formatted path to a fileName in the underlying Storage. The file is relative to the supplied class in the /target directory.
      • makeTestDataFile

        public static String makeTestDataFile​(Class<?> clazz,
                                              String subdir,
                                              String fileName)
        Parameters:
        clazz -
        subdir -
        fileName -
        Returns:
        UNIX-formatted path to a subdir/fileName in the underlying Storage. The file is relative to the supplied class in the /target directory.
      • getRootOfBuildDirectory

        public static File getRootOfBuildDirectory​(Class<?> clazz)
        Gets and/or creates the root of the test data directory. This method is here as a convenience and should not be used to store test data. Use makeTestDataPath(Class, String...) instead.
      • cleanPathSegment

        public static String cleanPathSegment​(String toClean)
        Removes characters that aren't acceptable in a file path (mostly for windows).