From ec4f7b40c6c777d41b1fe5fe41ac4f85b8b80cc5 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Wed, 3 Aug 2005 13:34:48 +0000 Subject: [PATCH] Finished unit testing - now need to do documentation. --- .../checks/imports/ImportControlCheck.java | 4 ++++ .../checks/imports/messages.properties | 3 ++- .../tools/checkstyle/import-control_one.xml | 1 + .../tools/checkstyle/import-control_wrong.xml | 7 +++++++ .../checkstyle/imports/InputImportControl.java | 1 + .../checks/imports/ImportControlCheckTest.java | 16 ++++++++++++++-- 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 src/testinputs/com/puppycrawl/tools/checkstyle/import-control_wrong.xml diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java index e03a56fee..141f93687 100755 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java @@ -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()); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/messages.properties b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/messages.properties index af4660976..55502b6a6 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/messages.properties +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/messages.properties @@ -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}. \ No newline at end of file +import.control.disallowed=Disallowed import - {0}. +import.control.unknown.pkg=Import control file does not handle this package. \ No newline at end of file diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_one.xml b/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_one.xml index 869dc6565..ec5011063 100755 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_one.xml +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_one.xml @@ -5,6 +5,7 @@ + diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_wrong.xml b/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_wrong.xml new file mode 100755 index 000000000..76cac8c77 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/import-control_wrong.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/imports/InputImportControl.java b/src/testinputs/com/puppycrawl/tools/checkstyle/imports/InputImportControl.java index c9b79b33d..addb2438d 100755 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/imports/InputImportControl.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/imports/InputImportControl.java @@ -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 { diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java index 107d078a4..cab90ae21 100755 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java @@ -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");