Finished unit testing - now need to do documentation.

This commit is contained in:
Oliver Burn 2005-08-03 13:34:48 +00:00
parent dc3fa902da
commit ec4f7b40c6
6 changed files with 29 additions and 3 deletions

View File

@ -80,6 +80,9 @@ public class ImportControlCheck extends Check
else {
mInPkg = full.getText();
mCurrentLeaf = mRoot.locateFinest(mInPkg);
if (mCurrentLeaf == null) {
log(nameAST, "import.control.unknown.pkg");
}
}
}
else if (mCurrentLeaf != null) {
@ -88,6 +91,7 @@ public class ImportControlCheck extends Check
imp = FullIdent.createFullIdentBelow(aAST);
}
else {
// know it is a static import
imp = FullIdent.createFullIdent((DetailAST) aAST
.getFirstChild().getNextSibling());
}

View File

@ -7,4 +7,5 @@ import.unused=Unused import - {0}.
import.ordering=Wrong order for ''{0}'' import.
import.separation=''{0}'' should be separated from previous imports.
import.control.missing.file=Missing an import control file.
import.control.disallowed=Disallowed import - {0}.
import.control.disallowed=Disallowed import - {0}.
import.control.unknown.pkg=Import control file does not handle this package.

View File

@ -5,6 +5,7 @@
<import-control pkg="com.puppycrawl.tools.checkstyle">
<allow class="java.awt.Image"/>
<allow class="java.awt.Button.ABORT"/>
<allow class="java.io.File" local-only="selected"/>
<subpackage name="imports">
<allow pkg="javax.swing"/>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE import-control PUBLIC
"-//Puppy Crawl//DTD Import Control 1.0//EN"
"http://www.puppycrawl.com/dtds/import_control_1_0.dtd">
<import-control pkg="wrong">
</import-control>

View File

@ -3,6 +3,7 @@ package com.puppycrawl.tools.checkstyle.imports;
import java.awt.Image;
import javax.swing.border.*;
import java.io.File;
import static java.awt.Button.ABORT;
public class InputImportControl
{

View File

@ -24,7 +24,19 @@ public class ImportControlCheckTest extends BaseCheckTestCase
checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
+ "/import-control_two.xml");
final String[] expected = {"3:1: Disallowed import - java.awt.Image.",
"4:1: Disallowed import - javax.swing.border.*."};
"4:1: Disallowed import - javax.swing.border.*.",
"6:1: Disallowed import - java.awt.Button.ABORT."};
verify(checkConfig, getPath("imports" + File.separator
+ "InputImportControl.java"), expected);
}
public void testWrong() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
checkConfig.addAttribute("file", System.getProperty("testinputs.dir")
+ "/import-control_wrong.xml");
final String[] expected = {"1:40: Import control file does not handle this package."};
verify(checkConfig, getPath("imports" + File.separator
+ "InputImportControl.java"), expected);
@ -47,7 +59,7 @@ public class ImportControlCheckTest extends BaseCheckTestCase
+ "InputImportControl.java"), expected);
}
public void testWrong() throws Exception
public void testUnknown() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
checkConfig.addAttribute("file", "unknown-file");