public class HintTest extends Object
HintTest.create() .input("<input Java source code>") .run(<class containg the hint>) .assertWarnings("<required warning(s)>");Note: when verifying that no warnings are produced in a particular situation, do not pass any warnings to the
assertWarnings
method.
A test verifying that a hint's transformation is correct:
HintTest.create() .input("<input Java source code>") .run(<class containg the hint>) .findWarning("<a warning produce by the hint>") .applyFix() //fill apply the only fix in the given ErrorDescription .assertCompilable() .assertOutput("<output Java source code>");All the tests run under the
test
branding, which allows to specify test values
for bundle keys for warning and fix in Bundle_test.properties
, to isolate the
test from changes in the production Bundle.properties
.Modifier and Type | Class and Description |
---|---|
class |
HintTest.AppliedFix
A wrapper over result after applying a fix.
|
class |
HintTest.HintOutput
Encapsulated the output of the hint.
|
class |
HintTest.HintWarning
A wrapper over a single warning.
|
Modifier and Type | Method and Description |
---|---|
HintTest |
classpath(URL... entries)
Use the specified
URL s as compile classpath while parsing
the Java input. |
static HintTest |
create()
Bootstraps the test framework.
|
HintTest |
input(String code)
Create a test file.
|
HintTest |
input(String code,
boolean compilable)
Create a test file.
|
HintTest |
input(String fileName,
String code)
Create a test file.
|
HintTest |
input(String fileName,
String code,
boolean compilable)
Create a test file.
|
HintTest |
options(String... options)
Sets additional command line options for all Java files used in this test.
|
HintTest |
preference(String preferencesKey,
boolean value)
Sets a preference that will be visible to the hint.
|
HintTest |
preference(String preferencesKey,
int value)
Sets a preference that will be visible to the hint.
|
HintTest |
preference(String preferencesKey,
String value)
Sets a preference that will be visible to the hint.
|
HintTest.HintOutput |
run(Class<?> hint)
Runs the given hint(s) on the first file written by a
input method. |
HintTest.HintOutput |
run(Class<?> hint,
String hintCode)
Runs the given hint(s) on the first file written by a
input method. |
HintTest |
setCaretMarker(char c)
A character to use as a marker of a caret in the input code.
|
HintTest |
sourceLevel(int sourceLevel)
Sets a source level for all Java files used in this test.
|
HintTest |
sourceLevel(String sourceLevel)
Sets a source level for all Java files used in this test.
|
public static HintTest create() throws Exception
run
method and assert results.Exception
public HintTest setCaretMarker(char c)
c
- a caret markerpublic HintTest classpath(URL... entries)
URL
s as compile classpath while parsing
the Java input. The URL
s need to be "folder" URL
s,
ready to be passed to ClassPathSupport.createClassPath(java.net.URL[])
.entries
- that should become roots of the compile classpathFileUtil.urlForArchiveOrDir(java.io.File)
,
FileUtil.getArchiveRoot(java.net.URL)
public HintTest input(String code) throws Exception
input("test/Test.java", code, true)
.code
- the content of the newly created test fileException
public HintTest input(String code, boolean compilable) throws Exception
input("test/Test.java", code, compilable)
.code
- the content of the newly created test filecompilable
- if true, it will be verified that the file does not contain
compilation errors before the hint is run on itException
public HintTest input(String fileName, String code) throws Exception
input(fileName, code, true)
.fileName
- a relative file name of the newly created file from a (automatically created) source rootcode
- the content of the newly created test fileException
public HintTest input(String fileName, String code, boolean compilable) throws Exception
fileName
- a relative file name of the newly created file from a (automatically created) source rootcode
- the content of the newly created test filecompilable
- if true, it will be verified that the file does not contain
compilation errors before the hint is run on itException
public HintTest sourceLevel(int sourceLevel)
sourceLevel
- the source level to use while parsing Java filespublic HintTest sourceLevel(String sourceLevel)
sourceLevel
- the source level to use while parsing Java filespublic HintTest options(String... options)
options
- the additional command line options to use while parsing Java filespublic HintTest preference(String preferencesKey, String value)
preferencesKey
- a key for the preferencesvalue
- the value to setpublic HintTest preference(String preferencesKey, int value)
preferencesKey
- a key for the preferencesvalue
- the value to setpublic HintTest preference(String preferencesKey, boolean value)
preferencesKey
- a key for the preferencesvalue
- the value to setpublic HintTest.HintOutput run(Class<?> hint) throws Exception
input
method.hint
- all hints in this class will be run on the fileException
public HintTest.HintOutput run(Class<?> hint, String hintCode) throws Exception
input
method.
Runs only hints with the specified hintCode
. Null hintCode includes
all hints from the classhint
- all hints in this class will be run on the filehintCode
- if not null
, only hints with the same id will be runException