100% test coverage for ThrowsCountCheck, #1009

This commit is contained in:
vlad 2015-05-19 00:00:05 +03:00
parent 893621b965
commit 2c99b9706e
2 changed files with 21 additions and 1 deletions

View File

@ -766,7 +766,6 @@
<regex><pattern>.*.checks.design.InterfaceIsTypeCheck</pattern><branchRate>100</branchRate><lineRate>85</lineRate></regex>
<regex><pattern>.*.checks.design.MutableExceptionCheck</pattern><branchRate>85</branchRate><lineRate>92</lineRate></regex>
<regex><pattern>.*.checks.design.OneTopLevelClassCheck</pattern><branchRate>77</branchRate><lineRate>95</lineRate></regex>
<regex><pattern>.*.checks.design.ThrowsCountCheck</pattern><branchRate>75</branchRate><lineRate>82</lineRate></regex>
<regex><pattern>.*.checks.design.VisibilityModifierCheck</pattern><branchRate>95</branchRate><lineRate>95</lineRate></regex>
<regex><pattern>.*.checks.header.AbstractHeaderCheck</pattern><branchRate>85</branchRate><lineRate>85</lineRate></regex>

View File

@ -19,15 +19,22 @@
package com.puppycrawl.tools.checkstyle.checks.design;
import antlr.CommonHiddenStreamToken;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import java.io.File;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import org.junit.Test;
import static com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck.MSG_KEY;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class ThrowsCountCheckTest extends BaseCheckTestSupport {
@Test
@ -68,4 +75,18 @@ public class ThrowsCountCheckTest extends BaseCheckTestSupport {
int[] expected = {TokenTypes.LITERAL_THROWS};
assertArrayEquals(expected, obj.getRequiredTokens());
}
@Test
public void testWrongTokenType() {
ThrowsCountCheck obj = new ThrowsCountCheck();
DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CLASS_DEF, "class"));
try {
obj.visitToken(ast);
fail();
}
catch (IllegalStateException e) {
assertEquals(ast.toString(), e.getMessage());
}
}
}