パッケージ com.kazurayam.unittest

クラス TestOutputOrganizer

java.lang.Object
com.kazurayam.unittest.TestOutputOrganizer

public final class TestOutputOrganizer extends Object
Provides utility methods that helps JUnit4/JUnit5/TestNG tests with the getProjectDirViaClasspath() method and the resolveOutput(). These methods are useful for Gradle Multi-projects where the Current Working Directory is NOT equal to the sub-projects' root directory.
  • メソッドの詳細

    • getProjectDirectory

      public Path getProjectDirectory()
      戻り値:
      the project directory where the clazz is hosted
    • getOutputDirectoryPathRelativeToProject

      public String getOutputDirectoryPathRelativeToProject()
      戻り値:
      a String like "build/tmp/testOutput" which was given to the Builder.
    • resolveOutputDirectory

      public Path resolveOutputDirectory()
      戻り値:
      returns the java.nio.file.Path object of the output directory. The default is "(projectDir)/test-output". You can customize the name of the output directory by calling setOutputDir(Path.get("dirName")), which is relative to the project directory.
    • createOutputDirectory

      public Path createOutputDirectory() throws IOException
      例外:
      IOException
    • cleanOutputDirectory

      public Path cleanOutputDirectory() throws IOException
      remove the output directory recursively if it is already present. will re-create the output directory, which will be empty
      戻り値:
      the reference to this TestOutputOrganizer instance
      例外:
      IOException - during removing files/directories
    • getOutputSubDirectoryPath

      public Optional<String> getOutputSubDirectoryPath()
    • resolveSubOutputDirectory

      public Path resolveSubOutputDirectory()
      if the subDirPath is set by setSubDir(Path d), then will return getOutputDir().resolve(subDirPath) if the subDirpath is not set, then will return the same as getOutputDir()
      戻り値:
      Path of output sub directory
    • createSubOutputDirectory

      public Path createSubOutputDirectory() throws IOException
      例外:
      IOException
    • cleanSubOutputDirectory

      public Path cleanSubOutputDirectory() throws IOException
      remove the directory, which is identifiable by outputDir.resolve(subDirPath), recursively if it is already present. Will re-create the dir which will be empty.
      戻り値:
      the reference to this TestOutputOrganizer instance
      例外:
      IOException - during removing files/directories
    • resolveClassOutputDirectory

      public Path resolveClassOutputDirectory()
    • createClassOutputDirectory

      public Path createClassOutputDirectory() throws IOException
      例外:
      IOException
    • cleanClassOutputDirectory

      public Path cleanClassOutputDirectory() throws IOException
      例外:
      IOException
    • resolveMethodOutputDirectory

      public Path resolveMethodOutputDirectory(String testMethodName)
    • resolveMethodOutputDirectory

      public Path resolveMethodOutputDirectory(Method testMethod)
    • createMethodOutputDirectory

      public Path createMethodOutputDirectory(String testMethodName) throws IOException
      例外:
      IOException
    • createMethodOutputDirectory

      public Path createMethodOutputDirectory(Method testMethod) throws IOException
      例外:
      IOException
    • cleanMethodOutputDirectory

      public Path cleanMethodOutputDirectory(String testMethodName) throws IOException
      例外:
      IOException
    • cleanMethodOutputDirectory

      public Path cleanMethodOutputDirectory(Method testMethod) throws IOException
      例外:
      IOException
    • toHomeRelativeString

      public String toHomeRelativeString(Path path)
      This method is meant to be used in messages and documentations. You do not want to show your own personal name in the console messages, right? So you will surely want to hide the username part of paths. This method translate a Path of "/User/kazurayam/github/unittest-helper/app/foo.txt" to "~/github/unittest-helper/app/foo.txt" which is relative to the $HOME of the user if the path is located under the $HOME. If the path is NOT located under the $HOME, just stringify the absolute path. This method returns a strin in the UNIX style path representation separated with '/' charactor even on Windows platform.
      パラメータ:
      path - a Path object to be translated into a Home Relative path string
      戻り値:
      a path string prepended by tilde `~` if the path starts with "user.home"
    • copyDir

      public void copyDir(Path sourceDir, Path targetDir) throws IOException
      copy the source directory and its content files/directories to the target directory recursively. If the targetDir is not existing, will create it.
      パラメータ:
      sourceDir - directory to copy from
      targetDir - directory to copy into
      例外:
      IOException - any error while i/o
    • deleteDir

      public void deleteDir(Path targetDir) throws IOException
      delete the target directory and its content files/directories recursively.
      パラメータ:
      targetDir - directory to delete
      例外:
      IOException - any error while deletion