You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2005/09/13 04:33:02 UTC
svn commit: r280462 [4/4] - in /jakarta/commons/proper/cli/trunk/src:
java/org/apache/commons/cli2/ java/org/apache/commons/cli2/builder/
java/org/apache/commons/cli2/commandline/
java/org/apache/commons/cli2/option/ java/org/apache/commons/cli2/resour...
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java Mon Sep 12 19:32:04 2005
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,6 +20,7 @@
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
+
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
@@ -37,47 +38,44 @@
import org.apache.commons.cli2.builder.GroupBuilder;
import org.apache.commons.cli2.option.ArgumentTest;
import org.apache.commons.cli2.option.DefaultOptionTest;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
-public class HelpFormatterTest extends TestCase {
+public class HelpFormatterTest
+ extends TestCase {
+ private ResourceHelper resources = ResourceHelper.getResourceHelper();
private HelpFormatter helpFormatter;
private Option verbose;
private Group options;
public void setUp() {
helpFormatter = new HelpFormatter("|*", "*-*", "*|", 80);
- helpFormatter.setDivider(
- "+------------------------------------------------------------------------------+");
+ helpFormatter.setDivider("+------------------------------------------------------------------------------+");
helpFormatter.setHeader("Jakarta Commons CLI");
helpFormatter.setFooter("Copyright 2003\nApache Software Foundation");
helpFormatter.setShellCommand("ant");
verbose =
- new DefaultOptionBuilder()
- .withLongName("verbose")
- .withDescription("print the version information and exit")
- .create();
-
- options = new GroupBuilder()
- .withName("options")
- .withOption(DefaultOptionTest.buildHelpOption())
- .withOption(ArgumentTest.buildTargetsArgument())
- .withOption(
- new DefaultOptionBuilder()
- .withLongName("diagnostics")
- .withDescription("print information that might be helpful to diagnose or report problems.")
- .create())
- .withOption(
- new DefaultOptionBuilder()
- .withLongName("projecthelp")
- .withDescription("print project help information")
- .create())
- .withOption(verbose)
- .create();
-
+ new DefaultOptionBuilder().withLongName("verbose")
+ .withDescription("print the version information and exit")
+ .create();
+
+ options =
+ new GroupBuilder().withName("options").withOption(DefaultOptionTest.buildHelpOption())
+ .withOption(ArgumentTest.buildTargetsArgument())
+ .withOption(new DefaultOptionBuilder().withLongName("diagnostics")
+ .withDescription("print information that might be helpful to diagnose or report problems.")
+ .create())
+ .withOption(new DefaultOptionBuilder().withLongName("projecthelp")
+ .withDescription("print project help information")
+ .create()).withOption(verbose)
+ .create();
+
helpFormatter.setGroup(options);
}
- public void testPrint() throws IOException {
+ public void testPrint()
+ throws IOException {
final StringWriter writer = new StringWriter();
final PrintWriter pw = new PrintWriter(writer);
helpFormatter.setPrintWriter(pw);
@@ -96,344 +94,282 @@
assertEquals("incorrect print writer", pw, helpFormatter.getPrintWriter());
// test divider
- assertEquals("incorrect divider",
- "+------------------------------------------------------------------------------+",
- helpFormatter.getDivider());
+ assertEquals("incorrect divider",
+ "+------------------------------------------------------------------------------+",
+ helpFormatter.getDivider());
// test header
assertEquals("incorrect header", "Jakarta Commons CLI", helpFormatter.getHeader());
// test footer
assertEquals("incorrect footer", "Copyright 2003\nApache Software Foundation",
- helpFormatter.getFooter());
+ helpFormatter.getFooter());
// test gutters
assertEquals("incorrect left gutter", "|*", helpFormatter.getGutterLeft());
assertEquals("incorrect right gutter", "*|", helpFormatter.getGutterRight());
assertEquals("incorrect center gutter", "*-*", helpFormatter.getGutterCenter());
-
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Jakarta Commons CLI *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Usage: *|",
- reader.readLine());
- assertEquals(
- "|*ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> *|",
- reader.readLine());
- assertEquals(
- "|*...]] *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*options *-* *|",
- reader.readLine());
- assertEquals(
- "|* --help (-?,-h) *-*Displays the help *|",
- reader.readLine());
- assertEquals(
- "|* --diagnostics *-*print information that might be helpful to diagnose *|",
- reader.readLine());
- assertEquals(
- "|* *-*or report problems. *|",
- reader.readLine());
- assertEquals(
- "|* --projecthelp *-*print project help information *|",
- reader.readLine());
- assertEquals(
- "|* --verbose *-*print the version information and exit *|",
- reader.readLine());
- assertEquals(
- "|* target [target ...]*-*The targets ant should build *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Copyright 2003 *|",
- reader.readLine());
- assertEquals(
- "|*Apache Software Foundation *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Jakarta Commons CLI *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Usage: *|",
+ reader.readLine());
+ assertEquals("|*ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> *|",
+ reader.readLine());
+ assertEquals("|*...]] *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*options *-* *|",
+ reader.readLine());
+ assertEquals("|* --help (-?,-h) *-*Displays the help *|",
+ reader.readLine());
+ assertEquals("|* --diagnostics *-*print information that might be helpful to diagnose *|",
+ reader.readLine());
+ assertEquals("|* *-*or report problems. *|",
+ reader.readLine());
+ assertEquals("|* --projecthelp *-*print project help information *|",
+ reader.readLine());
+ assertEquals("|* --verbose *-*print the version information and exit *|",
+ reader.readLine());
+ assertEquals("|* target [target ...]*-*The targets ant should build *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Copyright 2003 *|",
+ reader.readLine());
+ assertEquals("|*Apache Software Foundation *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testComparator() throws IOException {
+ public void testComparator()
+ throws IOException {
final StringWriter writer = new StringWriter();
final PrintWriter pw = new PrintWriter(writer);
helpFormatter.setPrintWriter(pw);
+
final Comparator comparator = new OptionComparator();
helpFormatter.setComparator(comparator);
helpFormatter.print();
// test comparator
assertEquals("invalid comparator", comparator, helpFormatter.getComparator());
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Jakarta Commons CLI *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Usage: *|",
- reader.readLine());
- assertEquals(
- "|*ant [--verbose --projecthelp --help --diagnostics] [<target1> [<target2> *|",
- reader.readLine());
- assertEquals(
- "|*...]] *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*options *-* *|",
- reader.readLine());
- assertEquals(
- "|* --verbose *-*print the version information and exit *|",
- reader.readLine());
- assertEquals(
- "|* --projecthelp *-*print project help information *|",
- reader.readLine());
- assertEquals(
- "|* --help (-?,-h) *-*Displays the help *|",
- reader.readLine());
- assertEquals(
- "|* --diagnostics *-*print information that might be helpful to diagnose *|",
- reader.readLine());
- assertEquals(
- "|* *-*or report problems. *|",
- reader.readLine());
- assertEquals(
- "|* target [target ...]*-*The targets ant should build *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Copyright 2003 *|",
- reader.readLine());
- assertEquals(
- "|*Apache Software Foundation *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Jakarta Commons CLI *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Usage: *|",
+ reader.readLine());
+ assertEquals("|*ant [--verbose --projecthelp --help --diagnostics] [<target1> [<target2> *|",
+ reader.readLine());
+ assertEquals("|*...]] *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*options *-* *|",
+ reader.readLine());
+ assertEquals("|* --verbose *-*print the version information and exit *|",
+ reader.readLine());
+ assertEquals("|* --projecthelp *-*print project help information *|",
+ reader.readLine());
+ assertEquals("|* --help (-?,-h) *-*Displays the help *|",
+ reader.readLine());
+ assertEquals("|* --diagnostics *-*print information that might be helpful to diagnose *|",
+ reader.readLine());
+ assertEquals("|* *-*or report problems. *|",
+ reader.readLine());
+ assertEquals("|* target [target ...]*-*The targets ant should build *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Copyright 2003 *|",
+ reader.readLine());
+ assertEquals("|*Apache Software Foundation *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintHelp() throws IOException {
+ public void testPrintHelp()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printHelp();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*options *-* *|",
- reader.readLine());
- assertEquals(
- "|* --help (-?,-h) *-*Displays the help *|",
- reader.readLine());
- assertEquals(
- "|* --diagnostics *-*print information that might be helpful to diagnose *|",
- reader.readLine());
- assertEquals(
- "|* *-*or report problems. *|",
- reader.readLine());
- assertEquals(
- "|* --projecthelp *-*print project help information *|",
- reader.readLine());
- assertEquals(
- "|* --verbose *-*print the version information and exit *|",
- reader.readLine());
- assertEquals(
- "|* target [target ...]*-*The targets ant should build *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*options *-* *|",
+ reader.readLine());
+ assertEquals("|* --help (-?,-h) *-*Displays the help *|",
+ reader.readLine());
+ assertEquals("|* --diagnostics *-*print information that might be helpful to diagnose *|",
+ reader.readLine());
+ assertEquals("|* *-*or report problems. *|",
+ reader.readLine());
+ assertEquals("|* --projecthelp *-*print project help information *|",
+ reader.readLine());
+ assertEquals("|* --verbose *-*print the version information and exit *|",
+ reader.readLine());
+ assertEquals("|* target [target ...]*-*The targets ant should build *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintHelp_WithException() throws IOException {
+ public void testPrintHelp_WithException()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.setException(new OptionException(verbose));
helpFormatter.printHelp();
+
//System.out.println(writer);
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*--verbose*-*print the version information and exit *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*--verbose*-*print the version information and exit *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintHelp_TooNarrow() throws IOException {
+ public void testPrintHelp_TooNarrow()
+ throws IOException {
final StringWriter writer = new StringWriter();
- helpFormatter = new HelpFormatter("<","=",">",4);
+ helpFormatter = new HelpFormatter("<", "=", ">", 4);
helpFormatter.setGroup(options);
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printHelp();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "<options = >",
- reader.readLine());
- assertEquals(
- "< --help (-?,-h) =D>",
- reader.readLine());
- assertEquals(
- "< =i>",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("<options = >", reader.readLine());
+ assertEquals("< --help (-?,-h) =D>", reader.readLine());
+ assertEquals("< =i>", reader.readLine());
+
// lots more lines unchecked
}
- public void testPrintException() throws IOException {
+ public void testPrintException()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.setException(new OptionException(verbose, "cli.error.missing.option"));
+ helpFormatter.setException(new OptionException(verbose, ResourceConstants.MISSING_OPTION));
helpFormatter.printException();
+
//System.out.println(writer);
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Missing option --verbose *|",
- reader.readLine());
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Missing option --verbose *|",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintUsage() throws IOException {
+ public void testPrintUsage()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printUsage();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Usage: *|",
- reader.readLine());
- assertEquals(
- "|*ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> *|",
- reader.readLine());
- assertEquals(
- "|*...]] *|",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Usage: *|",
+ reader.readLine());
+ assertEquals("|*ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> *|",
+ reader.readLine());
+ assertEquals("|*...]] *|",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintHeader() throws IOException {
+ public void testPrintHeader()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printHeader();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals(
- "|*Jakarta Commons CLI *|",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
+ assertEquals("|*Jakarta Commons CLI *|",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintFooter() throws IOException {
+ public void testPrintFooter()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printFooter();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "|*Copyright 2003 *|",
- reader.readLine());
- assertEquals(
- "|*Apache Software Foundation *|",
- reader.readLine());
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("|*Copyright 2003 *|",
+ reader.readLine());
+ assertEquals("|*Apache Software Foundation *|",
+ reader.readLine());
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
- public void testPrintDivider() throws IOException {
+ public void testPrintDivider()
+ throws IOException {
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.printDivider();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "+------------------------------------------------------------------------------+",
- reader.readLine());
+
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("+------------------------------------------------------------------------------+",
+ reader.readLine());
assertNull(reader.readLine());
}
public void testWrap() {
- final Iterator i =
- HelpFormatter.wrap("Apache Software Foundation", 30).iterator();
+ final Iterator i = HelpFormatter.wrap("Apache Software Foundation", 30).iterator();
assertEquals("Apache Software Foundation", i.next());
assertFalse(i.hasNext());
}
public void testWrap_WrapNeeded() {
- final Iterator i =
- HelpFormatter.wrap("Apache Software Foundation", 20).iterator();
+ final Iterator i = HelpFormatter.wrap("Apache Software Foundation", 20).iterator();
assertEquals("Apache Software", i.next());
assertEquals("Foundation", i.next());
assertFalse(i.hasNext());
}
public void testWrap_BeforeSpace() {
- final Iterator i =
- HelpFormatter.wrap("Apache Software Foundation", 16).iterator();
+ final Iterator i = HelpFormatter.wrap("Apache Software Foundation", 16).iterator();
assertEquals("Apache Software", i.next());
assertEquals("Foundation", i.next());
assertFalse(i.hasNext());
}
public void testWrap_AfterSpace() {
- final Iterator i =
- HelpFormatter.wrap("Apache Software Foundation", 17).iterator();
+ final Iterator i = HelpFormatter.wrap("Apache Software Foundation", 17).iterator();
assertEquals("Apache Software", i.next());
assertEquals("Foundation", i.next());
assertFalse(i.hasNext());
}
public void testWrap_InWord() {
- final Iterator i =
- HelpFormatter.wrap("Apache Software Foundation", 8).iterator();
+ final Iterator i = HelpFormatter.wrap("Apache Software Foundation", 8).iterator();
assertEquals("Apache", i.next());
assertEquals("Software", i.next());
assertEquals("Foundati", i.next());
@@ -442,8 +378,7 @@
}
public void testWrap_NewLine() {
- final Iterator i =
- HelpFormatter.wrap("\nApache Software Foundation\n", 30).iterator();
+ final Iterator i = HelpFormatter.wrap("\nApache Software Foundation\n", 30).iterator();
assertEquals("", i.next());
assertEquals("Apache Software Foundation", i.next());
assertEquals("", i.next());
@@ -451,13 +386,12 @@
}
public void testWrap_NewLine2() {
- List wrapped = HelpFormatter.wrap("A really quite long general description of the option with specific alternatives documented:\n"+
- " Indented special case\n"+
- " Alternative scenario", 30);
-
- final Iterator i =
- wrapped.iterator();
-
+ List wrapped =
+ HelpFormatter.wrap("A really quite long general description of the option with specific alternatives documented:\n" +
+ " Indented special case\n" + " Alternative scenario", 30);
+
+ final Iterator i = wrapped.iterator();
+
assertEquals("A really quite long general", i.next());
assertEquals("description of the option", i.next());
assertEquals("with specific alternatives", i.next());
@@ -466,49 +400,55 @@
assertEquals(" Alternative scenario", i.next());
assertFalse(i.hasNext());
}
-
+
public void testWrap_Below1Length() {
- try{
- HelpFormatter.wrap("Apache Software Foundation",-1);
+ try {
+ HelpFormatter.wrap("Apache Software Foundation", -1);
fail("IllegalArgumentException");
- }
- catch(IllegalArgumentException e) {
- assertEquals("width must be positive",e.getMessage());
+ } catch (IllegalArgumentException e) {
+ assertEquals(resources.getMessage(ResourceConstants.HELPFORMATTER_WIDTH_TOO_NARROW,
+ new Object[] { new Integer(-1) }), e.getMessage());
}
}
- public void testPad() throws IOException {
+ public void testPad()
+ throws IOException {
final StringWriter writer = new StringWriter();
HelpFormatter.pad("hello", 10, writer);
assertEquals("hello ", writer.toString());
}
- public void testPad_Null() throws IOException {
+ public void testPad_Null()
+ throws IOException {
final StringWriter writer = new StringWriter();
HelpFormatter.pad(null, 10, writer);
assertEquals(" ", writer.toString());
}
- public void testPad_TooLong() throws IOException {
+ public void testPad_TooLong()
+ throws IOException {
final StringWriter writer = new StringWriter();
HelpFormatter.pad("hello world", 10, writer);
assertEquals("hello world", writer.toString());
}
-
- public void testPad_TooShort() throws IOException {
+
+ public void testPad_TooShort()
+ throws IOException {
final StringWriter writer = new StringWriter();
HelpFormatter.pad("hello world", -5, writer);
assertEquals("hello world", writer.toString());
}
-
- public void testGutters() throws IOException {
+
+ public void testGutters()
+ throws IOException {
helpFormatter = new HelpFormatter(null, null, null, 80);
helpFormatter.setShellCommand("ant");
+
final Set lusage = new HashSet();
lusage.add(DisplaySetting.DISPLAY_ALIASES);
lusage.add(DisplaySetting.DISPLAY_GROUP_NAME);
helpFormatter.setLineUsageSettings(lusage);
-
+
// test line usage
assertEquals("incorrect line usage", lusage, helpFormatter.getLineUsageSettings());
@@ -534,82 +474,69 @@
dsettings.add(DisplaySetting.DISPLAY_GROUP_NAME);
dsettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED);
dsettings.add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-
+
helpFormatter.setDisplaySettings(dsettings);
verbose =
- new DefaultOptionBuilder()
- .withLongName("verbose")
- .withDescription("print the version information and exit")
- .create();
-
- options = new GroupBuilder()
- .withName("options")
- .withOption(DefaultOptionTest.buildHelpOption())
- .withOption(ArgumentTest.buildTargetsArgument())
- .withOption(
- new DefaultOptionBuilder()
- .withLongName("diagnostics")
- .withDescription("print information that might be helpful to diagnose or report problems.")
- .create())
- .withOption(
- new DefaultOptionBuilder()
- .withLongName("projecthelp")
- .withDescription("print project help information")
- .create())
- .withOption(verbose)
- .create();
-
+ new DefaultOptionBuilder().withLongName("verbose")
+ .withDescription("print the version information and exit")
+ .create();
+
+ options =
+ new GroupBuilder().withName("options").withOption(DefaultOptionTest.buildHelpOption())
+ .withOption(ArgumentTest.buildTargetsArgument())
+ .withOption(new DefaultOptionBuilder().withLongName("diagnostics")
+ .withDescription("print information that might be helpful to diagnose or report problems.")
+ .create())
+ .withOption(new DefaultOptionBuilder().withLongName("projecthelp")
+ .withDescription("print project help information")
+ .create()).withOption(verbose)
+ .create();
+
helpFormatter.setGroup(options);
// test default gutters
- assertEquals("incorrect left gutter", HelpFormatter.DEFAULT_GUTTER_LEFT, helpFormatter.getGutterLeft());
- assertEquals("incorrect right gutter", HelpFormatter.DEFAULT_GUTTER_RIGHT, helpFormatter.getGutterRight());
- assertEquals("incorrect center gutter", HelpFormatter.DEFAULT_GUTTER_CENTER, helpFormatter.getGutterCenter());
-
+ assertEquals("incorrect left gutter", HelpFormatter.DEFAULT_GUTTER_LEFT,
+ helpFormatter.getGutterLeft());
+ assertEquals("incorrect right gutter", HelpFormatter.DEFAULT_GUTTER_RIGHT,
+ helpFormatter.getGutterRight());
+ assertEquals("incorrect center gutter", HelpFormatter.DEFAULT_GUTTER_CENTER,
+ helpFormatter.getGutterCenter());
+
final StringWriter writer = new StringWriter();
helpFormatter.setPrintWriter(new PrintWriter(writer));
helpFormatter.print();
- final BufferedReader reader =
- new BufferedReader(new StringReader(writer.toString()));
- assertEquals(
- "Usage: ",
- reader.readLine());
- assertEquals(
- "ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> ...]] ",
- reader.readLine());
- assertEquals(
- "options ",
- reader.readLine());
- assertEquals(
- " --help (-?,-h) Displays the help ",
- reader.readLine());
- assertEquals(
- " --diagnostics print information that might be helpful to diagnose or ",
- reader.readLine());
- assertEquals(
- " report problems. ",
- reader.readLine());
- assertEquals(
- " --projecthelp print project help information ",
- reader.readLine());
- assertEquals(
- " --verbose print the version information and exit ",
- reader.readLine());
- assertEquals(
- " target [target ...] The targets ant should build ",
- reader.readLine());
+ final BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
+ assertEquals("Usage: ",
+ reader.readLine());
+ assertEquals("ant [--help --diagnostics --projecthelp --verbose] [<target1> [<target2> ...]] ",
+ reader.readLine());
+ assertEquals("options ",
+ reader.readLine());
+ assertEquals(" --help (-?,-h) Displays the help ",
+ reader.readLine());
+ assertEquals(" --diagnostics print information that might be helpful to diagnose or ",
+ reader.readLine());
+ assertEquals(" report problems. ",
+ reader.readLine());
+ assertEquals(" --projecthelp print project help information ",
+ reader.readLine());
+ assertEquals(" --verbose print the version information and exit ",
+ reader.readLine());
+ assertEquals(" target [target ...] The targets ant should build ",
+ reader.readLine());
assertNull(reader.readLine());
}
}
class OptionComparator implements Comparator {
-
- public int compare(Object o1, Object o2) {
+ public int compare(Object o1,
+ Object o2) {
Option opt1 = (Option) o1;
Option opt2 = (Option) o2;
+
return -opt1.getPreferredName().compareTo(opt2.getPreferredName());
}
}
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/ClassValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/ClassValidatorTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/ClassValidatorTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/ClassValidatorTest.java Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2003-2004 The Apache Software Foundation
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
public class ClassValidatorTest extends TestCase {
private final static ResourceHelper resources =
- ResourceHelper.getResourceHelper(ClassValidatorTest.class);
+ ResourceHelper.getResourceHelper();
private ClassValidator validator;
@@ -57,7 +57,7 @@
} catch (InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.bad.classname",
+ "ClassValidator.bad.classname",
className),
ive.getMessage());
}
@@ -75,7 +75,7 @@
} catch (InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.bad.classname",
+ "ClassValidator.bad.classname",
className),
ive.getMessage());
}
@@ -93,7 +93,7 @@
} catch (InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.bad.classname",
+ "ClassValidator.bad.classname",
className),
ive.getMessage());
}
@@ -111,7 +111,7 @@
} catch (InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.bad.classname",
+ "ClassValidator.bad.classname",
className),
ive.getMessage());
}
@@ -157,7 +157,7 @@
} catch (InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.class.notfound",
+ "ClassValidator.class.notfound",
className),
ive.getMessage());
}
@@ -199,7 +199,7 @@
catch (final InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.class.create",
+ "ClassValidator.class.create",
className),
ive.getMessage());
}
@@ -219,7 +219,7 @@
catch (final InvalidArgumentException ive) {
assertEquals(
resources.getMessage(
- "ClassValidator.error.class.access",
+ "ClassValidator.class.access",
className,
"Class org.apache.commons.cli2.validation.ClassValidator " +
"can not access a member of class " +
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/DateValidatorTest.java Mon Sep 12 19:32:04 2005
@@ -17,6 +17,7 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
@@ -27,19 +28,24 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
/**
* JUnit test case for DateValidator.
*
* @author Rob Oxspring
* @author John Keyes
*/
-public class DateValidatorTest extends TestCase {
+public class DateValidatorTest
+ extends TestCase {
+ private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
public static final DateFormat D_M_YY = new SimpleDateFormat("d/M/yy");
- public static final DateFormat YYYY_MM_YY =
- new SimpleDateFormat("yyyy-MM-dd");
+ public static final DateFormat YYYY_MM_YY = new SimpleDateFormat("yyyy-MM-dd");
private List formats = Arrays.asList(new Object[] { D_M_YY, YYYY_MM_YY });
- public void testSingleFormatValidate() throws InvalidArgumentException {
+ public void testSingleFormatValidate()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "23/12/03" };
final List list = Arrays.asList(array);
final Validator validator = new DateValidator(D_M_YY);
@@ -47,11 +53,12 @@
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_YY.format((Date)i.next()));
+ assertEquals("2003-12-23", YYYY_MM_YY.format((Date) i.next()));
assertFalse(i.hasNext());
}
- public void testDefaultDateFormatValidate() throws InvalidArgumentException {
+ public void testDefaultDateFormatValidate()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "23-Dec-2003" };
final List list = Arrays.asList(array);
final Validator validator = DateValidator.getDateInstance();
@@ -59,11 +66,12 @@
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_YY.format((Date)i.next()));
+ assertEquals("2003-12-23", YYYY_MM_YY.format((Date) i.next()));
assertFalse(i.hasNext());
}
- public void testDefaultTimeFormatValidate() throws InvalidArgumentException {
+ public void testDefaultTimeFormatValidate()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "18:00:00" };
final List list = Arrays.asList(array);
final Validator validator = DateValidator.getTimeInstance();
@@ -76,7 +84,8 @@
assertFalse(i.hasNext());
}
- public void testDefaultDateTimeFormatValidate() throws InvalidArgumentException {
+ public void testDefaultDateTimeFormatValidate()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "23-Jan-2003 18:00:00" };
final List list = Arrays.asList(array);
final Validator validator = DateValidator.getDateTimeInstance();
@@ -89,7 +98,8 @@
assertFalse(i.hasNext());
}
- public void testDefaultValidator() throws InvalidArgumentException {
+ public void testDefaultValidator()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "23/01/03 18:00" };
final List list = Arrays.asList(array);
final Validator validator = new DateValidator();
@@ -102,7 +112,8 @@
assertFalse(i.hasNext());
}
- public void testValidate() throws InvalidArgumentException {
+ public void testValidate()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
final List list = Arrays.asList(array);
final Validator validator = new DateValidator(formats);
@@ -110,12 +121,13 @@
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_YY.format((Date)i.next()));
- assertEquals("2002-10-12", YYYY_MM_YY.format((Date)i.next()));
+ assertEquals("2003-12-23", YYYY_MM_YY.format((Date) i.next()));
+ assertEquals("2002-10-12", YYYY_MM_YY.format((Date) i.next()));
assertFalse(i.hasNext());
}
- public void testMinimumBounds() throws InvalidArgumentException {
+ public void testMinimumBounds()
+ throws InvalidArgumentException {
final DateValidator validator = new DateValidator(formats);
final Calendar cal = Calendar.getInstance();
@@ -123,6 +135,7 @@
final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
final List list = Arrays.asList(array);
cal.set(2002, 1, 12);
+
final Date min = cal.getTime();
validator.setMinimum(min);
assertTrue("maximum bound is set", validator.getMaximum() == null);
@@ -134,30 +147,31 @@
final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
final List list = Arrays.asList(array);
cal.set(2003, 1, 12);
+
final Date min = cal.getTime();
validator.setMinimum(min);
try {
validator.validate(list);
fail("minimum out of bounds exception not caught");
- }
- catch (final InvalidArgumentException exp) {
- assertEquals("Out of range: 2002-10-12", exp.getMessage());
+ } catch (final InvalidArgumentException exp) {
+ assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
+ new Object[] { "2002-10-12" }), exp.getMessage());
}
}
}
- public void testFormats() throws InvalidArgumentException {
+ public void testFormats()
+ throws InvalidArgumentException {
final DateValidator validator = new DateValidator(formats);
- assertEquals("date format is incorrect",
- ((SimpleDateFormat)formats.get(0)).toPattern(),
- ((SimpleDateFormat)validator.getFormats()[0]).toPattern());
- assertEquals("date format is incorrect",
- ((SimpleDateFormat)formats.get(1)).toPattern(),
- ((SimpleDateFormat)validator.getFormats()[1]).toPattern());
+ assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(0)).toPattern(),
+ ((SimpleDateFormat) validator.getFormats()[0]).toPattern());
+ assertEquals("date format is incorrect", ((SimpleDateFormat) formats.get(1)).toPattern(),
+ ((SimpleDateFormat) validator.getFormats()[1]).toPattern());
}
- public void testMaximumBounds() throws InvalidArgumentException {
+ public void testMaximumBounds()
+ throws InvalidArgumentException {
final DateValidator validator = new DateValidator(formats);
final Calendar cal = Calendar.getInstance();
@@ -165,6 +179,7 @@
final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
final List list = Arrays.asList(array);
cal.set(2004, 1, 12);
+
final Date max = cal.getTime();
validator.setMaximum(max);
assertTrue("minimum bound is set", validator.getMinimum() == null);
@@ -176,15 +191,16 @@
final Object[] array = new Object[] { "23/12/03", "2004-10-12" };
final List list = Arrays.asList(array);
cal.set(2004, 1, 12);
+
final Date max = cal.getTime();
validator.setMaximum(max);
try {
validator.validate(list);
fail("maximum out of bounds exception not caught");
- }
- catch (final InvalidArgumentException exp) {
- assertEquals("Out of range: 2004-10-12", exp.getMessage());
+ } catch (final InvalidArgumentException exp) {
+ assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
+ new Object[] { "2004-10-12" }), exp.getMessage());
}
}
}
@@ -192,6 +208,7 @@
public static Test suite() {
Test result = new TestSuite(DateValidatorTest.class); // default behavior
result = new TimeZoneTestSuite("EST", result); // ensure it runs in EST timezone
+
return result;
}
}
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/EnumValidatorTest.java Mon Sep 12 19:32:04 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +23,20 @@
import junit.framework.TestCase;
-public class EnumValidatorTest extends TestCase {
- private final Set enumSet = new TreeSet(
- Arrays.asList(
- new Object[]{"red", "green", "blue"}));
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
+public class EnumValidatorTest
+ extends TestCase {
+ private final static ResourceHelper resources = ResourceHelper.getResourceHelper();
+ private final Set enumSet = new TreeSet(Arrays.asList(new Object[] { "red", "green", "blue" }));
+
+ public void testValidate()
+ throws InvalidArgumentException {
+ final Object[] array = new Object[] { "red", "green" };
- public void testValidate() throws InvalidArgumentException {
- final Object[] array = new Object[] { "red", "green"};
{
- final List list = Arrays.asList(array);
+ final List list = Arrays.asList(array);
final EnumValidator validator = new EnumValidator(enumSet);
assertEquals("valid values are incorrect", enumSet, validator.getValidValues());
validator.validate(list);
@@ -44,16 +49,17 @@
}
public void testNonMember() {
- final Object[] array = new Object[] { "red", "pink"};
+ final Object[] array = new Object[] { "red", "pink" };
final List list = Arrays.asList(array);
- final Validator validator = new EnumValidator(enumSet);
+ final EnumValidator validator = new EnumValidator(enumSet);
- try{
+ try {
validator.validate(list);
fail("InvalidArgumentException");
- }
- catch(InvalidArgumentException e){
- assertEquals("'pink' is not allowed. Permitted values are:['blue', 'green', 'red']",e.getMessage());
+ } catch (InvalidArgumentException e) {
+ assertEquals(resources.getMessage(ResourceConstants.ENUM_ILLEGAL_VALUE,
+ new Object[] { "pink", validator.getValuesAsString() }),
+ e.getMessage());
}
}
}
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/NumberValidatorTest.java Mon Sep 12 19:32:04 2005
@@ -16,28 +16,32 @@
package org.apache.commons.cli2.validation;
import java.text.NumberFormat;
+
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
/**
* JUnit test case for NumberValidator.
*
* @author Rob Oxspring
* @author John Keyes
*/
-public class NumberValidatorTest extends TestCase {
-
- public void testValidate_Number() throws InvalidArgumentException {
+public class NumberValidatorTest
+ extends TestCase {
+ private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
+
+ public void testValidate_Number()
+ throws InvalidArgumentException {
final NumberFormat format = NumberFormat.getNumberInstance();
-
- final Object[] array =
- new Object[] {
- format.format(1d),
- format.format(1.07d),
- format.format(-.45d)};
+
+ final Object[] array =
+ new Object[] { format.format(1d), format.format(1.07d), format.format(-.45d) };
{
final List list = Arrays.asList(array);
@@ -46,57 +50,56 @@
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals(1d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number)i.next()).doubleValue(), 0.0001);
+ assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
assertFalse(i.hasNext());
}
}
- public void testValidate_Currency() throws InvalidArgumentException {
+ public void testValidate_Currency()
+ throws InvalidArgumentException {
NumberFormat format = NumberFormat.getCurrencyInstance();
final Object[] array =
- new Object[] {
- format.format(1d),
- format.format(1.07),
- format.format(-0.45)};
+ new Object[] { format.format(1d), format.format(1.07), format.format(-0.45) };
final List list = Arrays.asList(array);
-
+
final NumberValidator validator = NumberValidator.getCurrencyInstance();
assertEquals("incorrect currency format", format, validator.getFormat());
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals(1d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number)i.next()).doubleValue(), 0.0001);
+ assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
assertFalse(i.hasNext());
}
- public void testValidate_Percent() throws InvalidArgumentException {
+ public void testValidate_Percent()
+ throws InvalidArgumentException {
final NumberFormat format = NumberFormat.getPercentInstance();
-
- final Object[] array
- = new Object[] {
- format.format(.01),
- format.format(1.07),
- format.format(-.45),
- format.format(0.001) };
+
+ final Object[] array =
+ new Object[] {
+ format.format(.01), format.format(1.07), format.format(-.45),
+ format.format(0.001)
+ };
final List list = Arrays.asList(array);
final Validator validator = NumberValidator.getPercentInstance();
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals(0.01d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(0.00001d, ((Number)i.next()).doubleValue(), 0.0001);
+ assertEquals(0.01d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(0.00001d, ((Number) i.next()).doubleValue(), 0.0001);
assertFalse(i.hasNext());
}
- public void testValidate_Integer() throws InvalidArgumentException {
+ public void testValidate_Integer()
+ throws InvalidArgumentException {
final Object[] array = new Object[] { "1", "107", "-45" };
final List list = Arrays.asList(array);
final Validator validator = NumberValidator.getIntegerInstance();
@@ -104,23 +107,22 @@
validator.validate(list);
final Iterator i = list.iterator();
- assertEquals(1d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(107d, ((Number)i.next()).doubleValue(), 0.0001);
- assertEquals(-45d, ((Number)i.next()).doubleValue(), 0.0001);
+ assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(107d, ((Number) i.next()).doubleValue(), 0.0001);
+ assertEquals(-45d, ((Number) i.next()).doubleValue(), 0.0001);
assertFalse(i.hasNext());
}
public void testValidate_ExcessChars() {
- final Object[] array = new Object[] { "10DowningStreet"};
+ final Object[] array = new Object[] { "10DowningStreet" };
final List list = Arrays.asList(array);
final Validator validator = NumberValidator.getIntegerInstance();
- try{
+ try {
validator.validate(list);
fail("InvalidArgumentException");
- }
- catch(InvalidArgumentException e){
- assertEquals("10DowningStreet",e.getMessage());
+ } catch (InvalidArgumentException e) {
+ assertEquals("10DowningStreet", e.getMessage());
}
}
@@ -138,9 +140,9 @@
try {
validator.validate(list);
fail("107 too big");
- }
- catch (InvalidArgumentException ive) {
- assertEquals("Out of range: 107", ive.getMessage());
+ } catch (InvalidArgumentException ive) {
+ assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
+ "107"), ive.getMessage());
}
}
@@ -157,9 +159,9 @@
try {
validator.validate(list);
fail("1 too small");
- }
- catch (InvalidArgumentException ive) {
- assertEquals("Out of range: 1", ive.getMessage());
+ } catch (InvalidArgumentException ive) {
+ assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
+ "1"), ive.getMessage());
}
}
}
Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java?rev=280462&r1=280461&r2=280462&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java (original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/UrlValidatorTest.java Mon Sep 12 19:32:04 2005
@@ -17,16 +17,23 @@
import java.net.MalformedURLException;
import java.net.URL;
+
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
-public class UrlValidatorTest extends TestCase {
-
- public void testValidate() throws InvalidArgumentException, MalformedURLException {
- final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc"};
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+
+public class UrlValidatorTest
+ extends TestCase {
+ private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
+
+ public void testValidate()
+ throws InvalidArgumentException, MalformedURLException {
+ final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" };
final List list = Arrays.asList(array);
final Validator validator = new UrlValidator();
@@ -38,47 +45,47 @@
assertFalse(i.hasNext());
}
- public void testMalformedURL() throws InvalidArgumentException, MalformedURLException {
- final Object[] array = new Object[] { "www.apache.org"};
+ public void testMalformedURL()
+ throws InvalidArgumentException, MalformedURLException {
+ final Object[] array = new Object[] { "www.apache.org" };
final List list = Arrays.asList(array);
final Validator validator = new UrlValidator();
try {
validator.validate(list);
+ } catch (InvalidArgumentException e) {
+ assertEquals(resources.getMessage(ResourceConstants.URLVALIDATOR_MALFORMED_URL,
+ new Object[] { "www.apache.org" }), e.getMessage());
}
- catch(InvalidArgumentException e){
- assertEquals("Cannot understand url: www.apache.org",e.getMessage());
- }
-
}
public void testBadProtocol() {
{
- final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc"};
+ final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" };
final List list = Arrays.asList(array);
final UrlValidator validator = new UrlValidator();
validator.setProtocol("http");
-
+
assertEquals("incorrect protocol", "http", validator.getProtocol());
- try{
+
+ try {
validator.validate(list);
fail("Expected InvalidArgumentException");
- }
- catch(InvalidArgumentException e){
- assertEquals("file:///etc",e.getMessage());
+ } catch (InvalidArgumentException e) {
+ assertEquals("file:///etc", e.getMessage());
}
}
+
{
- final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc"};
+ final Object[] array = new Object[] { "http://www.apache.org/", "file:///etc" };
final List list = Arrays.asList(array);
final UrlValidator validator = new UrlValidator("http");
-
- try{
+
+ try {
validator.validate(list);
fail("Expected InvalidArgumentException");
- }
- catch(InvalidArgumentException e){
- assertEquals("file:///etc",e.getMessage());
+ } catch (InvalidArgumentException e) {
+ assertEquals("file:///etc", e.getMessage());
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org