[Poem-commit] SF.net SVN: poem: [16] trunk/poem/src
Status: Planning
Brought to you by:
maledee
|
From: <poe...@li...> - 2008-02-20 15:16:13
|
Revision: 16
http://poem.svn.sourceforge.net/poem/?rev=16&view=rev
Author: rsinnema
Date: 2008-02-20 07:16:18 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
Create a poem from the command line
Modified Paths:
--------------
trunk/poem/src/fit/html/create-poem.html
trunk/poem/src/fit/java/net/sf/poem/fit/cli/CommandLineFixture.java
trunk/poem/src/main/java/net/sf/poem/cli/Command.java
trunk/poem/src/main/java/net/sf/poem/cli/CreateCommand.java
trunk/poem/src/main/java/net/sf/poem/cli/UsageCommand.java
trunk/poem/src/main/java/net/sf/poem/util/FileUtil.java
Added Paths:
-----------
trunk/poem/src/main/java/net/sf/poem/cli/PoemCommandLine.java
trunk/poem/src/test/java/net/sf/poem/cli/
trunk/poem/src/test/java/net/sf/poem/cli/test/
trunk/poem/src/test/java/net/sf/poem/cli/test/AbstractCommandTestCase.java
trunk/poem/src/test/java/net/sf/poem/cli/test/CreateCommandTest.java
trunk/poem/src/test/java/net/sf/poem/cli/test/PoemCommandLineTest.java
trunk/poem/src/test/java/net/sf/poem/cli/test/UsageCommandTest.java
trunk/poem/src/test/java/net/sf/poem/cli/test/package.html
Removed Paths:
-------------
trunk/poem/src/main/java/net/sf/poem/cli/PoemApplication.java
Modified: trunk/poem/src/fit/html/create-poem.html
===================================================================
--- trunk/poem/src/fit/html/create-poem.html 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/fit/html/create-poem.html 2008-02-20 15:16:18 UTC (rev 16)
@@ -54,7 +54,7 @@
</tr>
<tr>
<td>c</td>
- <td>--type=sonnet --language=nl_NL --title="De moeder de vrouw"</td>
+ <td>--type=sonnet --language=nl_NL "--title=De moeder de vrouw"</td>
<td>de-moeder-de-vrouw.xml</td>
<td><?xml version="1.0"?><poem type="sonnet" language="nl_NL"><title>De moeder de vrouw</title><paragraph><line></line></paragraph></poem></td>
</tr>
Modified: trunk/poem/src/fit/java/net/sf/poem/fit/cli/CommandLineFixture.java
===================================================================
--- trunk/poem/src/fit/java/net/sf/poem/fit/cli/CommandLineFixture.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/fit/java/net/sf/poem/fit/cli/CommandLineFixture.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -21,7 +21,7 @@
import java.util.Arrays;
import java.util.List;
-import net.sf.poem.cli.PoemApplication;
+import net.sf.poem.cli.PoemCommandLine;
import net.sf.poem.util.FileUtil;
import net.sf.poem.util.XmlUtil;
import fit.ColumnFixture;
@@ -36,30 +36,33 @@
// stop visibilitymodifier check
public String command;
public String options;
-
// resume visibilitymodifier check
+ private File file;
+
public String fileName() {
- return getFile().getName();
+ return getFile(false).getName();
}
public String fileContents() throws IOException {
- return XmlUtil.normalizeWhitespace(FileUtil.getContents(getFile()));
+ return XmlUtil.normalizeWhitespace(FileUtil.getContents(getFile(true)));
}
- private File getFile() {
- final List<File> beforeFiles = Arrays.asList(new File(".").listFiles());
- PoemApplication.main(getCommandLine());
- final File[] afterFiles = new File(".").listFiles();
+ private File getFile(final boolean cached) {
+ if (!cached) {
+ final List<File> beforeFiles = Arrays.asList(new File(".").listFiles());
+ PoemCommandLine.main(getCommandLine());
- File result = new File(".");
- for (int i = 0; i < afterFiles.length; i++) {
- if (!beforeFiles.contains(afterFiles[i])) {
- result = afterFiles[i];
- break;
+ file = new File(".");
+ for (final File afterFile : new File(".").listFiles()) {
+ if (!beforeFiles.contains(afterFile)) {
+ file = afterFile;
+ break;
+ }
}
+ file.deleteOnExit();
}
- return result;
+ return file;
}
private String[] getCommandLine() {
@@ -76,12 +79,21 @@
if (options.charAt(i) == '\"') {
inQuote = true;
} else if (options.charAt(i) == ' ') {
- result.add(options.substring(start, i).trim());
+ result.add(getOption(start, i));
start = i + 1;
}
}
}
+ result.add(getOption(start, options.length()));
return result.toArray(new String[result.size()]);
}
+ private String getOption(final int start, final int end) {
+ String result = options.substring(start, end).trim();
+ if (result.startsWith("\"") && result.endsWith("\"")) {
+ result = result.substring(1, result.length() - 1).trim();
+ }
+ return result;
+ }
+
}
Modified: trunk/poem/src/main/java/net/sf/poem/cli/Command.java
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/cli/Command.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/main/java/net/sf/poem/cli/Command.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -21,6 +21,9 @@
*/
public interface Command {
+ String OPTION_PREFIX = "--";
+ String HELP_OPTION = OPTION_PREFIX + "help";
+
/**
* Perform the command.
* @param args The command line arguments. The first argument indicates
@@ -28,4 +31,9 @@
*/
void perform(String[] args);
+ /**
+ * @return A description on how to use the command
+ */
+ String getUsage();
+
}
Modified: trunk/poem/src/main/java/net/sf/poem/cli/CreateCommand.java
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/cli/CreateCommand.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/main/java/net/sf/poem/cli/CreateCommand.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -16,20 +16,76 @@
package net.sf.poem.cli;
import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import net.sf.poem.api.Poem;
+import net.sf.poem.api.PoemFactory;
+
/**
* Create a poem.
*/
public class CreateCommand implements Command {
+ private static final String OPTION_TITLE = "title";
+ private static final String OPTION_TYPE = "type";
+ private static final String OPTION_LANGUAGE = "language";
+
+ private final PrintStream out;
+ private final Map<String, String> validOptions;
+
public CreateCommand(final PrintStream out) {
- // TODO Auto-generated constructor stub
+ this.out = out;
+
+ validOptions = new LinkedHashMap<String, String>();
+ validOptions.put(OPTION_LANGUAGE, "the poem's language in ISO format, e.g. 'en_UK'");
+ validOptions.put(OPTION_TYPE, "the kind of poem, e.g. 'sonnet'");
+ validOptions.put(OPTION_TITLE, "the poem's title");
}
public void perform(final String[] args) {
- // TODO Auto-generated method stub
+ try {
+ final Map<String, String> options = getOptions(args);
+ final Poem poem = PoemFactory.newInstance(options.get(OPTION_LANGUAGE),
+ options.get(OPTION_TYPE), options.get(OPTION_TITLE));
+ out.println("Created poem '" + poem.getFile().getName() + "'");
+ } catch (final Exception e) {
+ out.println(e.getMessage());
+ }
+ }
+ private Map<String, String> getOptions(final String[] args) {
+ final Map<String, String> result = new HashMap<String, String>();
+ for (int i = 1; i < args.length; i++) {
+ if (HELP_OPTION.equals(args[i])) {
+ throw new IllegalArgumentException(getUsage());
+ }
+ final String[] nameValue = args[i].split("=");
+ if (nameValue.length != 2 || !nameValue[0].startsWith(OPTION_PREFIX)) {
+ throw new IllegalArgumentException("Invalid option: '" + args[i]
+ + "'. Options look like '--<option>=<value>'.");
+ }
+ final String option = nameValue[0].substring(OPTION_PREFIX.length());
+ if (!validOptions.containsKey(option)) {
+ throw new UnsupportedOperationException("Unsupported option: '" + option
+ + "'. Use '--help' for a list of supported options.");
+ }
+ result.put(option, nameValue[1]);
+ }
+ return result;
}
+ public String getUsage() {
+ final StringBuffer result = new StringBuffer();
+ result.append("Supported options:\n");
+ for (final Entry<String, String> entry : validOptions.entrySet()) {
+ result.append(OPTION_PREFIX).append(entry.getKey()).append(": ");
+ result.append(entry.getValue()).append('\n');
+ }
+ return result.toString();
+ }
+
}
Deleted: trunk/poem/src/main/java/net/sf/poem/cli/PoemApplication.java
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/cli/PoemApplication.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/main/java/net/sf/poem/cli/PoemApplication.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -1,49 +0,0 @@
-// Copyright (C) 2008 Remon Sinnema
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package net.sf.poem.cli;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * The main program.
- */
-public class PoemApplication {
-
- /**
- * @param args The command line arguments
- */
- public static void main(final String[] args) {
- new PoemApplication().run(args);
- }
-
- private final Map<String, Command> commands = new HashMap<String, Command>();
-
- public PoemApplication() {
- commands.put("c", new CreateCommand(System.out));
- }
-
- public void run(final String[] args) {
- getCommand(args[0]).perform(args);
- }
-
- private Command getCommand(final String command) {
- return commands.containsKey(command) ? commands.get(command)
- : new UsageCommand(System.err, commands);
- }
-
-}
Copied: trunk/poem/src/main/java/net/sf/poem/cli/PoemCommandLine.java (from rev 15, trunk/poem/src/main/java/net/sf/poem/cli/PoemApplication.java)
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/cli/PoemCommandLine.java (rev 0)
+++ trunk/poem/src/main/java/net/sf/poem/cli/PoemCommandLine.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,53 @@
+// Copyright (C) 2008 Remon Sinnema
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package net.sf.poem.cli;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * The main command line program.
+ */
+public class PoemCommandLine {
+
+ /**
+ * @param args The command line arguments
+ */
+ public static void main(final String[] args) {
+ new PoemCommandLine().run(args);
+ }
+
+ private final Map<String, Command> commands = new HashMap<String, Command>();
+
+ public PoemCommandLine() {
+ addCommand("c", new CreateCommand(System.out));
+ }
+
+ protected final void addCommand(final String identifier, final Command command) {
+ commands.put(identifier, command);
+ }
+
+ public final void run(final String[] args) {
+ getCommand(args[0]).perform(args);
+ }
+
+ private Command getCommand(final String command) {
+ return commands.containsKey(command) ? commands.get(command)
+ : new UsageCommand(System.err, commands);
+ }
+
+}
Modified: trunk/poem/src/main/java/net/sf/poem/cli/UsageCommand.java
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/cli/UsageCommand.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/main/java/net/sf/poem/cli/UsageCommand.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -17,6 +17,7 @@
import java.io.PrintStream;
import java.util.Map;
+import java.util.Map.Entry;
/**
@@ -24,10 +25,34 @@
*/
public class UsageCommand implements Command {
+ private final PrintStream out;
+ private final Map<String, Command> commands;
+
public UsageCommand(final PrintStream out, final Map<String, Command> commands) {
+ this.out = out;
+ this.commands = commands;
}
public void perform(final String[] args) {
+ if (!HELP_OPTION.equals(args[0])) {
+ out.print("Unsupported command '");
+ out.print(args[0]);
+ out.println("'.");
+ out.println("Usage: poem <command> [<options>]");
+ }
+
+ out.println("Supported commands:");
+ for (final Entry<String, Command> entry : commands.entrySet()) {
+ out.print(entry.getKey());
+ out.print(": ");
+ out.println(entry.getValue().getUsage());
+ }
+
+ out.println("poem <command> --help gives help on command <command>");
}
+ public String getUsage() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/poem/src/main/java/net/sf/poem/util/FileUtil.java
===================================================================
--- trunk/poem/src/main/java/net/sf/poem/util/FileUtil.java 2008-02-19 21:22:54 UTC (rev 15)
+++ trunk/poem/src/main/java/net/sf/poem/util/FileUtil.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
@@ -42,8 +43,14 @@
public static String getContents(final File file) throws IOException {
+ return getContents(new FileInputStream(file));
+ }
+
+
+ public static String getContents(final InputStream inputStream)
+ throws IOException {
final StringBuffer result = new StringBuffer();
- final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
result.append(line).append('\n');
}
Added: trunk/poem/src/test/java/net/sf/poem/cli/test/AbstractCommandTestCase.java
===================================================================
--- trunk/poem/src/test/java/net/sf/poem/cli/test/AbstractCommandTestCase.java (rev 0)
+++ trunk/poem/src/test/java/net/sf/poem/cli/test/AbstractCommandTestCase.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,43 @@
+// Copyright (C) 2008 Remon Sinnema
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package net.sf.poem.cli.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+import net.sf.poem.util.FileUtil;
+
+
+/**
+ * Abstract test case for testing commands.
+ */
+public abstract class AbstractCommandTestCase extends TestCase {
+
+ private ByteArrayOutputStream baos;
+
+ protected PrintStream newCommandStream() {
+ baos = new ByteArrayOutputStream();
+ return new PrintStream(baos);
+ }
+
+ protected String getCommandOutput() throws IOException {
+ return FileUtil.getContents(new ByteArrayInputStream(baos.toByteArray()));
+ }
+
+}
Added: trunk/poem/src/test/java/net/sf/poem/cli/test/CreateCommandTest.java
===================================================================
--- trunk/poem/src/test/java/net/sf/poem/cli/test/CreateCommandTest.java (rev 0)
+++ trunk/poem/src/test/java/net/sf/poem/cli/test/CreateCommandTest.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,94 @@
+// Copyright (C) 2008 Remon Sinnema
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package net.sf.poem.cli.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.poem.cli.CreateCommand;
+import net.sf.poem.util.FileUtil;
+
+
+/**
+ * Test for {@see CreateCommand}.
+ */
+public class CreateCommandTest extends AbstractCommandTestCase {
+
+ private List<File> beforeFiles;
+
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ beforeFiles = Arrays.asList(getCurrentDirFiles());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ final File[] afterFiles = getCurrentDirFiles();
+ for (final File file : afterFiles) {
+ if (!beforeFiles.contains(file)) {
+ FileUtil.delete(file);
+ }
+ }
+ }
+
+ public void testPerform() throws IOException {
+ final File poem = new File("ape.xml");
+ if (poem.exists()) {
+ poem.delete();
+ }
+
+ newCreateCommand().perform(new String[] {"c",
+ "--type=sonnet", "--title=ape", "--language=foo_Bar"});
+ assertTrue("poem not created", poem.exists());
+ assertEquals("output", "Created poem 'ape.xml'\n", getCommandOutput());
+ }
+
+ public void testIllegalOption() throws IOException {
+ newCreateCommand().perform(new String[]{"c", "bear"});
+ assertEquals("bear", "Invalid option: 'bear'. Options look like '--<option>=<value>'.\n",
+ getCommandOutput());
+
+ newCreateCommand().perform(new String[]{"c", "cheetah=dingo"});
+ assertEquals("cheetah=dingo", "Invalid option: 'cheetah=dingo'. Options look like '--<option>=<value>'.\n",
+ getCommandOutput());
+
+ newCreateCommand().perform(new String[]{"c", "--elephant=fox"});
+ assertEquals("--elephant=fox", "Unsupported option: 'elephant'. Use '--help' for a list of supported options.\n",
+ getCommandOutput());
+ }
+
+ public void testHelp() throws IOException {
+ newCreateCommand().perform(new String[]{"c", "--help"});
+ assertEquals("help", "Supported options:\n"
+ + "--language: the poem's language in ISO format, e.g. 'en_UK'\n"
+ + "--type: the kind of poem, e.g. 'sonnet'\n"
+ + "--title: the poem's title\n\n", getCommandOutput());
+ }
+
+ private CreateCommand newCreateCommand() {
+ return new CreateCommand(newCommandStream());
+ }
+
+ private File[] getCurrentDirFiles() {
+ return new File(".").listFiles();
+ }
+
+}
Added: trunk/poem/src/test/java/net/sf/poem/cli/test/PoemCommandLineTest.java
===================================================================
--- trunk/poem/src/test/java/net/sf/poem/cli/test/PoemCommandLineTest.java (rev 0)
+++ trunk/poem/src/test/java/net/sf/poem/cli/test/PoemCommandLineTest.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,62 @@
+// Copyright (C) 2008 Remon Sinnema
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package net.sf.poem.cli.test;
+
+import junit.framework.TestCase;
+import net.sf.poem.cli.Command;
+import net.sf.poem.cli.PoemCommandLine;
+
+
+/**
+ * Test for the command line program.
+ */
+public class PoemCommandLineTest extends TestCase {
+
+ /**
+ * Mock command to test whether the command pattern is correctly implemented.
+ */
+ public class MockCommand implements Command {
+ public void perform(final String[] args) {
+ performArgs = args;
+ }
+
+ public String getUsage() {
+ return null;
+ }
+ }
+
+
+ /**
+ *
+ */
+ public class TestPoemCommandLine extends PoemCommandLine {
+
+ public TestPoemCommandLine() {
+ super();
+ addCommand("mock", new MockCommand());
+ }
+ }
+
+
+ private String[] performArgs;
+
+ public void testCommandPattern() {
+ final String[] args = new String[] {"mock", "me", "not"};
+ new TestPoemCommandLine().run(args);
+ assertSame("Command line", args, performArgs);
+ }
+
+}
Added: trunk/poem/src/test/java/net/sf/poem/cli/test/UsageCommandTest.java
===================================================================
--- trunk/poem/src/test/java/net/sf/poem/cli/test/UsageCommandTest.java (rev 0)
+++ trunk/poem/src/test/java/net/sf/poem/cli/test/UsageCommandTest.java 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,83 @@
+// Copyright (C) 2008 Remon Sinnema
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package net.sf.poem.cli.test;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import net.sf.poem.cli.Command;
+import net.sf.poem.cli.UsageCommand;
+
+
+
+/**
+ * Test usage help.
+ */
+public class UsageCommandTest extends AbstractCommandTestCase {
+
+ /**
+ * Mock command to test the usage command.
+ */
+ public class MockCommand implements Command {
+
+ private final String usage;
+
+ public MockCommand(final String usage) {
+ this.usage = usage;
+ }
+
+ public void perform(final String[] args) {
+ }
+
+ public String getUsage() {
+ return usage;
+ }
+
+ }
+
+
+ public void testUnsupportedCommand() throws IOException {
+ new UsageCommand(newCommandStream(), getCommands()).perform(new String[] {"q"});
+
+ assertEquals("output", "Unsupported command 'q'.\n"
+ + "Usage: poem <command> [<options>]\n"
+ + "Supported commands:\n"
+ + "m: Do something\n"
+ + "n: Do something else\n"
+ + "poem <command> --help gives help on command <command>\n",
+ getCommandOutput());
+ }
+
+
+ public void testHelp() throws IOException {
+ new UsageCommand(newCommandStream(), getCommands()).perform(new String[] {"--help"});
+
+ assertEquals("output", "Supported commands:\n"
+ + "m: Do something\n"
+ + "n: Do something else\n"
+ + "poem <command> --help gives help on command <command>\n",
+ getCommandOutput());
+ }
+
+ private Map<String, Command> getCommands() {
+ final Map<String, Command> commands = new LinkedHashMap<String, Command>();
+ commands.put("m", new MockCommand("Do something"));
+ commands.put("n", new MockCommand("Do something else"));
+ return commands;
+ }
+
+}
Added: trunk/poem/src/test/java/net/sf/poem/cli/test/package.html
===================================================================
--- trunk/poem/src/test/java/net/sf/poem/cli/test/package.html (rev 0)
+++ trunk/poem/src/test/java/net/sf/poem/cli/test/package.html 2008-02-20 15:16:18 UTC (rev 16)
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ These are the <a href="http://junit.org">unit tests</a> for the command line client.
+ </body>
+</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|