Added test for FileLengthCheck
This commit is contained in:
parent
031bc6f277
commit
a7c5f33141
|
|
@ -20,6 +20,7 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
// TODO: tests!
|
||||
|
||||
|
|
@ -59,9 +60,18 @@ public class FileLengthCheck extends Check
|
|||
/**
|
||||
* @param aLength the maximum length of a Java source file
|
||||
*/
|
||||
public void setMax(int aLength)
|
||||
// TODO: Should be an int argument.
|
||||
// It seems like I don't know how to use beanutils, I thought
|
||||
// that parsing this stuff is the core job of beanutils
|
||||
public void setMax(String aLength)
|
||||
{
|
||||
mMaxFileLength = aLength;
|
||||
try {
|
||||
mMaxFileLength = Integer.parseInt(aLength);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
throw new ConversionException("Can't parse '"
|
||||
+ aLength + "' as maximal file length", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.checks.FileLengthCheck;
|
||||
|
||||
public class FileLengthCheckTest
|
||||
extends BaseCheckTestCase
|
||||
{
|
||||
public FileLengthCheckTest(String aName)
|
||||
{
|
||||
super(aName);
|
||||
}
|
||||
|
||||
private void runIt(String aMax, String[] aExpected) throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(FileLengthCheck.class.getName());
|
||||
checkConfig.addProperty("max", aMax);
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("InputSimple.java");
|
||||
verify(c, fname, aExpected);
|
||||
}
|
||||
|
||||
public void testAlarm() throws Exception
|
||||
{
|
||||
final String[] expected = {
|
||||
"1:1: File length is 198 lines (max allowed is 20)."
|
||||
};
|
||||
runIt("20", expected);
|
||||
}
|
||||
|
||||
public void testOK() throws Exception
|
||||
{
|
||||
final String[] expected = {
|
||||
};
|
||||
runIt("2000", expected);
|
||||
}
|
||||
|
||||
public void testArgs() throws Exception
|
||||
{
|
||||
final CheckConfiguration checkConfig = new CheckConfiguration();
|
||||
checkConfig.setClassname(FileLengthCheck.class.getName());
|
||||
try {
|
||||
checkConfig.addProperty("max", "abc");
|
||||
createChecker(checkConfig);
|
||||
fail("Should indicate illegal args");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Expected Exception because of illegal argument for "max"
|
||||
|
||||
// TODO: I would have expected to receive a ConversionException here
|
||||
// but in fact I do get an InvocationTargetException - another
|
||||
// mystery in beanutils?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue