Package com.sun.javatest
Class TestFinder
java.lang.Object
com.sun.javatest.TestFinder
- Direct Known Subclasses:
BinaryTestFinder
,ChameleonTestFinder
,HTMLTestFinder
,RandomTestFinder
,ReverseTestFinder
,TagTestFinder
,TestFinderDecorator
Base implementation for test finders which search for test descriptions
given a starting location. When creating instances of TestFinder for use,
the creator should be sure to call the init() method before use.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface is used to report significant errors found while reading files, but which are not of themselves serious enough to stop reading further.static class
This exception is to report serious problems that occur while finding tests. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
A boolean to enable trace output while debugging test finders.protected TestEnvironment
Deprecated.This feature was available in earlier versions of JT Harness but does not interact well with JT Harness 3.0's GUI features. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear outstanding errors found by the test finder, so that until a new error is reported, getErrorCount will return 0 and getErrors will return an empty array.protected void
decodeAllArgs
(String... args) Perform argument decoding, calling decodeArg for successive args until exhausted.protected int
Decode the arg at a specified position in the arg array.protected void
error
(I18NResourceBundle i18n, String key) Report an error to the error handler.protected void
error
(I18NResourceBundle i18n, String key, Object arg) Report an error to the error handler.protected void
error
(I18NResourceBundle i18n, String key, Object... args) Report an error to the error handler.protected void
Report that another file that needs to be read has been found.protected void
Report that a test description has been found.protected void
foundTestDescription
(Map<String, String> entries, File file, int line) Report that data for a test description has been found.Get the current comparator being used.protected static Comparator
<String> Get the default to be used when the user does not want to specify their own.int
Get an count of the number of errors found by this test finder, as recorded by calls to the error handler via error and localizedError.Get the registered error handler.String[]
Get the errors recorded by the test finder, as recorded by calls to the error handler via error and localizedError.File[]
getFiles()
Get the files that were found by the most recent call of read.getRoot()
Get the root file of the test suite, as passed in to theinit
method.Get the root directory of the test suite; this is either the root passed in to the init method or if that is a file, it is the directory containing the file.getTests()
Get the test descriptions that were found by the most recent call of read.void
init
(String[] args, File testSuiteRoot, TestEnvironment env) Initialize the data required by the finder.void
init
(String[] args, File testSuiteRoot, File[] tests, TestFilter[] filters, TestEnvironment env) Deprecated.Use one of the other init() methods.boolean
Determine whether a location corresponds to a directory (folder) or an actual file.long
lastModified
(File f) Determine when the last time this path was modified.protected void
localizedError
(String msg) Report a message to the error handler, without additional processing."normalize" the test description entries read from a file.protected void
Handle a test description entry read from a file.void
Read a file, looking for test descriptions and other files that might need to be read.protected abstract void
Scan a file, looking for test descriptions and other files that might need to be scanned.void
Incoming files and test descriptions are sorted by their name during processing, this method allows adjustment of the comparison method to be used during this sorting.void
Set an error handler to be informed of errors that may arise while reading tests.protected void
Set the test suite root file or directory.Returns the total number of tests in the inspected suite if it is known.
-
Field Details
-
debug
protected static boolean debugA boolean to enable trace output while debugging test finders. -
env
Deprecated.This feature was available in earlier versions of JT Harness but does not interact well with JT Harness 3.0's GUI features. Use with discretion, if at all.The environment passed in when the test finder was initialized. It is not used by the basic test finder code, but may be used by individual test finders to modify test descriptions as they are read.
-
-
Constructor Details
-
TestFinder
public TestFinder()
-
-
Method Details
-
getDefaultComparator
Get the default to be used when the user does not want to specify their own. The default is a US Locale Collator.- Returns:
- The comparator which would be used if a custom one was not provided.
-
init
Initialize the data required by the finder. Clients creating instances of test finders should call this before allowing use of the finder. Not doing so may result in unexpected results.- Parameters:
args
- An array of strings specified as arguments in the environment. Null indicates no args.testSuiteRoot
- The root file that will be passed to test descriptions read by the finder.env
- The environment being used to run the test. May be null.- Throws:
TestFinder.Fault
- if there is a problem interpreting any of args.
-
init
@Deprecated public void init(String[] args, File testSuiteRoot, File[] tests, TestFilter[] filters, TestEnvironment env) throws TestFinder.Fault Deprecated.Use one of the other init() methods. This functionality is no longer supported. Methods on TestResultTable should yield similar results.Initialize the data required by the finder. Clients creating instances of test finders should call this before allowing use of the finder. Not doing so may result in unexpected results.- Parameters:
args
- An array of strings specified as arguments in the environment. Null indicates no args.testSuiteRoot
- The root file that will be passed to test descriptions read by the finder.tests
- The tests to be read by the finder. (ignored)filters
- An optional array of filters to filter the tests read by the finder.env
- The environment being used to run the test. May be null.- Throws:
TestFinder.Fault
- if there is a problem interpreting any of args.- See Also:
-
decodeAllArgs
Perform argument decoding, calling decodeArg for successive args until exhausted.- Parameters:
args
- The arguments to be decoded- Throws:
TestFinder.Fault
- if decodeArg throws the exception while decoding one of the arguments, or if decodeArg does not recognize an argument.
-
decodeArg
Decode the arg at a specified position in the arg array. If overridden by a subtype, the subtype should try and decode any args it recognizes, and then call super.decodeArg to give the superclass(es) a chance to recognize any arguments.- Parameters:
args
- The array of argumentsi
- The next argument to be decoded- Returns:
- The number of elements consumed in the array; for example, for a simple option like "-v" the result should be 1; for an option with an argument like "-f file" the result should be 2, etc.
- Throws:
TestFinder.Fault
- If there is a problem with the value of the current arg, such as a bad value to an option, the Fault exception can be thrown. The exception should NOT be thrown if the current arg is unrecognized: in that case, an implementation should delegate the call to the supertype.
-
getRoot
Get the root file of the test suite, as passed in to theinit
method.- Returns:
- the root file of the test suite
- See Also:
-
setRoot
Set the test suite root file or directory.- Parameters:
testSuiteRoot
- The path to be set as the root of the test suite in which files will be read.- Throws:
IllegalStateException
- if already setTestFinder.Fault
- if there is some test-finder-specific problem with the specified file.- See Also:
-
getRootDir
Get the root directory of the test suite; this is either the root passed in to the init method or if that is a file, it is the directory containing the file.- Returns:
- the root directory of the test suite
-
getComparator
Get the current comparator being used.- Returns:
- The current comparator, may be null.
- Since:
- 3.2
- See Also:
-
setComparator
Incoming files and test descriptions are sorted by their name during processing, this method allows adjustment of the comparison method to be used during this sorting. Sorting can be disabled by calling this method with anull
parameter. By default, this class will do US Locale sorting.- Parameters:
c
- The comparison operator to be used. Null indicates no sorting (old behavior).- Since:
- 3.2
- See Also:
-
getErrorHandler
Get the registered error handler.- Returns:
- The error handler currently receiving error messages. May be null.
- See Also:
-
setErrorHandler
Set an error handler to be informed of errors that may arise while reading tests. This is typically used to report errors that are not associated with any specific test, such as syntax errors outside of any test description, or problems accessing files.- Parameters:
h
- The error handler that will be informed of non-fatal errors that occur while reading the test suite- See Also:
-
error
Report an error to the error handler.- Parameters:
i18n
- A resource bundle containing the localized error messageskey
- The name of the entry in the resource bundle containing the appropriate error message. The message should not need any arguments.
-
error
Report an error to the error handler.- Parameters:
i18n
- A resource bundle containing the localized error messageskey
- The name of the entry in the resource bundle containing the appropriate error message. The message will be formatted with a single argument, using MessageFormat.format.arg
- The argument to be formatted in the message found in the resource bundle
-
error
Report an error to the error handler.- Parameters:
i18n
- A resource bundle containing the localized error messageskey
- The name of the entry in the resource bundle containing the appropriate error message. The message will be formatted with an array of arguments, using MessageFormat.format.args
- The arguments to be formatted in the message found in the resource bundle
-
localizedError
Report a message to the error handler, without additional processing.- Parameters:
msg
- The message to be reported- See Also:
-
getErrorCount
public int getErrorCount()Get an count of the number of errors found by this test finder, as recorded by calls to the error handler via error and localizedError. The count may be reset using the clearErrors method.- Returns:
- the number of errors found by the test finder
- See Also:
-
getErrors
Get the errors recorded by the test finder, as recorded by calls to the error handler via error and localizedError. Errors reported by the error methods will be given localized. If there are no errors.\, an empty array (not null) will be returned.- Returns:
- the errors found by the test finder
-
clearErrors
public void clearErrors()Clear outstanding errors found by the test finder, so that until a new error is reported, getErrorCount will return 0 and getErrors will return an empty array. -
isFolder
Determine whether a location corresponds to a directory (folder) or an actual file. If the finder implementation chooses, the locations used in read() and scan() may be real or virtual. This method will be queried to determine if a location is a container or something that should be scanned for tests. If it is both...- Parameters:
path
- The location in question.- Since:
- 4.0
-
lastModified
Determine when the last time this path was modified. This is used to decide whether to rescan that location or not. The default implementation defers the choice to the java.- Parameters:
f
- The location in question.- Since:
- 4.0
-
read
Read a file, looking for test descriptions and other files that might need to be read. If the file is relative, it will be evaluated relative to getRootDir. Depending on the test finder, the file may be either a plain file or a directory.- Parameters:
file
- The file to be read.
-
scan
Scan a file, looking for test descriptions and other files that might need to be scanned. The implementation depends on the type of test finder.- Parameters:
file
- The file to scan
-
processEntry
Handle a test description entry read from a file. By default, the name-value pair is inserted into the entries dictionary; however, the method can be overridden by a subtype to adjust the name or value before putting it into the dictionary, or even to ignore/fault the pair.- Parameters:
entries
- The dictionary of the entries being readname
- The name of the entry that has been readvalue
- The value of the entry that has been read
-
normalize
"normalize" the test description entries read from a file. By default, this is a no-op; however, the method can be overridden by a subtype to supply default values for missing entries, etc.- Parameters:
entries
- A set of tag values read from a test description in a file- Returns:
- A normalized set of entries
-
foundTestDescription
Report that data for a test description has been found.- Parameters:
entries
- The data for the test descriptionfile
- The file being readline
- The line number within the file (used for error messages)
-
foundTestDescription
Report that a test description has been found.- Parameters:
td
- The data for the test description. May never be null.- See Also:
-
getTests
Get the test descriptions that were found by the most recent call of read.- Returns:
- the test descriptions that were found by the most recent call of read.
- See Also:
-
totalNumberOfTestsInTheSuite
Returns the total number of tests in the inspected suite if it is known. (For example if preliminary quick scan of the suite was done). Default implementation returns empty Optional.- Returns:
- total number of tests or empty optional if there's no info available
-
foundFile
Report that another file that needs to be read has been found.- Parameters:
newFile
- the file that has been found that needs to be read.- See Also:
-
getFiles
Get the files that were found by the most recent call of read.- Returns:
- the files that were found by the most recent call of read.
- See Also:
-