|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface TestClassFinder
Finds Class references by recursively scanning a directory for source files. This class
can be used to build dynamic test suites. To construct a new instance, see
TestClassFinderUtils.newInstance().
An interface is used instead of a concrete class to make mocking and testing easier.
Example:
List<Class<?>> classList =
TestClassFinderUtils.newInstance()
.withRootDir(new File("src/test"))
.withIncludePatterns(Pattern.compile("Test\\.java"))
.findAsList();
| Method Summary | |
|---|---|
Class<?>[] |
findAsArray()
This is a convenience method to call findAsList(). |
List<Class<?>> |
findAsList()
Searches recursively from the root directory to find Java sources files and returns the corresponding Class for each matching file. |
List<Pattern> |
withExcludePatterns()
Retrieves the list of patterns used to include source files. |
TestClassFinder |
withExcludePatterns(List<Pattern> filePathPatternList)
Constructs a new instance with a new list of patterns used to exclude source files. |
TestClassFinder |
withExcludePatterns(Pattern filePathPattern,
Pattern... moreFilePathPatternsArr)
This is a convenience method to call withExcludePatterns(List). |
List<Pattern> |
withIncludePatterns()
Retrieves the list of patterns used to include source files. |
TestClassFinder |
withIncludePatterns(List<Pattern> filePathPatternList)
Constructs a new instance with a new list of patterns used to include source files. |
TestClassFinder |
withIncludePatterns(Pattern filePathPattern,
Pattern... moreFilePathPatternsArr)
This is a convenience method to call withIncludePatterns(List). |
File |
withRootDirPath()
Retrieves root directory to use when finding test classes. |
TestClassFinder |
withRootDirPath(File rootDirPath)
Constructs a new instance with new root directory to use when finding test classes. |
| Method Detail |
|---|
TestClassFinder withRootDirPath(File rootDirPath)
new File("./src/test") is a good choice.
rootDirPath - Path to root directory to search for test classes. Must not be null.
NullPointerException - if rootDirPath is nullTestClassFinderUtils.DEFAULT_ROOT_DIR_PATH,
withRootDirPath()File withRootDirPath()
"user.dir".
TestClassFinderUtils.DEFAULT_ROOT_DIR_PATH,
withRootDirPath(File)
TestClassFinder withIncludePatterns(Pattern filePathPattern,
Pattern... moreFilePathPatternsArr)
withIncludePatterns(List).
NullPointerException - if filePathPattern or moreFilePathPatternsArr (or any element) is
nullTestClassFinder withIncludePatterns(List<Pattern> filePathPatternList)
withExcludePatterns(List).
Matching is performed with Matcher.find(), which does not require the entire input
string to match, like Matcher.matches(). If anchoring is required, the patterns must
explicitly include "^" (start anchor) or "$" (end anchor).
filePathPatternList - "ExternalTest\\.java$""."null, but may be emptyNullPointerException - if filePathPatternList (or any element) is null
IllegalArgumentException - if filePathPatternList is emptyTestClassFinderUtils.DEFAULT_INCLUDE_PATTERN_LIST,
withIncludePatterns(Pattern, Pattern...),
withIncludePatterns(),
withExcludePatterns(List)List<Pattern> withIncludePatterns()
"."
null or empty.TestClassFinderUtils.DEFAULT_INCLUDE_PATTERN_LIST,
withIncludePatterns(List),
withExcludePatterns()
TestClassFinder withExcludePatterns(Pattern filePathPattern,
Pattern... moreFilePathPatternsArr)
withExcludePatterns(List).
NullPointerException - if filePathPattern or moreFilePathPatternsArr (or any element) is
nullTestClassFinder withExcludePatterns(List<Pattern> filePathPatternList)
withIncludePatterns(List).
Matching is performed with Matcher.find(), which does not require the entire input
string to match, like Matcher.matches(). If anchoring is required, the patterns must
explicitly include "^" (start anchor) or "$" (end anchor).
filePathPatternList - "ExternalTest\\.java$"null, but may be emptyNullPointerException - if filePathPatternList (or any element) is nullTestClassFinderUtils.DEFAULT_EXCLUDE_PATTERN_LIST,
withIncludePatterns(Pattern, Pattern...),
withIncludePatterns(),
withIncludePatterns(List)List<Pattern> withExcludePatterns()
null or empty.TestClassFinderUtils.DEFAULT_EXCLUDE_PATTERN_LIST,
withExcludePatterns(List),
withIncludePatterns()List<Class<?>> findAsList()
Class for each matching file. Three class types are automatically
excluded: nested, inner, and abstract classes.
If a source file matches at least one include pattern and matches zero exclude patterns, it will be included in the result.
If SLF4J logging is enabled:
debug level for the root directorydebug level for each normal (regular) file
null.
ClassNotFoundRuntimeException - if a Class cannot be found for a source filefindAsArray()Class<?>[] findAsArray()
findAsList().
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||