Skip to content

Commit

Permalink
Issue sevntu-checkstyle#610: standardized UTs from CheckstyleTestMake…
Browse files Browse the repository at this point in the history
…up violations
  • Loading branch information
rnveach authored and kariem committed Jul 26, 2018
1 parent f5a128c commit 1e5c804
Show file tree
Hide file tree
Showing 58 changed files with 717 additions and 653 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class BaseCheckTestSupport {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final PrintStream printStream = new PrintStream(baos);

public static DefaultConfiguration createCheckConfig(Class<?> clazz) {
public static DefaultConfiguration createModuleConfig(Class<?> clazz) {
return new DefaultConfiguration(clazz.getName());
}

Expand Down Expand Up @@ -111,7 +111,7 @@ protected Checker createChecker(Configuration checkConfig) throws Exception {

protected DefaultConfiguration createCheckerConfig(Configuration config) {
final DefaultConfiguration result = new DefaultConfiguration("configuration");
final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
// make sure that the tests always run with this charset
result.addAttribute("charset", "iso-8859-1");
result.addChild(treeWalkerConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ForbidAnnotationCheckTest extends BaseCheckTestSupport {

@Test
public void testDefaultCheck() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

final String[] expected1 = {};

Expand All @@ -45,7 +45,7 @@ public void testDefaultCheck() throws Exception {

@Test
public void testNullProperties() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", null);
checkConfig.addAttribute("annotationTargets", null);
Expand All @@ -57,7 +57,7 @@ public void testNullProperties() throws Exception {

@Test
public void testFullAnnotationName() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "Test");

Expand All @@ -68,7 +68,7 @@ public void testFullAnnotationName() throws Exception {

@Test
public void testVariableIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames",
"Edible,Author,Author2,SuppressWarnings");
Expand All @@ -86,7 +86,7 @@ public void testVariableIsForbidden() throws Exception {

@Test
public void testMethodIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "Twizzle,One,Two,Three,B");
checkConfig.addAttribute("annotationTargets", "METHOD_DEF");
Expand All @@ -104,7 +104,7 @@ public void testMethodIsForbidden() throws Exception {

@Test
public void testClassAndConstuctorIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "Test,ctor,ctor2");
checkConfig.addAttribute("annotationTargets", "CLASS_DEF,CTOR_DEF");
Expand All @@ -120,7 +120,7 @@ public void testClassAndConstuctorIsForbidden() throws Exception {

@Test
public void testAnnotationIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "Retention,Target");
checkConfig.addAttribute("annotationTargets", "ANNOTATION_DEF");
Expand All @@ -135,7 +135,7 @@ public void testAnnotationIsForbidden() throws Exception {

@Test
public void testParameterAndInterfaceIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "MyAnnotation,A");
checkConfig.addAttribute("annotationTargets",
Expand All @@ -151,7 +151,7 @@ public void testParameterAndInterfaceIsForbidden() throws Exception {

@Test
public void testEnumIsForbidden() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(ForbidAnnotationCheck.class);
final DefaultConfiguration checkConfig = createModuleConfig(ForbidAnnotationCheck.class);

checkConfig.addAttribute("annotationNames", "C,int1,int2,int3");
checkConfig.addAttribute("annotationTargets",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ForbidAnnotationElementValueCheckTest extends BaseCheckTestSupport
@Test
public void testAnnotationWithStringParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);
checkConfig.addAttribute("annotationName", "Anno1");
checkConfig.addAttribute("elementName", "str");
checkConfig.addAttribute("forbiddenElementValueRegexp", "someString\\d+");
Expand All @@ -45,7 +45,7 @@ public void testAnnotationWithStringParameter() throws Exception {
@Test
public void testAnnotationWithIntegerParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Anno2");
checkConfig.addAttribute("elementName", "intVal");
Expand All @@ -61,7 +61,7 @@ public void testAnnotationWithIntegerParameter() throws Exception {
@Test
public void testAnnotationWithFloatParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Anno3");
checkConfig.addAttribute("elementName", "floatVal");
Expand All @@ -77,7 +77,7 @@ public void testAnnotationWithFloatParameter() throws Exception {
@Test
public void testAnnotationWithBooleanParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Anno4");
checkConfig.addAttribute("elementName", "boolVal");
Expand All @@ -93,7 +93,7 @@ public void testAnnotationWithBooleanParameter() throws Exception {
@Test
public void testAnnotationWithDotSplittedParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Bean");
checkConfig.addAttribute("elementName", "name");
Expand All @@ -109,7 +109,7 @@ public void testAnnotationWithDotSplittedParameter() throws Exception {
@Test
public void testAnnotationWithSeveralParameters() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Anno5");
checkConfig.addAttribute("elementName", "stringValue");
Expand All @@ -125,7 +125,7 @@ public void testAnnotationWithSeveralParameters() throws Exception {
@Test
public void testAnnotationWithSingleParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "SuppressWarnings");
checkConfig.addAttribute("elementName", "value");
Expand All @@ -141,7 +141,7 @@ public void testAnnotationWithSingleParameter() throws Exception {
@Test
public void testAnnotationWtithBooleanParameterValueDoesntMatch() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Anno4");
checkConfig.addAttribute("elementName", "boolVal");
Expand All @@ -155,7 +155,7 @@ public void testAnnotationWtithBooleanParameterValueDoesntMatch() throws Excepti
@Test
public void testAnnotationWithListAsParameterValue() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "SuppressWarnings");
checkConfig.addAttribute("elementName", "value");
Expand All @@ -172,7 +172,7 @@ public void testAnnotationWithListAsParameterValue() throws Exception {
@Test
public void testAnnotationWithAnnotationAsParameter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "Name");
checkConfig.addAttribute("elementName", "last");
Expand All @@ -188,7 +188,7 @@ public void testAnnotationWithAnnotationAsParameter() throws Exception {
@Test
public void testAnnotationWithDefaultValues() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

final String[] expected = {
"114:11: " + getCheckMessage(MSG_KEY, "expected", "Test"),
Expand All @@ -200,7 +200,7 @@ public void testAnnotationWithDefaultValues() throws Exception {
@Test
public void testFullAnnotationClasspath() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(ForbidAnnotationElementValueCheck.class);
createModuleConfig(ForbidAnnotationElementValueCheck.class);

checkConfig.addAttribute("annotationName", "SuppressWarnings");
checkConfig.addAttribute("elementName", "value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RequiredParameterForAnnotationCheckTest extends BaseCheckTestSuppor
public void testValidateRequiredParameter()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(RequiredParameterForAnnotationCheck.class);
createModuleConfig(RequiredParameterForAnnotationCheck.class);

checkConfig.addAttribute("annotationName", "testAnnotation1");
checkConfig.addAttribute("requiredParameters", "firstParameter");
Expand All @@ -53,7 +53,7 @@ public void testValidateRequiredParameter()
public void testMultipleProperties1()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(RequiredParameterForAnnotationCheck.class);
createModuleConfig(RequiredParameterForAnnotationCheck.class);

checkConfig.addAttribute("annotationName", "testAnnotation1");
checkConfig.addAttribute("requiredParameters",
Expand Down Expand Up @@ -93,7 +93,7 @@ public void testMultipleProperties1()
public void testMultipleProperties2()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(RequiredParameterForAnnotationCheck.class);
createModuleConfig(RequiredParameterForAnnotationCheck.class);

checkConfig.addAttribute("annotationName", "testAnnotation1");
checkConfig.addAttribute("requiredParameters", "firstParameter,secondParameter");
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testMultipleProperties2()
public void testForAnnotationWithCanonicalName()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(RequiredParameterForAnnotationCheck.class);
createModuleConfig(RequiredParameterForAnnotationCheck.class);

checkConfig.addAttribute("annotationName", "com.github.sevntu.checkstyle.checks"
+ ".annotation.InputRequiredParameterForAnnotationCheck.testAnnotation2");
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testForAnnotationWithCanonicalName()
public void testMultipleParametersForAnnotationWithCanonicalName()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(RequiredParameterForAnnotationCheck.class);
createModuleConfig(RequiredParameterForAnnotationCheck.class);

checkConfig.addAttribute("annotationName", "com.github.sevntu.checkstyle.checks"
+ ".annotation.InputRequiredParameterForAnnotationCheck.testAnnotation2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AvoidConstantAsFirstOperandInConditionCheckTest extends BaseCheckTe
@Test
public void testAll() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidConstantAsFirstOperandInConditionCheck.class);
createModuleConfig(AvoidConstantAsFirstOperandInConditionCheck.class);
final String[] expected = {
"24: " + getCheckMessage(MSG_KEY, "=="),
"25: " + getCheckMessage(MSG_KEY, "=="),
Expand Down Expand Up @@ -69,7 +69,7 @@ public void testAll() throws Exception {
@Test
public void testAttributes() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidConstantAsFirstOperandInConditionCheck.class);
createModuleConfig(AvoidConstantAsFirstOperandInConditionCheck.class);
checkConfig.addAttribute("targetConstantTypes", "LITERAL_FALSE,NUM_INT,NUM_FLOAT");
final String[] expected = {
"25: " + getCheckMessage(MSG_KEY, "=="),
Expand All @@ -84,7 +84,7 @@ public void testAttributes() throws Exception {
@Test
public void testNullProperties() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidConstantAsFirstOperandInConditionCheck.class);
createModuleConfig(AvoidConstantAsFirstOperandInConditionCheck.class);

checkConfig.addAttribute("targetConstantTypes", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AvoidDefaultSerializableInInnerClassesCheckTest extends
public void testWithAllowPartiaFalse()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
createModuleConfig(AvoidDefaultSerializableInInnerClassesCheck.class);

final String[] expected = {
"33: " + warningMessage,
Expand All @@ -61,7 +61,7 @@ public void testWithAllowPartiaFalse()
public void testPrivateNotRealReadObject()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
createModuleConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
checkConfig.addAttribute("allowPartialImplementation", "true");

final String[] expected = {
Expand All @@ -76,7 +76,7 @@ public void testPrivateNotRealReadObject()
public void testRealReadObjectNotRealReadObjectRealPrivate()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
createModuleConfig(AvoidDefaultSerializableInInnerClassesCheck.class);

final String[] expected = {};

Expand All @@ -88,7 +88,7 @@ public void testRealReadObjectNotRealReadObjectRealPrivate()
public void testWithAllowPartiaTrue()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
createModuleConfig(AvoidDefaultSerializableInInnerClassesCheck.class);
checkConfig.addAttribute("allowPartialImplementation", "true");
final String[] expected = {
"33: " + warningMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AvoidHidingCauseExceptionCheckTest extends BaseCheckTestSupport {
@Test
public final void issue52Test() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidHidingCauseExceptionCheck.class);
createModuleConfig(AvoidHidingCauseExceptionCheck.class);

final String[] expected = {};

Expand All @@ -42,7 +42,7 @@ public final void issue52Test() throws Exception {
@Test
public final void test() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidHidingCauseExceptionCheck.class);
createModuleConfig(AvoidHidingCauseExceptionCheck.class);

final String[] expected = {
"18:13: " + getCheckMessage(MSG_KEY, "e"),
Expand All @@ -69,7 +69,7 @@ public final void test() throws Exception {
@Test
public final void testWrappingException() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidHidingCauseExceptionCheck.class);
createModuleConfig(AvoidHidingCauseExceptionCheck.class);

verify(checkConfig, getPath("InputAvoidHidingCauseExceptionCheckWrapping.java"),
CommonUtils.EMPTY_STRING_ARRAY);
Expand Down
Loading

0 comments on commit 1e5c804

Please sign in to comment.