Adding javadoc and code compliance
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -41,7 +41,6 @@ package fr.bigeon.gclc;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -74,8 +73,8 @@ public class ConsoleApplicationTest {
|
||||
public void testConsoleApplication() {
|
||||
|
||||
try (PipedConsoleInput manager = new PipedConsoleInput()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(null,
|
||||
manager, "", "");
|
||||
final ConsoleApplication app = new ConsoleApplication(null, manager,
|
||||
"", "");
|
||||
app.exit();
|
||||
} catch (final IOException e) {
|
||||
fail("System Console Manager failed");
|
||||
@@ -84,26 +83,32 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecution() {
|
||||
public void testExecution() throws IOException, InterruptedException,
|
||||
InvalidCommandName {
|
||||
try (CommandTestingApplication application = new CommandTestingApplication()) {
|
||||
|
||||
// remove welcome
|
||||
assertEquals(application.getApplication().header,
|
||||
assertEquals("Header should be preserved",
|
||||
application.getApplication().header,
|
||||
application.readNextLine());
|
||||
// Remove first prompt
|
||||
application.sendCommand("");
|
||||
application.sendCommand("test");
|
||||
assertEquals("Test command ran fine", application.readNextLine());
|
||||
assertEquals("Test should run", "Test command ran fine",
|
||||
application.readNextLine());
|
||||
application.sendCommand("toto");
|
||||
assertEquals(
|
||||
assertEquals("Command fail should dispaly appropriate message",
|
||||
Messages.getString("ConsoleApplication.cmd.failed", "toto"),
|
||||
application.readNextLine());
|
||||
assertEquals(
|
||||
"Unrecognized comment should result in a specific message.",
|
||||
Messages.getString("CommandProvider.unrecognized", "toto"),
|
||||
application.readNextLine());
|
||||
application.sendCommand("long");
|
||||
assertEquals("Waita minute", application.readNextLine());
|
||||
assertEquals("done!", application.readNextLine());
|
||||
assertEquals("Before wait should receive message", "Waita minute",
|
||||
application.readNextLine());
|
||||
assertEquals("Unexpected message", "done!",
|
||||
application.readNextLine());
|
||||
|
||||
final CommandRequestListener crl = new CommandRequestListener() {
|
||||
|
||||
@@ -122,27 +127,28 @@ public class ConsoleApplicationTest {
|
||||
application.getApplication().addListener(crl);
|
||||
application.getApplication().addListener(crl2);
|
||||
application.sendCommand("test");
|
||||
assertEquals("Test command ran fine", application.readNextLine());
|
||||
assertEquals("Unexpected message", "Test command ran fine",
|
||||
application.readNextLine());
|
||||
application.getApplication().removeListener(crl2);
|
||||
application.getApplication().removeListener(crl);
|
||||
application.getApplication().removeListener(crl);
|
||||
|
||||
assertTrue(application.getApplication().isRunning());
|
||||
assertTrue("Unclosed application should be running",
|
||||
application.getApplication().isRunning());
|
||||
|
||||
application.sendCommand("exit");
|
||||
assertEquals(application.getApplication().footer,
|
||||
assertEquals("Footer should be preserved",
|
||||
application.getApplication().footer,
|
||||
application.readNextLine());
|
||||
assertFalse(application.getApplication().isRunning());
|
||||
} catch (final IOException e1) {
|
||||
assertNull(e1);
|
||||
assertFalse("Stopped application should not be running",
|
||||
application.getApplication().isRunning());
|
||||
}
|
||||
|
||||
ConsoleApplication appli = null;
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput();
|
||||
PipedConsoleInput in = new PipedConsoleInput()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(manager,
|
||||
in, null,
|
||||
null);
|
||||
final ConsoleApplication app = new ConsoleApplication(manager, in,
|
||||
null, null);
|
||||
appli = app;
|
||||
app.add(new ExitCommand("exit", app));
|
||||
|
||||
@@ -154,83 +160,72 @@ public class ConsoleApplicationTest {
|
||||
app.start();
|
||||
}
|
||||
});
|
||||
|
||||
th.start();
|
||||
|
||||
in.type("exit");
|
||||
th.join();
|
||||
|
||||
} catch (IOException | InvalidCommandName |
|
||||
|
||||
InterruptedException e) {
|
||||
|
||||
assertNull(e);
|
||||
}
|
||||
|
||||
assertNotNull(appli);
|
||||
assertNotNull(
|
||||
"Application should still exist even if the console input and output are closed.",
|
||||
appli);
|
||||
appli.start();
|
||||
assertFalse(appli.isRunning());
|
||||
assertFalse(
|
||||
"Application should not start on closed console input and output",
|
||||
appli.isRunning());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterpretCommand() {
|
||||
public void testInterpretCommand() throws InvalidCommandName, IOException {
|
||||
try (PipedConsoleInput test = new PipedConsoleInput();
|
||||
PipedConsoleOutput out = new PipedConsoleOutput()) {
|
||||
final ConsoleApplication appl = new ConsoleApplication(out, test,
|
||||
"", "");
|
||||
|
||||
appl.interpretCommand("invalid cmd \"due to misplaced\"quote");
|
||||
assertEquals("Command line cannot be parsed", out.readNextLine());
|
||||
assertEquals("Specific error message expected",
|
||||
"Command line cannot be parsed", out.readNextLine());
|
||||
|
||||
appl.interpretCommand("");
|
||||
|
||||
final String message = "message";
|
||||
try {
|
||||
appl.add(new ICommand() {
|
||||
appl.add(new ICommand() {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see
|
||||
* fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput,
|
||||
* fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException(
|
||||
CommandRunExceptionType.USAGE, message, this);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
message, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "fail";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "fail";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(final ConsoleOutput manager,
|
||||
final String... args) throws IOException {
|
||||
manager.println(message);
|
||||
}
|
||||
@Override
|
||||
public void help(final ConsoleOutput manager,
|
||||
final String... args) throws IOException {
|
||||
manager.println(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
assertNull(e);
|
||||
}
|
||||
});
|
||||
appl.interpretCommand("fail");
|
||||
assertEquals(
|
||||
assertEquals("Unexpected message",
|
||||
Messages.getString("ConsoleApplication.cmd.failed", "fail"),
|
||||
out.readNextLine());
|
||||
assertEquals(message, out.readNextLine());
|
||||
assertEquals(message, out.readNextLine());
|
||||
assertEquals("Unexpected message", message, out.readNextLine());
|
||||
assertEquals("Unexpected message", message, out.readNextLine());
|
||||
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
*/
|
||||
package fr.bigeon.gclc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -53,102 +54,74 @@ import fr.bigeon.gclc.exception.CommandParsingException;
|
||||
@SuppressWarnings({"nls", "static-method"})
|
||||
public class GCLCConstantsTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
||||
*/
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
||||
*
|
||||
* @throws CommandParsingException if an error occured */
|
||||
@Test
|
||||
public void testSplitCommand() {
|
||||
public void testSplitCommand() throws CommandParsingException {
|
||||
List<String> res;
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse simple command " + e.getLocalizedMessage()); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 1);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
res = GCLCConstants.splitCommand("aCommand");
|
||||
assertTrue("single word command should have one element",
|
||||
res.size() == 1);
|
||||
assertTrue("Command should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
assertEquals("Command size", 4, res.size());
|
||||
assertEquals("Elements should be preserved", "aCommand", res.get(0));
|
||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(3).equals("arguments"));
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
assertEquals("Command size", 4, res.size());
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(3).equals("arguments"));
|
||||
res = GCLCConstants.splitCommand("aCommand \"with some\" arguments");
|
||||
assertEquals("Command size", 3, res.size());
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(1).equals("with some"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(2).equals("arguments"));
|
||||
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
||||
assertEquals("Command size", 3, res.size());
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(1).equals("with some"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(2).equals("arguments"));
|
||||
res = GCLCConstants.splitCommand("aCommand wi\\\"th some arguments");
|
||||
assertEquals("Command size", 4, res.size());
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
assertTrue("Elements should be preserved", res.get(1).equals("wi\"th"));
|
||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(3).equals("arguments"));
|
||||
|
||||
res = GCLCConstants.splitCommand("aCommand with \"some arguments\"");
|
||||
assertEquals("Command size", 3, res.size());
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(0).equals("aCommand"));
|
||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||
assertTrue("Elements should be preserved",
|
||||
res.get(2).equals("some arguments"));
|
||||
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 4);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("with"));
|
||||
assertTrue(res.get(2).equals("some"));
|
||||
assertTrue(res.get(3).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments and double whitspaces " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 4);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("with"));
|
||||
assertTrue(res.get(2).equals("some"));
|
||||
assertTrue(res.get(3).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand \"with some\" arguments");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 3);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("with some"));
|
||||
assertTrue(res.get(2).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments with escaped whitspaces " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 3);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("with some"));
|
||||
assertTrue(res.get(2).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand wi\\\"th some arguments");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 4);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("wi\"th"));
|
||||
assertTrue(res.get(2).equals("some"));
|
||||
assertTrue(res.get(3).equals("arguments"));
|
||||
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand with \"some arguments\"");
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command ending with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
assertTrue(res.size() == 3);
|
||||
assertTrue(res.get(0).equals("aCommand"));
|
||||
assertTrue(res.get(1).equals("with"));
|
||||
assertTrue(res.get(2).equals("some arguments"));
|
||||
|
||||
// Wrong lines?
|
||||
try {
|
||||
// Wrong lines?
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand with \"some ar\"guments");
|
||||
fail("Parsing argument with string cut");
|
||||
fail("Misplaced quotes should fail");
|
||||
} catch (final CommandParsingException e) {
|
||||
// OK
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -52,7 +51,8 @@ import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandParsingException;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@@ -60,66 +60,63 @@ import fr.bigeon.gclc.exception.CommandParsingException;
|
||||
public class CommandParametersTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#CommandParameters(java.util.Set, java.util.Set, boolean)}. */
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#CommandParameters(java.util.Set, java.util.Set, boolean)}.
|
||||
*
|
||||
* @throws CommandParsingException if an unexpected exception is thrown */
|
||||
@Test
|
||||
public final void testCommandParameters() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
public final void testCommandParameters() throws CommandParsingException {
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
CommandParameters parameters = new CommandParameters(bools, strings,
|
||||
true);
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungivenFlag");
|
||||
fail("parse of unknown in strict should fail");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
parameters = new CommandParameters(bools, strings, false);
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungivenFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
fail("parse of unknown in non strict should suceed");
|
||||
assertNull(e);
|
||||
}
|
||||
parameters.parseArgs("-ungivenFlag");
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#get(java.lang.String)}. */
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#get(java.lang.String)}.
|
||||
*
|
||||
* @throws CommandParsingException if an exception occired */
|
||||
@Test
|
||||
public final void testGet() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
public final void testGet() throws CommandParsingException {
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
|
||||
CommandParameters parameters = new CommandParameters(bools, strings,
|
||||
true);
|
||||
final CommandParameters parameters = new CommandParameters(bools,
|
||||
strings, true);
|
||||
|
||||
assertNull(parameters.get("ungiven"));
|
||||
assertNull(parameters.get("str"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven", "val");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
fail("Missing parameter should fail for strict element");
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertNull(parameters.get("ungiven"));
|
||||
assertNull(parameters.get("str"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-str", "val");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
parameters.parseArgs("-str", "val");
|
||||
assertNull(parameters.get("ungiven"));
|
||||
assertEquals("val", parameters.get("str"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
fail("Invalid argument type parsing should fail");
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertNull(parameters.get("ungiven"));
|
||||
assertEquals("val", parameters.get("str"));
|
||||
@@ -128,9 +125,9 @@ public class CommandParametersTest {
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#getAdditionals()}. */
|
||||
@Test
|
||||
public final void testGetAdditionals() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
public final void testGetAdditionals() throws CommandParsingException {
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
@@ -138,44 +135,35 @@ public class CommandParametersTest {
|
||||
CommandParameters parameters = new CommandParameters(bools, strings,
|
||||
true);
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
parameters.parseArgs("-boolFlag");
|
||||
assertTrue(parameters.getAdditionals().isEmpty());
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
fail("Should fail");
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertTrue(parameters.getAdditionals().isEmpty());
|
||||
|
||||
parameters = new CommandParameters(bools, strings, false);
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
parameters.parseArgs("-boolFlag");
|
||||
assertTrue(parameters.getAdditionals().isEmpty());
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
parameters.parseArgs("-ungiven");
|
||||
assertTrue(parameters.getAdditionals().contains("ungiven"));
|
||||
assertEquals(1, parameters.getAdditionals().size());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#getBool(java.lang.String)}. */
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#getBool(java.lang.String)}.
|
||||
*
|
||||
* @throws CommandParsingException */
|
||||
@Test
|
||||
public final void testGetBool() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
public final void testGetBool() throws CommandParsingException {
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
@@ -186,19 +174,15 @@ public class CommandParametersTest {
|
||||
assertFalse(parameters.getBool("ungiven"));
|
||||
assertFalse(parameters.getBool("boolFlag"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
parameters.parseArgs("-boolFlag");
|
||||
assertTrue(parameters.getBool("boolFlag"));
|
||||
assertFalse(parameters.getBool("ungiven"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven");
|
||||
fail("unknown parameter should fail");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertFalse(parameters.getBool("ungiven"));
|
||||
assertTrue(parameters.getBool("boolFlag"));
|
||||
@@ -210,70 +194,59 @@ public class CommandParametersTest {
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertTrue(parameters.getBool("boolFlag"));
|
||||
assertFalse(parameters.getBool("ungiven"));
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungiven");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
assertFalse(parameters.getBool("ungiven"));
|
||||
assertTrue(parameters.getBool("boolFlag"));
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#parseArgs(java.lang.String[])}. */
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#parseArgs(java.lang.String[])}.
|
||||
*
|
||||
* @throws CommandParsingException */
|
||||
@Test
|
||||
public final void testParseArgs() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
public final void testParseArgs() throws CommandParsingException {
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
|
||||
CommandParameters parameters = new CommandParameters(bools, strings,
|
||||
true);
|
||||
final CommandParameters parameters = new CommandParameters(bools,
|
||||
strings, true);
|
||||
|
||||
try {
|
||||
parameters.parseArgs("-ungivenFlag");
|
||||
fail("unknown argument should fail in strict");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
fail("Strict should fail with flag");
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
parameters.parseArgs("-str");
|
||||
fail("missing string argument value should fail");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNotNull(e);
|
||||
fail("String argument without second element should fail");
|
||||
} catch (final CommandParsingException e) {
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
try {
|
||||
parameters.parseArgs("-str", "-boolFlag");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
try {
|
||||
parameters.parseArgs("-boolFlag", "-str", "val");
|
||||
} catch (CommandParsingException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
|
||||
parameters.parseArgs("-boolFlag");
|
||||
parameters.parseArgs("-str", "-boolFlag");
|
||||
parameters.parseArgs("-boolFlag", "-str", "val");
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#set(java.lang.String, boolean)}. */
|
||||
@Test
|
||||
public final void testSetStringBoolean() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
@@ -310,8 +283,8 @@ public class CommandParametersTest {
|
||||
* {@link fr.bigeon.gclc.command.CommandParameters#set(java.lang.String, java.lang.String)}. */
|
||||
@Test
|
||||
public final void testSetStringString() {
|
||||
Set<String> strings = new HashSet<>();
|
||||
Set<String> bools = new HashSet<>();
|
||||
final Set<String> strings = new HashSet<>();
|
||||
final Set<String> bools = new HashSet<>();
|
||||
|
||||
bools.add("boolFlag");
|
||||
strings.add("str");
|
||||
|
||||
@@ -38,68 +38,61 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class CommandProviderTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.CommandProvider#add(fr.bigeon.gclc.command.ICommand)}. */
|
||||
* {@link fr.bigeon.gclc.command.CommandProvider#add(fr.bigeon.gclc.command.ICommand)}.
|
||||
*
|
||||
* @throws InvalidCommandName */
|
||||
@Test
|
||||
public final void testAdd() {
|
||||
CommandProvider provider = new CommandProvider();
|
||||
public final void testAdd() throws InvalidCommandName {
|
||||
final CommandProvider provider = new CommandProvider();
|
||||
try {
|
||||
provider.add(new MockCommand(null));
|
||||
fail("null name for command should be rejected");
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
} catch (final InvalidCommandName e) {
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
provider.add(new MockCommand(""));
|
||||
fail("null name for command should be rejected");
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
} catch (final InvalidCommandName e) {
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
provider.add(new MockCommand("-name"));
|
||||
fail("name with minus as starting character for command should be rejected");
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
} catch (final InvalidCommandName e) {
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
provider.add(new MockCommand("name command"));
|
||||
fail("name with space for command should be rejected");
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
ICommand mock = new MockCommand("name");
|
||||
try {
|
||||
provider.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNull(e);
|
||||
} catch (final InvalidCommandName e) {
|
||||
// ok
|
||||
}
|
||||
final ICommand mock = new MockCommand("name");
|
||||
provider.add(mock);
|
||||
|
||||
try {
|
||||
provider.add(new MockCommand(mock.getCommandName()));
|
||||
fail("already existing command name should be rejected");
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
} catch (final InvalidCommandName e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
try {
|
||||
provider.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
provider.add(mock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -56,7 +54,7 @@ import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
public class CommandTest {
|
||||
|
||||
@Test
|
||||
public final void testCommand() {
|
||||
public final void testCommand() throws IOException {
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
Command cmd;
|
||||
cmd = new Command("name") {
|
||||
@@ -248,8 +246,6 @@ public class CommandTest {
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -59,44 +57,41 @@ import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
public class HelpExecutorTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.HelpExecutor#execute(java.lang.String[])}. */
|
||||
* {@link fr.bigeon.gclc.command.HelpExecutor#execute(java.lang.String[])}.
|
||||
*
|
||||
* @throws CommandRunException
|
||||
* @throws IOException */
|
||||
@Test
|
||||
public final void testExecute() {
|
||||
try {
|
||||
final PipedConsoleOutput test = new PipedConsoleOutput();
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new Command("mock") {
|
||||
public final void testExecute() throws CommandRunException, IOException {
|
||||
final PipedConsoleOutput test = new PipedConsoleOutput();
|
||||
final HelpExecutor help = new HelpExecutor("?", new Command("mock") {
|
||||
|
||||
@Override
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
help.execute(test, null);
|
||||
test.close();
|
||||
|
||||
try {
|
||||
help.execute(test, null);
|
||||
fail("manager closed shall provoke failure of help command execution");
|
||||
} catch (final Exception e) {
|
||||
assertNotNull(e);
|
||||
@Override
|
||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
help.execute(test, null);
|
||||
test.close();
|
||||
|
||||
try {
|
||||
help.execute(test, null);
|
||||
fail("manager closed shall provoke failure of help command execution");
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,24 +105,22 @@ public class HelpExecutorTest {
|
||||
help = new HelpExecutor("?", new MockCommand("mock"));
|
||||
}
|
||||
|
||||
/** Test method for {@link fr.bigeon.gclc.command.HelpExecutor#tip()}. */
|
||||
/** Test method for {@link fr.bigeon.gclc.command.HelpExecutor#tip()}.
|
||||
*
|
||||
* @throws IOException */
|
||||
@Test
|
||||
public final void testTip() {
|
||||
public final void testTip() throws IOException {
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new MockCommand("mock"));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new SubedCommand("sub", new MockCommand("mock")));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -64,9 +63,11 @@ import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
public class ParametrizedCommandTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#addParameter(java.lang.String, boolean, boolean)}. */
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#addParameter(java.lang.String, boolean, boolean)}.
|
||||
*
|
||||
* @throws InvalidParameterException */
|
||||
@Test
|
||||
public final void testAddParameter() {
|
||||
public final void testAddParameter() throws InvalidParameterException {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand("name") {
|
||||
|
||||
@Override
|
||||
@@ -108,37 +109,37 @@ public class ParametrizedCommandTest {
|
||||
// XXX Boolean flag should not be specified mandatory! They are by
|
||||
// nature qualified
|
||||
final String str = "str";
|
||||
try {
|
||||
assertTrue(cmd.getBooleanParameters().isEmpty());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertFalse(cmd.isNeeded(str));
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
cmd.addStringParameter(str, true);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
} catch (final InvalidParameterException e) {
|
||||
fail("Unexpected error in addition of legitimate parameter");
|
||||
assertNotNull(e);
|
||||
}
|
||||
assertTrue(cmd.getBooleanParameters().isEmpty());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertFalse(cmd.isNeeded(str));
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
cmd.addStringParameter(str, true);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#execute(java.lang.String[])}. */
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#execute(java.lang.String[])}.
|
||||
*
|
||||
* @throws CommandRunException
|
||||
* @throws InterruptedException
|
||||
* @throws IOException */
|
||||
@Test
|
||||
public final void testExecute() {
|
||||
public final void testExecute() throws CommandRunException,
|
||||
InterruptedException, IOException {
|
||||
final String addParam = "additional";
|
||||
final String str1 = "str1";
|
||||
final String str2 = "str2";
|
||||
@@ -175,15 +176,10 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
private int call = 0;
|
||||
{
|
||||
@@ -245,17 +241,12 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
cmd = new ParametrizedCommand("name", true) {
|
||||
private int call = 0;
|
||||
{
|
||||
@@ -314,25 +305,20 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unexpected error");
|
||||
}
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
try {
|
||||
cmd.execute(null, null, addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
// Test on command with missing needed elements
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
@@ -367,21 +353,16 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam, addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam, addParam);
|
||||
try {
|
||||
cmd.execute(null, null);
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
cmd = new ParametrizedCommand("name", true) {
|
||||
private final int call = 0;
|
||||
@@ -416,36 +397,31 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
try {
|
||||
cmd.execute(null, null, "-" + str1, str2, addParam);
|
||||
fail("Additional parameter should cause failure");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
cmd.execute(null, null);
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam);
|
||||
fail("unepected error");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
try {
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam, addParam);
|
||||
fail("unepected error");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
// TODO Test of interactive not providing and providing all needed
|
||||
try (PipedConsoleOutput out = new PipedConsoleOutput();
|
||||
@@ -480,71 +456,57 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute(out, in, "-" + str1, str2);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(out, in, "-" + str1, str2, addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam,
|
||||
addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute(out, in, "-" + str1, str2);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(out, in, "-" + str1, str2, addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam, addParam);
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
|
||||
cmd.execute(out, in);
|
||||
cmd.execute(out, in);
|
||||
|
||||
th.join();
|
||||
th.join();
|
||||
|
||||
th = new Thread(new Runnable() {
|
||||
th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
|
||||
cmd.execute(out, in, "-" + addParam);
|
||||
cmd.execute(out, in, "-" + addParam);
|
||||
|
||||
th.join();
|
||||
} catch (CommandRunException | InterruptedException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
th.join();
|
||||
}
|
||||
try {
|
||||
final PipedConsoleOutput out = new PipedConsoleOutput();
|
||||
@@ -584,10 +546,8 @@ public class ParametrizedCommandTest {
|
||||
cmd.execute(out, test, "-" + str1, str2);
|
||||
cmd.execute(out, test, "-" + addParam);
|
||||
fail("Closed manager shall cause error");
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
// ok
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ public class ScriptExecutionTest {
|
||||
test = new PipedConsoleOutput();
|
||||
} catch (final IOException e2) {
|
||||
fail("creation of console manager failed"); //$NON-NLS-1$
|
||||
assertNotNull(e2);
|
||||
return;
|
||||
}
|
||||
final ConsoleApplication app = new ConsoleApplication(
|
||||
|
||||
@@ -71,21 +71,18 @@ public class SubedCommandTest {
|
||||
cmd.add(new MockCommand("id"));
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.add(new MockCommand("id"));
|
||||
fail("addition of command with already used id succeeded");
|
||||
} catch (final InvalidCommandName e) {
|
||||
//
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.add(new MockCommand(""));
|
||||
fail("addition of command with invalid id succeeded");
|
||||
} catch (final InvalidCommandName e) {
|
||||
//
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -226,13 +223,13 @@ public class SubedCommandTest {
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.executeSub("id");
|
||||
cmd.executeSub(null, null,"id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.executeSub("fail");
|
||||
cmd.executeSub(null, null, "fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.manager;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -68,76 +66,71 @@ public class ReadingRunnableTest {
|
||||
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}. */
|
||||
@Test
|
||||
public final void testGetMessage() {
|
||||
BufferedReader reader = null;
|
||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
final BufferedReader reader = null;
|
||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
runnable.setRunning(false);
|
||||
|
||||
try {
|
||||
runnable.getMessage();
|
||||
fail("reading from closed runnable");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
} catch (final IOException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* @throws IOException */
|
||||
@Test
|
||||
public final void testGetWaitForDelivery() throws InterruptedException, IOException {
|
||||
try (PipedOutputStream out = new PipedOutputStream();
|
||||
InputStream piped = new PipedInputStream(out);
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(piped, "UTF-8"))) {
|
||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
final Thread th0 = new Thread(runnable, "read");
|
||||
th0.start();
|
||||
final Thread th = runnable.getWaitForDelivery("msg");
|
||||
|
||||
out.write(Charset.forName("UTF-8")
|
||||
.encode("msg" + System.lineSeparator()).array());
|
||||
|
||||
final Thread th2 = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runnable.getMessage();
|
||||
} catch (final IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "get");
|
||||
th2.start();
|
||||
th.join();
|
||||
runnable.setRunning(false);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}. */
|
||||
@Test
|
||||
public final void testHasMessage() {
|
||||
|
||||
BufferedReader reader = null;
|
||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
final BufferedReader reader = null;
|
||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
runnable.setRunning(false);
|
||||
|
||||
try {
|
||||
runnable.getMessage();
|
||||
fail("reading from closed runnable");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
||||
*
|
||||
* @throws InterruptedException */
|
||||
@Test
|
||||
public final void testGetWaitForDelivery() throws InterruptedException {
|
||||
try (PipedOutputStream out = new PipedOutputStream();
|
||||
InputStream piped = new PipedInputStream(out);
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(piped, "UTF-8"))) {
|
||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||
Thread th0 = new Thread(runnable, "read");
|
||||
th0.start();
|
||||
Thread th = runnable.getWaitForDelivery("msg");
|
||||
|
||||
out.write(Charset.forName("UTF-8")
|
||||
.encode("msg" + System.lineSeparator()).array());
|
||||
|
||||
Thread th2 = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runnable.getMessage();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "get");
|
||||
th2.start();
|
||||
try {
|
||||
th.join();
|
||||
} catch (InterruptedException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
runnable.setRunning(false);
|
||||
out.close();
|
||||
} catch (IOException e1) {
|
||||
assertNull(e1);
|
||||
} catch (final IOException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ package fr.bigeon.gclc.manager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -54,62 +52,64 @@ import java.nio.charset.Charset;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class SystemConsoleManagerTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#isClosed()}. */
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#isClosed()}.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException */
|
||||
@Test
|
||||
public final void testIsClosed() {
|
||||
try {
|
||||
final PipedOutputStream outStream = new PipedOutputStream();
|
||||
final InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
final String test = "test";
|
||||
final SystemConsoleInput manager = new SystemConsoleInput(
|
||||
System.out,
|
||||
in, Charset.forName("UTF-8"));
|
||||
public final void testIsClosed() throws IOException, InterruptedException {
|
||||
final PipedOutputStream outStream = new PipedOutputStream();
|
||||
final InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
final String test = "test";
|
||||
final StreamConsoleInput manager = new StreamConsoleInput(System.out,
|
||||
in, Charset.forName("UTF-8"));
|
||||
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
out.println(test);
|
||||
}
|
||||
});
|
||||
|
||||
th.start();
|
||||
assertEquals(test, manager.prompt());
|
||||
assertFalse(manager.isClosed());
|
||||
manager.close();
|
||||
assertTrue(manager.isClosed());
|
||||
try {
|
||||
manager.prompt();
|
||||
fail("prompt on closed manager");
|
||||
} catch (final IOException e) {
|
||||
assertNotNull(e);
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
out.println(test);
|
||||
}
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
assertNull(e);
|
||||
});
|
||||
|
||||
th.start();
|
||||
assertEquals(test, manager.prompt());
|
||||
assertFalse(manager.isClosed());
|
||||
manager.close();
|
||||
assertTrue(manager.isClosed());
|
||||
try {
|
||||
manager.prompt();
|
||||
fail("prompt on closed manager");
|
||||
} catch (final IOException e) {
|
||||
// ok
|
||||
}
|
||||
th.join();
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#prompt()}. */
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#prompt()}.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException */
|
||||
@Test
|
||||
public final void testPrompt() {
|
||||
public final void testPrompt() throws IOException, InterruptedException {
|
||||
|
||||
final String test = "test";
|
||||
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
SystemConsoleInput manager = new SystemConsoleInput(System.out,
|
||||
in, Charset.forName("UTF-8"))) {
|
||||
StreamConsoleInput manager = new StreamConsoleInput(System.out, in,
|
||||
Charset.forName("UTF-8"))) {
|
||||
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@@ -124,26 +124,24 @@ public class SystemConsoleManagerTest {
|
||||
assertEquals(test, manager.prompt());
|
||||
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#setPrompt(java.lang.String)}. */
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#setPrompt(java.lang.String)}.
|
||||
*
|
||||
* @throws IOException */
|
||||
@Test
|
||||
public final void testSetPrompt() {
|
||||
public final void testSetPrompt() throws IOException {
|
||||
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
SystemConsoleInput manager = new SystemConsoleInput(System.out,
|
||||
in, Charset.forName("UTF-8"))) {
|
||||
StreamConsoleInput manager = new StreamConsoleInput(System.out, in,
|
||||
Charset.forName("UTF-8"))) {
|
||||
|
||||
final String prt = "++";
|
||||
manager.setPrompt(prt);
|
||||
assertEquals(prt, manager.getPrompt());
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user