Package it.tidalwave.util.test
Class BaseTestHelper
- java.lang.Object
-
- it.tidalwave.util.test.BaseTestHelper
-
- Direct Known Subclasses:
SpringTestHelper
public class BaseTestHelper extends java.lang.ObjectA 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 classBaseTestHelper.TestResourceA manipulator of a pair of (actual file, expected file).
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Objecttest
-
Constructor Summary
Constructors Constructor Description BaseTestHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringreadStringFromResource(java.lang.String resourceName)Reads the content from the resource file as a single string.java.nio.file.PathresourceFileFor(java.lang.String resourceName)Returns aPathfor a resource file.BaseTestHelper.TestResourcetestResourceFor(java.lang.String resourceName)Create aBaseTestHelper.TestResourcefor the given name.
-
-
-
Method Detail
-
resourceFileFor
@Nonnull public java.nio.file.Path resourceFileFor(@Nonnull java.lang.String resourceName)Returns aPathfor a resource file. The resource should be placed undersrc/test/resources/test-class-simple-name/test-resources/resource-name. Note that the file actually loaded is the one undertarget/test-classescopied 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.IOExceptionReads the content from the resource file as a single string. SeeresourceFileFor(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 aBaseTestHelper.TestResourcefor the given name. The actual file will be created undertarget/test-artifacts/test-class-simple-name/resourceName. The expected file should be placed insrc/test/resources/test-class-simple-name/expected-results/resource-name. Note that the file actually loaded is the one undertarget/test-classescopied there (and eventually filtered) by Maven. Thetest-class-simple-nameis 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
-
-