From 03f8352479400cd2c80511bfe0242932a4f00f11 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Thu, 19 Sep 2002 09:07:57 +0000 Subject: [PATCH] Got the unit tests to pass again. They highlighted a bug in the recent changes, and once again prove they are worth the effort. ;-) --- .../puppycrawl/tools/checkstyle/Checker.java | 15 +++++++---- .../com/puppycrawl/tools/checkstyle/Defn.java | 4 +++ .../checkstyle/LocalizedMessageTest.java | 10 ++++--- .../tools/checkstyle/TreeWalkerTest.java | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index bf75cf428..da4a6dece 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -224,21 +224,25 @@ public class Checker } catch (FileNotFoundException fnfe) { errors = new LocalizedMessage[] { - new LocalizedMessage(0, "general.fileNotFound", null, null)}; + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "general.fileNotFound", null)}; } catch (IOException ioe) { errors = new LocalizedMessage[] { - new LocalizedMessage(0, "general.exception", null, + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "general.exception", new String[] {ioe.getMessage()})}; } catch (RecognitionException re) { errors = new LocalizedMessage[] { - new LocalizedMessage(0, "general.exception", null, + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "general.exception", new String[] {re.getMessage()})}; } catch (TokenStreamException te) { errors = new LocalizedMessage[] { - new LocalizedMessage(0, "general.exception", null, + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "general.exception", new String[] {te.getMessage()})}; } @@ -276,7 +280,8 @@ public class Checker fireFileStarted(docFile); if (!packageDoc.exists()) { final LocalizedMessage error = - new LocalizedMessage(0, "javadoc.packageHtml", null, null); + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "javadoc.packageHtml", null); fireErrors(docFile, new LocalizedMessage[]{error}); packageHtmlErrors++; } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java index 823c0853b..0462240bc 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java @@ -25,6 +25,10 @@ package com.puppycrawl.tools.checkstyle; **/ public interface Defn { + // TODO: Change to a class - follow the advice of Bloch. + /** name of resource bundle for Checkstyle */ + String CHECKSTYLE_BUNDLE = "com.puppycrawl.tools.checkstyle.messages"; + /** property name for the to-do pattern **/ String TODO_PATTERN_PROP = "checkstyle.pattern.todo"; /** property name for the parameter pattern **/ diff --git a/src/tests/com/puppycrawl/tools/checkstyle/LocalizedMessageTest.java b/src/tests/com/puppycrawl/tools/checkstyle/LocalizedMessageTest.java index 0100bbc83..db09a6347 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/LocalizedMessageTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/LocalizedMessageTest.java @@ -9,7 +9,6 @@ import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; public class LocalizedMessageTest extends TestCase { - private final String BUNDLE = "com.puppycrawl.tools.checkstyle.messages"; public LocalizedMessageTest(String name) { super(name); @@ -23,15 +22,18 @@ public class LocalizedMessageTest public void testMisc() { LocalizedMessage lm = - new LocalizedMessage(0, BUNDLE, "DefaultLogger.auditFinished", null); + new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "DefaultLogger.auditFinished", null); assertNotNull(lm); assertEquals("Audit done.", lm.getMessage()); - lm = new LocalizedMessage(0, BUNDLE, "DefaultLogger.addException", + lm = new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "DefaultLogger.addException", new String[]{"Claira"}); assertNotNull(lm); assertEquals("Error auditing Claira", lm.getMessage()); - lm = new LocalizedMessage(0, BUNDLE, "ws.notFollowed", new String[] {"{"}); + lm = new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE, + "ws.notFollowed", new String[] {"{"}); assertNotNull(lm); assertEquals("'{' is not followed by whitespace.", lm.getMessage()); } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java new file mode 100644 index 000000000..765c541e4 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java @@ -0,0 +1,27 @@ +/* + * Created by IntelliJ IDEA. + * User: oliver.burn + * Date: 19/09/2002 + * Time: 18:35:19 + * To change template for new class use + * Code Style | Class Templates options (Tools | IDE Options). + */ +package com.puppycrawl.tools.checkstyle; + +import junit.framework.TestCase; +import com.puppycrawl.tools.checkstyle.api.LocalizedMessages; + +public class TreeWalkerTest + extends TestCase +{ + public TreeWalkerTest(String s) + { + super(s); + } + + public void testCreate() + { + new TreeWalker(new LocalizedMessages(8)); + assertTrue(true); + } +}