100% UTs coverage for TreeWalker. #1294
This commit is contained in:
parent
b2d7013e9e
commit
a2da840df3
1
pom.xml
1
pom.xml
|
|
@ -1079,7 +1079,6 @@
|
|||
<totalLineRate>95</totalLineRate>
|
||||
<regexes>
|
||||
<regex><pattern>.*.Checker</pattern><branchRate>80</branchRate><lineRate>85</lineRate></regex>
|
||||
<regex><pattern>.*.TreeWalker</pattern><branchRate>97</branchRate><lineRate>94</lineRate></regex>
|
||||
|
||||
<regex><pattern>.*.checks.AbstractOptionCheck</pattern><branchRate>100</branchRate><lineRate>80</lineRate></regex>
|
||||
<regex><pattern>.*.checks.AbstractTypeAwareCheck</pattern><branchRate>87</branchRate><lineRate>84</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -210,9 +210,7 @@ public final class TreeWalker
|
|||
LOG.error(exceptionMsg);
|
||||
final RecognitionException re = tre.recog;
|
||||
String message = "TokenStreamRecognitionException occured";
|
||||
if (re != null) {
|
||||
message = re.getMessage();
|
||||
}
|
||||
message = re.getMessage();
|
||||
getMessageCollector().add(createLocalizedMessage(message));
|
||||
}
|
||||
// RecognitionException and any other (need to check if needed)
|
||||
|
|
|
|||
|
|
@ -268,4 +268,36 @@ public class TreeWalkerTest extends BaseCheckTestSupport {
|
|||
lines.add(" class a {} ");
|
||||
treeWalker.processFiltered(file, lines);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessWithParserTrowable() throws Exception {
|
||||
final TreeWalker treeWalker = new TreeWalker();
|
||||
treeWalker.configure(createCheckConfig(TypeNameCheck.class));
|
||||
PackageObjectFactory factory = new PackageObjectFactory(
|
||||
new HashSet<String>(), Thread.currentThread().getContextClassLoader());
|
||||
treeWalker.setModuleFactory(factory);
|
||||
treeWalker.setCacheFile(temporaryFolder.newFile().getPath());
|
||||
treeWalker.setupChild(createCheckConfig(TypeNameCheck.class));
|
||||
final File file = temporaryFolder.newFile("file.java");
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
lines.add(" classD a {} ");
|
||||
|
||||
treeWalker.processFiltered(file, lines);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessWithRecognitionException() throws Exception {
|
||||
final TreeWalker treeWalker = new TreeWalker();
|
||||
treeWalker.configure(createCheckConfig(TypeNameCheck.class));
|
||||
PackageObjectFactory factory = new PackageObjectFactory(
|
||||
new HashSet<String>(), Thread.currentThread().getContextClassLoader());
|
||||
treeWalker.setModuleFactory(factory);
|
||||
treeWalker.setCacheFile(temporaryFolder.newFile().getPath());
|
||||
treeWalker.setupChild(createCheckConfig(TypeNameCheck.class));
|
||||
final File file = temporaryFolder.newFile("file.java");
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
lines.add(" class a%$# {} ");
|
||||
|
||||
treeWalker.processFiltered(file, lines);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue