Added a helper method to create a configuration for a check.

As they say in XP, "never repeat yourself". So I will try to
"never repeat yourself".
This commit is contained in:
Oliver Burn 2002-12-01 04:34:28 +00:00
parent cff42d4cd7
commit 79a25c2edc
4 changed files with 24 additions and 17 deletions

View File

@ -9,8 +9,7 @@ public class AvoidStarImportTest
throws Exception
{
final DefaultConfiguration checkConfig =
new DefaultConfiguration("test");
checkConfig.addAttribute("classname", AvoidStarImport.class.getName());
createCheckConfig(AvoidStarImport.class);
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputImport.java");
final String[] expected = {

View File

@ -33,6 +33,14 @@ public abstract class BaseCheckTestCase
protected final PrintStream mStream = new PrintStream(mBAOS);
protected final Properties mProps = new Properties();
public static DefaultConfiguration createCheckConfig(Class aClazz)
{
final DefaultConfiguration checkConfig =
new DefaultConfiguration("test");
checkConfig.addAttribute("classname", aClazz.getName());
return checkConfig;
}
protected Checker createChecker(Configuration aConfig)
throws Exception
{

View File

@ -9,9 +9,9 @@ public class ConstantNameCheckTest
public void testIllegalRegexp()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(ConstantNameCheck.class.getName());
checkConfig.addProperty("format", "\\");
final DefaultConfiguration checkConfig =
createCheckConfig(ConstantNameCheck.class);
checkConfig.addAttribute("format", "\\");
try {
createChecker(checkConfig);
fail();
@ -24,8 +24,8 @@ public class ConstantNameCheckTest
public void testDefault()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(ConstantNameCheck.class.getName());
final DefaultConfiguration checkConfig =
createCheckConfig(ConstantNameCheck.class);
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSimple.java");
final String[] expected = {
@ -38,8 +38,8 @@ public class ConstantNameCheckTest
public void testInterface()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(ConstantNameCheck.class.getName());
final DefaultConfiguration checkConfig =
createCheckConfig(ConstantNameCheck.class);
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputInner.java");
final String[] expected = {

View File

@ -9,8 +9,8 @@ public class EmptyBlockCheckTest
public void testDefault()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(EmptyBlockCheck.class.getName());
final DefaultConfiguration checkConfig =
createCheckConfig(EmptyBlockCheck.class);
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSemantic.java");
final String[] expected = {
@ -30,9 +30,9 @@ public class EmptyBlockCheckTest
public void testText()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(EmptyBlockCheck.class.getName());
checkConfig.addProperty("option", BlockOption.TEXT.toString());
final DefaultConfiguration checkConfig =
createCheckConfig(EmptyBlockCheck.class);
checkConfig.addAttribute("option", BlockOption.TEXT.toString());
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSemantic.java");
final String[] expected = {
@ -48,9 +48,9 @@ public class EmptyBlockCheckTest
public void testStatement()
throws Exception
{
final CheckConfiguration checkConfig = new CheckConfiguration();
checkConfig.setClassname(EmptyBlockCheck.class.getName());
checkConfig.addProperty("option", BlockOption.STMT.toString());
final DefaultConfiguration checkConfig =
createCheckConfig(EmptyBlockCheck.class);
checkConfig.addAttribute("option", BlockOption.STMT.toString());
final Checker c = createChecker(checkConfig);
final String fname = getPath("InputSemantic.java");
final String[] expected = {