added tests for AvoidNestedBlocks check

This commit is contained in:
Lars Kühne 2003-05-18 07:00:51 +00:00
parent c1863ec7e2
commit 545d9f02ff
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle;
/**
* Test case for finding nested blocks.
* @author lkuehne
**/
class InputNestedBlocks
{
static
{ // OK
}
public void method()
{
int x = 0;
// if (condition that is not important anymore)
{ // nested block, should be marked
int x = 1;
int y = x;
}
if (x == 1)
{ // OK
x = 2;
}
switch (x)
{
case 0:
x = 3; // OK
break;
default:
{ // should be marked, even if a switch
// case does not have its own scope
x = 2;
}
}
}
}

View File

@ -63,6 +63,7 @@ import com.puppycrawl.tools.checkstyle.checks.WhitespaceAroundTest;
import com.puppycrawl.tools.checkstyle.checks.ArrayTypeStyleCheckTest;
import com.puppycrawl.tools.checkstyle.checks.FinalParametersCheckTest;
import com.puppycrawl.tools.checkstyle.checks.HideUtilityClassConstructorCheckTest;
import com.puppycrawl.tools.checkstyle.checks.AvoidNestedBlocksCheckTest;
import junit.framework.Test;
import junit.framework.TestSuite;
@ -85,6 +86,7 @@ public class AllTests {
suite.addTest(new TestSuite(AbstractViolationReporterTest.class));
suite.addTest(new TestSuite(ArrayTypeStyleCheckTest.class));
suite.addTest(new TestSuite(AvoidInlineConditionalsCheckTest.class));
suite.addTest(new TestSuite(AvoidNestedBlocksCheckTest.class));
suite.addTest(new TestSuite(AvoidStarImportTest.class));
suite.addTest(new TestSuite(ConfigurationLoaderTest.class));
suite.addTest(new TestSuite(ConstantNameCheckTest.class));

View File

@ -0,0 +1,20 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class AvoidNestedBlocksCheckTest
extends BaseCheckTestCase
{
public void testIt()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidNestedBlocksCheck.class);
final String[] expected = {
"22:9: Avoid nested blocks.",
"38:17: Avoid nested blocks.",
};
verify(checkConfig, getPath("InputNestedBlocks.java"), expected);
}
}