Class BaseTestHelper

  • Direct Known Subclasses:
    SpringTestHelper

    public class BaseTestHelper
    extends java.lang.Object
    A facility that provides some common tasks for testing, such as manipulating test files.
    Since:
    3.2-ALPHA-18
    Author:
    Fabrizio Giudici
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  BaseTestHelper.TestResource
      A manipulator of a pair of (actual file, expected file).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object test  
    • Constructor Summary

      Constructors 
      Constructor Description
      BaseTestHelper()  
    • Field Detail

      • test

        @Nonnull
        protected final java.lang.Object test
    • Constructor Detail

      • BaseTestHelper

        public BaseTestHelper()
    • Method Detail

      • resourceFileFor

        @Nonnull
        public java.nio.file.Path resourceFileFor​(@Nonnull
                                                  java.lang.String resourceName)
        Returns a Path for a resource file. The resource should be placed under src/test/resources/test-class-simple-name/test-resources/resource-name. Note that the file actually loaded is the one under target/test-classes copied there (and eventually filtered) by Maven.
        Parameters:
        resourceName - the resource name
        Returns:
        the Path
      • readStringFromResource

        @Nonnull
        public java.lang.String readStringFromResource​(@Nonnull
                                                       java.lang.String resourceName)
                                                throws java.io.IOException
        Reads the content from the resource file as a single string. See resourceFileFor(String) for further info.
        Parameters:
        resourceName - the resource name
        Returns:
        the string
        Throws:
        java.io.IOException - in case of error
      • testResourceFor

        @Nonnull
        public BaseTestHelper.TestResource testResourceFor​(@Nonnull
                                                           java.lang.String resourceName)
                                                    throws java.io.IOException
        Create a BaseTestHelper.TestResource for the given name. The actual file will be created under target/test-artifacts/test-class-simple-name/resourceName. The expected file should be placed in src/test/resources/test-class-simple-name/expected-results/resource-name. Note that the file actually loaded is the one under target/test-classes copied there (and eventually filtered) by Maven. The test-class-simple-name is tried first with the current test, and then with its eventual super-classes; this allows to extend existing test suites. Note that if the resource files for a super class are not in the current project module, they should be explicitly copied here (for instance, by means of the Maven dependency plugin).
        Parameters:
        resourceName - the name
        Returns:
        the TestResource
        Throws:
        java.io.IOException - in case of error