Add Code compliance
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -69,19 +69,19 @@ public class ConsoleApplicationTest {
|
||||
|
||||
/** Test the base of a console application */
|
||||
@Test
|
||||
public void test() {
|
||||
public void testConsoleApplication() {
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager()) {
|
||||
ConsoleApplication app = new ConsoleApplication(manager, "", "");
|
||||
final ConsoleApplication app = new ConsoleApplication(manager, "", "");
|
||||
app.exit();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("System Console Manager failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executionTest() {
|
||||
public void testExecution() {
|
||||
try (CommandTestingApplication application = new CommandTestingApplication()) {
|
||||
|
||||
// remove welcome
|
||||
@@ -106,17 +106,17 @@ public class ConsoleApplicationTest {
|
||||
assertEquals("Waita minute", application.readNextLine());
|
||||
assertEquals("done!", application.readNextLine());
|
||||
|
||||
CommandRequestListener crl = new CommandRequestListener() {
|
||||
final CommandRequestListener crl = new CommandRequestListener() {
|
||||
|
||||
@Override
|
||||
public void commandRequest(String command) {
|
||||
public void commandRequest(final String command) {
|
||||
//
|
||||
}
|
||||
};
|
||||
CommandRequestListener crl2 = new CommandRequestListener() {
|
||||
final CommandRequestListener crl2 = new CommandRequestListener() {
|
||||
|
||||
@Override
|
||||
public void commandRequest(String command) {
|
||||
public void commandRequest(final String command) {
|
||||
//
|
||||
}
|
||||
};
|
||||
@@ -136,7 +136,7 @@ public class ConsoleApplicationTest {
|
||||
assertEquals(application.getApplication().footer,
|
||||
application.readNextLine());
|
||||
assertFalse(application.getApplication().isRunning());
|
||||
} catch (IOException e1) {
|
||||
} catch (final IOException e1) {
|
||||
assertNull(e1);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ConsoleApplicationTest {
|
||||
appli = app;
|
||||
app.add(new ExitCommand("exit", app));
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
@@ -174,9 +174,9 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void interpretCommandTest() {
|
||||
public void testInterpretCommand() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
ConsoleApplication appl = new ConsoleApplication(test, "", "");
|
||||
final ConsoleApplication appl = new ConsoleApplication(test, "", "");
|
||||
|
||||
appl.interpretCommand("invalid cmd \"due to misplaced\"quote");
|
||||
assertEquals("Command line cannot be parsed", test.readNextLine());
|
||||
@@ -188,7 +188,7 @@ public class ConsoleApplicationTest {
|
||||
appl.add(new ICommand() {
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
throw new CommandRunException(
|
||||
CommandRunExceptionType.USAGE, message, this);
|
||||
}
|
||||
@@ -199,8 +199,8 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(ConsoleManager manager,
|
||||
String... args) throws IOException {
|
||||
public void help(final ConsoleManager manager,
|
||||
final String... args) throws IOException {
|
||||
manager.println(message);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
});
|
||||
} catch (InvalidCommandName e) {
|
||||
} catch (final InvalidCommandName e) {
|
||||
assertNull(e);
|
||||
}
|
||||
appl.interpretCommand("fail");
|
||||
@@ -220,7 +220,7 @@ public class ConsoleApplicationTest {
|
||||
assertEquals(message, test.readNextLine());
|
||||
assertEquals(message, test.readNextLine());
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
|
||||
/** A test-purpose application
|
||||
*
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
|
||||
@@ -62,44 +62,41 @@ public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
application.root));
|
||||
application.add(new Command("test") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
try {
|
||||
application.manager.println("Test command ran fine");
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "A test command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
try {
|
||||
application.manager.println("Test command ran fine");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
}
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
application.add(new Command("long") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "A long execution command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
try {
|
||||
application.manager.println("Waita minute");
|
||||
Thread.sleep(TWO_SECONDS);
|
||||
application.manager.println("done!");
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
throw new CommandRunException("wait interrupted", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
});
|
||||
application.add(new Command("failingCmd") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
@@ -107,9 +104,25 @@ public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
application.add(new Command("failingCmd") {
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "A long execution command";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class GCLCConstantsTest {
|
||||
List<String> res;
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse simple command " + e.getLocalizedMessage()); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class GCLCConstantsTest {
|
||||
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -82,7 +82,7 @@ public class GCLCConstantsTest {
|
||||
assertTrue(res.get(3).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments and double whitspaces " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -95,7 +95,7 @@ public class GCLCConstantsTest {
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand \"with some\" arguments");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -106,7 +106,7 @@ public class GCLCConstantsTest {
|
||||
assertTrue(res.get(2).equals("arguments"));
|
||||
try {
|
||||
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with arguments with escaped whitspaces " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -118,7 +118,7 @@ public class GCLCConstantsTest {
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand wi\\\"th some arguments");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -132,7 +132,7 @@ public class GCLCConstantsTest {
|
||||
try {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand with \"some arguments\"");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
fail("Unable to parse command ending with string argument " + //$NON-NLS-1$
|
||||
e.getLocalizedMessage());
|
||||
return;
|
||||
@@ -147,9 +147,8 @@ public class GCLCConstantsTest {
|
||||
res = GCLCConstants
|
||||
.splitCommand("aCommand with \"some ar\"guments");
|
||||
fail("Parsing argument with string cut");
|
||||
} catch (CommandParsingException e) {
|
||||
} catch (final CommandParsingException e) {
|
||||
// OK
|
||||
assertTrue(e.getLocalizedMessage(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,44 +54,49 @@ import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
public class CommandTest {
|
||||
|
||||
@Test
|
||||
public final void test() {
|
||||
public final void testCommand() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
Command cmd;
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.Command#brief() */
|
||||
@Override
|
||||
@@ -100,19 +105,24 @@ public class CommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.Command#brief() */
|
||||
@Override
|
||||
@@ -121,14 +131,29 @@ public class CommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
@@ -140,16 +165,16 @@ public class CommandTest {
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
@@ -161,15 +186,15 @@ public class CommandTest {
|
||||
protected String usageDetail() {
|
||||
return "details";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
@@ -181,16 +206,16 @@ public class CommandTest {
|
||||
protected String usageDetail() {
|
||||
return "details" + System.lineSeparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
@@ -202,15 +227,10 @@ public class CommandTest {
|
||||
protected String usageDetail() {
|
||||
return "\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd.help(test);
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
@@ -56,37 +58,18 @@ import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
*/
|
||||
public class HelpExecutorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.HelpExecutor#HelpExecutor(java.lang.String, fr.bigeon.gclc.manager.ConsoleManager, fr.bigeon.gclc.command.ICommand)}.
|
||||
*/
|
||||
@Test
|
||||
public final void testHelpExecutor(){
|
||||
HelpExecutor help;
|
||||
try {
|
||||
help = new HelpExecutor("?", null, new MockCommand("mock"));
|
||||
fail("help is an interactive command, should need console manager");
|
||||
} catch (Exception e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
help = new HelpExecutor("?", test, new MockCommand("mock"));
|
||||
} catch (Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.HelpExecutor#execute(java.lang.String[])}.
|
||||
*/
|
||||
@Test
|
||||
public final void testExecute(){
|
||||
try {
|
||||
PipedConsoleManager test = new PipedConsoleManager();
|
||||
HelpExecutor help = new HelpExecutor("?", test,
|
||||
final PipedConsoleManager test = new PipedConsoleManager();
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
new Command("mock") {
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -94,6 +77,10 @@ public class HelpExecutorTest {
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -103,33 +90,45 @@ public class HelpExecutorTest {
|
||||
try {
|
||||
help.execute();
|
||||
fail("manager closed shall provoke failure of help command execution");
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.HelpExecutor#HelpExecutor(java.lang.String, fr.bigeon.gclc.manager.ConsoleManager, fr.bigeon.gclc.command.ICommand)}.
|
||||
*
|
||||
* @throws IOException if an IO occurs */
|
||||
@Test
|
||||
public final void testHelpExecutor() throws IOException {
|
||||
HelpExecutor help;
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
help = new HelpExecutor("?", test, new MockCommand("mock"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.HelpExecutor#tip()}.
|
||||
*/
|
||||
@Test
|
||||
public final void testTip(){
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
HelpExecutor help = new HelpExecutor("?", test,
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
new MockCommand("mock"));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
HelpExecutor help = new HelpExecutor("?", test,
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
new SubedCommand("sub", new MockCommand("mock")));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,144 +59,47 @@ import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ParametrizedCommandTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#ParametrizedCommand(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String)}. */
|
||||
@Test
|
||||
public final void testParametrizedCommandConsoleManagerString() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(test, "name") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertTrue(cmd.isInteractive());
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected exception in creation");
|
||||
assertNull(e);
|
||||
}
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#ParametrizedCommand(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String, boolean)}. */
|
||||
@Test
|
||||
public final void testParametrizedCommandConsoleManagerStringBoolean() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(test, "name",
|
||||
false) {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertTrue(cmd.isInteractive());
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected exception in creation");
|
||||
assertNull(e);
|
||||
}
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name", false) {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#addParameter(java.lang.String, boolean, boolean)}. */
|
||||
@Test
|
||||
public final void testAddParameter() {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name") {
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd = new ParametrizedCommand(null, "name", true) {
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// XXX Boolean flag should not be specified mandatory! They are by
|
||||
// nature qualified
|
||||
String str = "str";
|
||||
final String str = "str";
|
||||
try {
|
||||
assertTrue(cmd.getBooleanParameters().isEmpty());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
@@ -218,7 +121,7 @@ public class ParametrizedCommandTest {
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
fail("Unexpected error in addition of legitimate parameter");
|
||||
assertNotNull(e);
|
||||
}
|
||||
@@ -239,12 +142,7 @@ public class ParametrizedCommandTest {
|
||||
private boolean evenCall = true;
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertTrue(parameters.getBooleanArgumentKeys().isEmpty());
|
||||
assertTrue(parameters.getStringArgumentKeys().isEmpty());
|
||||
if (evenCall) {
|
||||
@@ -256,13 +154,23 @@ public class ParametrizedCommandTest {
|
||||
evenCall = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute("-" + addParam);
|
||||
cmd.execute(addParam);
|
||||
cmd.execute("-" + addParam, addParam);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
@@ -275,19 +183,14 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertEquals(2, parameters.getBooleanArgumentKeys().size());
|
||||
assertEquals(2, parameters.getStringArgumentKeys().size());
|
||||
switch (call) {
|
||||
@@ -319,6 +222,16 @@ public class ParametrizedCommandTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
@@ -327,7 +240,7 @@ public class ParametrizedCommandTest {
|
||||
cmd.execute("-" + addParam, addParam);
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
@@ -340,19 +253,13 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertEquals(2, parameters.getBooleanArgumentKeys().size());
|
||||
assertEquals(2, parameters.getStringArgumentKeys().size());
|
||||
switch (call) {
|
||||
@@ -381,25 +288,35 @@ public class ParametrizedCommandTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unexpected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute(addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
// Test on command with missing needed elements
|
||||
@@ -412,11 +329,15 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
@@ -424,8 +345,8 @@ public class ParametrizedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
@@ -434,14 +355,14 @@ public class ParametrizedCommandTest {
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
cmd = new ParametrizedCommand("name", true) {
|
||||
@@ -453,52 +374,57 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
//
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
fail("Additional parameter should cause failure");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
fail("unepected error");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
fail("unepected error");
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
// TODO Test of interactive not providing and providing all needed
|
||||
@@ -510,11 +436,15 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
@@ -522,8 +452,8 @@ public class ParametrizedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
@@ -532,7 +462,7 @@ public class ParametrizedCommandTest {
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
@@ -554,7 +484,7 @@ public class ParametrizedCommandTest {
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
test.readNextLine());
|
||||
test.type(str2);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
@@ -573,7 +503,7 @@ public class ParametrizedCommandTest {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
test.readNextLine());
|
||||
test.type(str2);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
@@ -587,12 +517,12 @@ public class ParametrizedCommandTest {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
PipedConsoleManager test = new PipedConsoleManager();
|
||||
final PipedConsoleManager test = new PipedConsoleManager();
|
||||
cmd = new ParametrizedCommand(test, "name") {
|
||||
{
|
||||
try {
|
||||
@@ -600,32 +530,168 @@ public class ParametrizedCommandTest {
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
} catch (final InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
test.close();
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + addParam);
|
||||
fail("Closed manager shall cause error");
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#ParametrizedCommand(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String)}. */
|
||||
@Test
|
||||
public final void testParametrizedCommandConsoleManagerString() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final ParametrizedCommand cmd = new ParametrizedCommand(test, "name") {
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertTrue(cmd.isInteractive());
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected exception in creation");
|
||||
assertNull(e);
|
||||
}
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name") {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name") {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#ParametrizedCommand(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String, boolean)}. */
|
||||
@Test
|
||||
public final void testParametrizedCommandConsoleManagerStringBoolean() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final ParametrizedCommand cmd = new ParametrizedCommand(test, "name",
|
||||
false) {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertTrue(cmd.isInteractive());
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected exception in creation");
|
||||
assertNull(e);
|
||||
}
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name", false) {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,20 +68,20 @@ public class ScriptExecutionTest {
|
||||
PipedConsoleManager test;
|
||||
try {
|
||||
test = new PipedConsoleManager();
|
||||
} catch (IOException e2) {
|
||||
} catch (final IOException e2) {
|
||||
fail("creation of console manager failed"); //$NON-NLS-1$
|
||||
assertNotNull(e2);
|
||||
return;
|
||||
}
|
||||
ConsoleApplication app = new ConsoleApplication(
|
||||
final ConsoleApplication app = new ConsoleApplication(
|
||||
test, "", "");
|
||||
new ConsoleTestApplication().attach(app);
|
||||
ScriptExecution exec = new ScriptExecution("script", app, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
final ScriptExecution exec = new ScriptExecution("script", app, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
try {
|
||||
exec.execute();
|
||||
fail("execution of script command with no file should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.USAGE, e1.getType());
|
||||
@@ -90,7 +90,7 @@ public class ScriptExecutionTest {
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/withprependSpace.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with lines begining with space should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.EXECUTION, e1.getType());
|
||||
@@ -99,7 +99,7 @@ public class ScriptExecutionTest {
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/invalidCmdParse.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with invalid command line should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.EXECUTION, e1.getType());
|
||||
@@ -108,7 +108,7 @@ public class ScriptExecutionTest {
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/invalidCmd.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with invalid command should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.EXECUTION, e1.getType());
|
||||
@@ -117,7 +117,7 @@ public class ScriptExecutionTest {
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/failingCmdInvoc.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with failing command should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.EXECUTION, e1.getType());
|
||||
@@ -126,7 +126,7 @@ public class ScriptExecutionTest {
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/someNonExisting.file"); //$NON-NLS-1$
|
||||
fail("execution of script with unexisting file should fail"); //$NON-NLS-1$
|
||||
} catch (CommandRunException e1) {
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
assertEquals(exec, e1.getSource());
|
||||
assertEquals(CommandRunExceptionType.EXECUTION, e1.getType());
|
||||
@@ -138,38 +138,38 @@ public class ScriptExecutionTest {
|
||||
exec.execute("src/test/resources/script3.txt"); //$NON-NLS-1$
|
||||
exec.execute("src/test/resources/script4.txt"); //$NON-NLS-1$
|
||||
exec.execute("src/test/resources/script5.txt", "test"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (CommandRunException e) {
|
||||
} catch (final CommandRunException e) {
|
||||
e.printStackTrace();
|
||||
fail("execution of wellformed script should not fail"); //$NON-NLS-1$
|
||||
}
|
||||
try {
|
||||
test.close();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for {@link fr.bigeon.gclc.command.ScriptExecution#tip()}. */
|
||||
@Test
|
||||
public void testTip() {
|
||||
ScriptExecution exec = new ScriptExecution("script", null, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
exec.tip();
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.ScriptExecution#help(fr.bigeon.gclc.manager.ConsoleManager, String...)}. */
|
||||
@Test
|
||||
public void testHelp() {
|
||||
ScriptExecution exec = new ScriptExecution("script", null, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
final ScriptExecution exec = new ScriptExecution("script", null, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
exec.help(test);
|
||||
exec.help(test, "ignored element");
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
fail("unexpected error in help invocation"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for {@link fr.bigeon.gclc.command.ScriptExecution#tip()}. */
|
||||
@Test
|
||||
public void testTip() {
|
||||
final ScriptExecution exec = new ScriptExecution("script", null, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
assertNotNull("Tip should not be null", exec.tip());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,296 @@ import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
@SuppressWarnings("all")
|
||||
public class SubedCommandTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#add(fr.bigeon.gclc.command.ICommand)}. */
|
||||
@Test
|
||||
public final void testAdd() {
|
||||
final SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
try {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#execute(java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testExecute() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
final MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", null);
|
||||
}
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd, e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
fail("Request for inexistent default command should fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd, e.getSource());
|
||||
}
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd.get("fail"), e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Request for default command should execute default command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#executeSub(java.lang.String, java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testExecuteSub() {
|
||||
final SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
final MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.executeSub("id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.executeSub("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd.get("fail"), e.getSource());
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#get(java.lang.String)}. */
|
||||
@Test
|
||||
public final void testGet() {
|
||||
final SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
assertNull(cmd.get("id"));
|
||||
|
||||
final MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
assertEquals(mock, cmd.get("id"));
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#getCommandName()}. */
|
||||
@Test
|
||||
public final void testGetCommandName() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name with spaces");
|
||||
assertEquals("name with spaces", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", "some tip");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", new MockCommand(""));
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", new MockCommand(""), "some tip");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#help(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testHelp() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
ICommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
cmd.help(manager, "id");
|
||||
cmd.help(manager, "inexistent");
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
mock = new ICommand() {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(final ConsoleManager manager,
|
||||
final String... args) throws IOException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
}
|
||||
};
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (final InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\ttip", manager.readNextLine());
|
||||
assertEquals("\tid: tip", manager.readNextLine());
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#SubedCommand(java.lang.String)}. */
|
||||
@Test
|
||||
@@ -101,284 +391,6 @@ public class SubedCommandTest {
|
||||
assertEquals("name with spaces", cmd.getCommandName());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#add(fr.bigeon.gclc.command.ICommand)}. */
|
||||
@Test
|
||||
public final void testAdd() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
try {
|
||||
cmd.add(new MockCommand("id"));
|
||||
} catch (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 (InvalidCommandName e) {
|
||||
//
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.add(new MockCommand(""));
|
||||
fail("addition of command with invalid id succeeded");
|
||||
} catch (InvalidCommandName e) {
|
||||
//
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#execute(java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testExecute() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", null);
|
||||
}
|
||||
});
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
} catch (CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd, e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
fail("Request for inexistent default command should fail");
|
||||
} catch (CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd, e.getSource());
|
||||
}
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
});
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
} catch (CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd.get("fail"), e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
} catch (CommandRunException e) {
|
||||
fail("Request for default command should execute default command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#executeSub(java.lang.String, java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testExecuteSub() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
});
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.executeSub("id");
|
||||
} catch (CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.executeSub("fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd.get("fail"), e.getSource());
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#get(java.lang.String)}. */
|
||||
@Test
|
||||
public final void testGet() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
assertNull(cmd.get("id"));
|
||||
|
||||
MockCommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
assertEquals(mock, cmd.get("id"));
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#getCommandName()}. */
|
||||
@Test
|
||||
public final void testGetCommandName() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name with spaces");
|
||||
assertEquals("name with spaces", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", "some tip");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", new MockCommand(""));
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
cmd = new SubedCommand("name", new MockCommand(""), "some tip");
|
||||
assertEquals("name", cmd.getCommandName());
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand#help(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testHelp() {
|
||||
SubedCommand cmd = new SubedCommand("name");
|
||||
|
||||
ICommand mock = new MockCommand("id");
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
cmd.help(manager, "id");
|
||||
cmd.help(manager, "inexistent");
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
mock = new ICommand() {
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return "tip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(ConsoleManager manager,
|
||||
String... args) throws IOException {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
};
|
||||
cmd = new SubedCommand("name", mock);
|
||||
|
||||
try {
|
||||
cmd.add(mock);
|
||||
} catch (InvalidCommandName e) {
|
||||
fail("addition of command with valid id failed");
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\ttip", manager.readNextLine());
|
||||
assertEquals("\tid: tip", manager.readNextLine());
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected exception when running help");
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for {@link fr.bigeon.gclc.command.SubedCommand#tip()}. */
|
||||
@Test
|
||||
public final void testTip() {
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.proc;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -49,68 +52,65 @@ import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ProcessListTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.proc.ProcessList#execute(java.lang.String[])}.
|
||||
*
|
||||
*
|
||||
* @throws CommandRunException if an error occured in the execution
|
||||
* @throws IOException if the manager could not be created */
|
||||
@Test
|
||||
public final void testExecute() throws CommandRunException, IOException {
|
||||
TaskPool pool = new TaskPool();
|
||||
ProcessList pl = new ProcessList("list", pool,
|
||||
new PipedConsoleManager());
|
||||
final TaskPool pool = new TaskPool();
|
||||
try (PipedConsoleManager pcm = new PipedConsoleManager()) {
|
||||
final ProcessList pl = new ProcessList("list", pool, pcm);
|
||||
pl.execute();
|
||||
pool.add(new Task() {
|
||||
pool.add(new Task() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
//
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
}
|
||||
@Override
|
||||
public void addInterruptionListener(final InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunning(boolean running) {
|
||||
//
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rmInterruptionListener(InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void rmInterruptionListener(final InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
//
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterruptionListener(InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
});
|
||||
pl.execute();
|
||||
@Override
|
||||
public void setRunning(final boolean running) {
|
||||
//
|
||||
}
|
||||
});
|
||||
pl.execute();
|
||||
assertTrue("List should give the process",
|
||||
pcm.readNextLine().endsWith("name"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTip() {
|
||||
try {
|
||||
new ProcessList("list", new TaskPool(), new PipedConsoleManager())
|
||||
.tip();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
public void testTip() throws IOException {
|
||||
try (PipedConsoleManager pcm = new PipedConsoleManager()) {
|
||||
assertNotNull("Tip should not be null", new ProcessList("list",
|
||||
new TaskPool(), pcm).tip());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
package fr.bigeon.gclc.proc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -55,26 +54,46 @@ public class TaskPoolTest {
|
||||
* {@link fr.bigeon.gclc.proc.TaskPool#add(fr.bigeon.gclc.proc.Task)}. */
|
||||
@Test
|
||||
public final void testAdd() {
|
||||
TaskPool pool = new TaskPool();
|
||||
final TaskPool pool = new TaskPool();
|
||||
Task task = null;
|
||||
try {
|
||||
pool.add(task);
|
||||
fail("Expected a null pointer exception");
|
||||
} catch (NullPointerException e) {
|
||||
assertNotNull(e);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// ok
|
||||
}
|
||||
task = new Task() {
|
||||
private final Object lock = new Object();
|
||||
private boolean running;
|
||||
private InterruptionListener listener;
|
||||
|
||||
@Override
|
||||
public void addInterruptionListener(final InterruptionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rmInterruptionListener(final InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
while (running) {
|
||||
try {
|
||||
lock.wait(100);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -84,45 +103,25 @@ public class TaskPoolTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunning(boolean running) {
|
||||
public void setRunning(final boolean running) {
|
||||
synchronized (lock) {
|
||||
this.running = running;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rmInterruptionListener(InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterruptionListener(InterruptionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
};
|
||||
pool.add(task);
|
||||
assertEquals(1, pool.getPIDs().size());
|
||||
|
||||
for (String pid : pool.getPIDs()) {
|
||||
for (final String pid : pool.getPIDs()) {
|
||||
assertEquals(task, pool.get(pid));
|
||||
}
|
||||
Thread th = new Thread(task);
|
||||
final Thread th = new Thread(task);
|
||||
th.start();
|
||||
task.setRunning(false);
|
||||
try {
|
||||
th.join(1000);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@@ -78,7 +79,7 @@ public class CLIPrompterTest {
|
||||
@Test
|
||||
public final void testPromptBoolean() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -91,7 +92,7 @@ public class CLIPrompterTest {
|
||||
CLIPrompter.promptBoolean(test, "My message")); //$NON-NLS-1$
|
||||
assertFalse(
|
||||
CLIPrompter.promptBoolean(test, "My message")); //$NON-NLS-1$
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -131,7 +132,7 @@ public class CLIPrompterTest {
|
||||
final String cancel = "Cancel"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -142,7 +143,7 @@ public class CLIPrompterTest {
|
||||
test, keys, choices, message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test, keys,
|
||||
choices, message, cancel));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -157,9 +158,10 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size());
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0)));
|
||||
@@ -176,9 +178,9 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
assertEquals(CLIPrompterMessages
|
||||
.getString("promptchoice.outofbounds", 0, keys.size() - 1), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
assertEquals(
|
||||
CLIPrompterMessages.getString("promptchoice.outofbounds", 0, //$NON-NLS-1$
|
||||
keys.size() - 1), test.readNextLine());
|
||||
assertTrue(test.readNextLine().contains(keys.get(0)));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1)));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
@@ -199,94 +201,6 @@ public class CLIPrompterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testPromptChoiceConsoleManagerListOfUStringString() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final List<Object> keys = new ArrayList<>();
|
||||
keys.add("A choice"); //$NON-NLS-1$
|
||||
keys.add("An other"); //$NON-NLS-1$
|
||||
final String cancel = "Cancel"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(Integer.valueOf(0),
|
||||
CLIPrompter.promptChoice(test,
|
||||
keys, message, cancel));
|
||||
assertEquals(Integer.valueOf(0), CLIPrompter
|
||||
.promptChoice(test,
|
||||
keys, message, null));
|
||||
assertEquals(Integer.valueOf(1), CLIPrompter
|
||||
.promptChoice(test, keys, message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test, keys,
|
||||
message, cancel));
|
||||
} catch (IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size());
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("0"); //$NON-NLS-1$
|
||||
// Sucess, reprompt without cancel
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
assertEquals(CLIPrompterMessages
|
||||
.getString("promptchoice.outofbounds", 0, keys.size() - 1), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("0"); //$NON-NLS-1$
|
||||
// Success do it again
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("1"); //$NON-NLS-1$
|
||||
// Sucess, prompt with cancel
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
fail("Unexpected excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
@@ -299,20 +213,20 @@ public class CLIPrompterTest {
|
||||
final String cancel = "Cancel"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(choices.get(keys.get(0)),
|
||||
CLIPrompter.promptChoice(
|
||||
test, keys, choices, message, cancel));
|
||||
CLIPrompter.promptChoice(test, keys, choices,
|
||||
message, cancel));
|
||||
assertEquals(choices.get(keys.get(0)),
|
||||
CLIPrompter.promptChoice(
|
||||
test, keys, choices, message, null));
|
||||
CLIPrompter.promptChoice(test, keys, choices,
|
||||
message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test, keys,
|
||||
choices, message, cancel));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -327,9 +241,10 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size());
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
@@ -346,9 +261,9 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
assertEquals(CLIPrompterMessages
|
||||
.getString("promptchoice.outofbounds", 0, keys.size() - 1), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
assertEquals(
|
||||
CLIPrompterMessages.getString("promptchoice.outofbounds", 0, //$NON-NLS-1$
|
||||
keys.size() - 1), test.readNextLine());
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
@@ -369,6 +284,93 @@ public class CLIPrompterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testPromptChoiceConsoleManagerListOfUStringString() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final List<Object> keys = new ArrayList<>();
|
||||
keys.add("A choice"); //$NON-NLS-1$
|
||||
keys.add("An other"); //$NON-NLS-1$
|
||||
final String cancel = "Cancel"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(Integer.valueOf(0), CLIPrompter
|
||||
.promptChoice(test, keys, message, cancel));
|
||||
assertEquals(Integer.valueOf(0), CLIPrompter
|
||||
.promptChoice(test, keys, message, null));
|
||||
assertEquals(Integer.valueOf(1), CLIPrompter
|
||||
.promptChoice(test, keys, message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test, keys,
|
||||
message, cancel));
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
th.start();
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size());
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("0"); //$NON-NLS-1$
|
||||
// Sucess, reprompt without cancel
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
assertEquals(
|
||||
CLIPrompterMessages.getString("promptchoice.outofbounds", 0, //$NON-NLS-1$
|
||||
keys.size() - 1), test.readNextLine());
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("0"); //$NON-NLS-1$
|
||||
// Success do it again
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("1"); //$NON-NLS-1$
|
||||
// Sucess, prompt with cancel
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
fail("Unexpected excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.prompt.CLIPrompter#promptChoice(fr.bigeon.gclc.manager.ConsoleManager, java.util.Map, java.lang.String, java.lang.String)}. */
|
||||
@Test
|
||||
@@ -383,18 +385,20 @@ public class CLIPrompterTest {
|
||||
final String cancel = "Cancel"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(choices.get(keys.get(0)), CLIPrompter
|
||||
.promptChoice(test, choices, message, cancel));
|
||||
assertEquals(choices.get(keys.get(0)), CLIPrompter
|
||||
.promptChoice(test, choices, message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test,
|
||||
assertEquals(choices.get(keys.get(0)),
|
||||
CLIPrompter.promptChoice(test, keys, choices,
|
||||
message, cancel));
|
||||
assertEquals(choices.get(keys.get(0)),
|
||||
CLIPrompter.promptChoice(test, keys, choices,
|
||||
message, null));
|
||||
assertEquals(null, CLIPrompter.promptChoice(test, keys,
|
||||
choices, message, cancel));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -402,16 +406,19 @@ public class CLIPrompterTest {
|
||||
});
|
||||
th.start();
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
final String readNextLine = test.readNextLine();
|
||||
assertTrue(readNextLine + " expected to contain " + keys.get(0),
|
||||
readNextLine.contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertTrue(test.readNextLine().contains(cancel));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size());
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
@@ -428,9 +435,9 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("2"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
assertEquals(CLIPrompterMessages
|
||||
.getString("promptchoice.outofbounds", 0, keys.size() - 1), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
assertEquals(
|
||||
CLIPrompterMessages.getString("promptchoice.outofbounds", 0, //$NON-NLS-1$
|
||||
keys.size() - 1), test.readNextLine());
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
@@ -456,7 +463,7 @@ public class CLIPrompterTest {
|
||||
@Test
|
||||
public final void testPromptInteger() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -465,7 +472,7 @@ public class CLIPrompterTest {
|
||||
CLIPrompter.promptInteger(test, "My message")); //$NON-NLS-1$
|
||||
assertEquals(-15,
|
||||
CLIPrompter.promptInteger(test, "My message")); //$NON-NLS-1$
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -498,7 +505,7 @@ public class CLIPrompterTest {
|
||||
keys.add("An other"); //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -507,7 +514,7 @@ public class CLIPrompterTest {
|
||||
CLIPrompter.promptList(test, message));
|
||||
assertEquals(keys,
|
||||
CLIPrompter.promptList(test, message));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -556,7 +563,7 @@ public class CLIPrompterTest {
|
||||
final String ender = "*"; //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -565,7 +572,7 @@ public class CLIPrompterTest {
|
||||
CLIPrompter.promptList(test, message, ender));
|
||||
assertEquals(keys,
|
||||
CLIPrompter.promptList(test, message, ender));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -606,19 +613,21 @@ public class CLIPrompterTest {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final String message = "My message";
|
||||
final String longText = "Some text with" + System.lineSeparator() +
|
||||
"line feeds and other" + System.lineSeparator() +
|
||||
System.lineSeparator() + " \tspecial characters";
|
||||
"line feeds and other" +
|
||||
System.lineSeparator() +
|
||||
System.lineSeparator() +
|
||||
" \tspecial characters";
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("",
|
||||
CLIPrompter.promptLongText(test, message));
|
||||
assertEquals(longText,
|
||||
assertEquals(longText + System.lineSeparator(),
|
||||
CLIPrompter.promptLongText(test, message));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -627,10 +636,9 @@ public class CLIPrompterTest {
|
||||
th.start();
|
||||
String nLine = test.readNextLine();
|
||||
assertTrue(nLine.startsWith(message));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.dispkey",
|
||||
CLIPrompterMessages.getString(
|
||||
"promptlongtext.exit.defaultkey"))));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages.getString(
|
||||
"promptlongtext.exit.dispkey", CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.defaultkey"))));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
test.type(CLIPrompterMessages
|
||||
@@ -638,14 +646,13 @@ public class CLIPrompterTest {
|
||||
// enter long text
|
||||
nLine = test.readNextLine();
|
||||
assertTrue(nLine.startsWith(message));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.dispkey",
|
||||
CLIPrompterMessages.getString(
|
||||
"promptlongtext.exit.defaultkey"))));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages.getString(
|
||||
"promptlongtext.exit.dispkey", CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.defaultkey"))));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
String[] text = longText.split(System.lineSeparator());
|
||||
for (String element : text) {
|
||||
final String[] text = longText.split(System.lineSeparator());
|
||||
for (final String element : text) {
|
||||
test.type(element);
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
@@ -666,21 +673,23 @@ public class CLIPrompterTest {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final String message = "My message";
|
||||
final String ender = "\\quit";
|
||||
final String[] text = new String[]{"Some text with" ,
|
||||
"feeds and other" , " \tspecial characters"};
|
||||
final String[] text = new String[] {"Some text with",
|
||||
"feeds and other", " \tspecial characters"};
|
||||
final String longText = text[0] + System.lineSeparator() + text[1] +
|
||||
System.lineSeparator() + text[2];
|
||||
System.lineSeparator() + text[2];
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("", //$NON-NLS-1$
|
||||
CLIPrompter.promptLongText(test, message, ender));
|
||||
assertEquals(longText,
|
||||
CLIPrompter.promptLongText(test, message, ender));
|
||||
} catch (IOException e) {
|
||||
CLIPrompter.promptLongText(test, message,
|
||||
ender));
|
||||
assertEquals(longText + System.lineSeparator(),
|
||||
CLIPrompter.promptLongText(test, message,
|
||||
ender));
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -690,8 +699,7 @@ public class CLIPrompterTest {
|
||||
String nLine = test.readNextLine();
|
||||
assertTrue(nLine.startsWith(message));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.dispkey",
|
||||
ender)));
|
||||
.getString("promptlongtext.exit.dispkey", ender)));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
test.type(ender);
|
||||
@@ -699,11 +707,10 @@ public class CLIPrompterTest {
|
||||
nLine = test.readNextLine();
|
||||
assertTrue(nLine.startsWith(message));
|
||||
assertTrue(nLine.endsWith(CLIPrompterMessages
|
||||
.getString("promptlongtext.exit.dispkey",
|
||||
ender)));
|
||||
.getString("promptlongtext.exit.dispkey", ender)));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
for (String element : text) {
|
||||
for (final String element : text) {
|
||||
test.type(element);
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
|
||||
test.readNextLine());
|
||||
@@ -729,7 +736,7 @@ public class CLIPrompterTest {
|
||||
choices.add("The actual other"); //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -737,14 +744,14 @@ public class CLIPrompterTest {
|
||||
assertTrue(CLIPrompter
|
||||
.promptMultiChoice(test, keys, choices, message)
|
||||
.isEmpty());
|
||||
ArrayList<Object> l = new ArrayList<>();
|
||||
final ArrayList<Object> l = new ArrayList<>();
|
||||
l.add(choices.get(0));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, choices, message));
|
||||
l.add(choices.get(1));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, choices, message));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -758,9 +765,10 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size() - 1);
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0)));
|
||||
@@ -812,7 +820,7 @@ public class CLIPrompterTest {
|
||||
choices.put(keys.get(1), "The actual other"); //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -820,14 +828,14 @@ public class CLIPrompterTest {
|
||||
assertTrue(CLIPrompter
|
||||
.promptMultiChoice(test, keys, choices, message)
|
||||
.isEmpty());
|
||||
ArrayList<Object> l = new ArrayList<>();
|
||||
final ArrayList<Object> l = new ArrayList<>();
|
||||
l.add(choices.get(keys.get(0)));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, choices, message));
|
||||
l.add(choices.get(keys.get(1)));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, choices, message));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -841,9 +849,10 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size() - 1);
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
@@ -892,7 +901,7 @@ public class CLIPrompterTest {
|
||||
keys.add("An other"); //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -900,14 +909,14 @@ public class CLIPrompterTest {
|
||||
assertTrue(CLIPrompter
|
||||
.promptMultiChoice(test, keys, message)
|
||||
.isEmpty());
|
||||
ArrayList<Integer> l = new ArrayList<>();
|
||||
final ArrayList<Integer> l = new ArrayList<>();
|
||||
l.add(0);
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, message));
|
||||
l.add(1);
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
keys, message));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -921,9 +930,10 @@ public class CLIPrompterTest {
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size() - 1);
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
@@ -975,22 +985,22 @@ public class CLIPrompterTest {
|
||||
choices.put(keys.get(1), "The actual other"); //$NON-NLS-1$
|
||||
final String message = "My message"; //$NON-NLS-1$
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertTrue(CLIPrompter
|
||||
.promptMultiChoice(test, choices, message)
|
||||
.promptMultiChoice(test, keys, choices, message)
|
||||
.isEmpty());
|
||||
ArrayList<Object> l = new ArrayList<>();
|
||||
final ArrayList<Object> l = new ArrayList<>();
|
||||
l.add(choices.get(keys.get(0)));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
choices, message));
|
||||
keys, choices, message));
|
||||
l.add(choices.get(keys.get(1)));
|
||||
assertEquals(l, CLIPrompter.promptMultiChoice(test,
|
||||
choices, message));
|
||||
} catch (IOException e) {
|
||||
keys, choices, message));
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -998,15 +1008,18 @@ public class CLIPrompterTest {
|
||||
});
|
||||
th.start();
|
||||
assertTrue(test.readNextLine().startsWith(message));
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
final String readNextLine = test.readNextLine();
|
||||
assertTrue(readNextLine + " expected to contain " + keys.get(0),
|
||||
readNextLine.contains(keys.get(0).toString()));
|
||||
assertTrue(test.readNextLine().contains(keys.get(1).toString()));
|
||||
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
||||
test.readNextLine());
|
||||
test.type("yoyo"); //$NON-NLS-1$
|
||||
// fail, reprompt
|
||||
String msg = CLIPrompterMessages.getString("promptchoice.formaterr", //$NON-NLS-1$
|
||||
final String msg = CLIPrompterMessages.getString(
|
||||
"promptchoice.formaterr", //$NON-NLS-1$
|
||||
0, keys.size() - 1);
|
||||
for (String line : msg.split(System.lineSeparator())) {
|
||||
for (final String line : msg.split(System.lineSeparator())) {
|
||||
assertEquals(line, test.readNextLine());
|
||||
}
|
||||
assertTrue(test.readNextLine().contains(keys.get(0).toString()));
|
||||
@@ -1051,14 +1064,14 @@ public class CLIPrompterTest {
|
||||
public final void testPromptNonEmpty() {
|
||||
try (final PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final String res = "some content"; //$NON-NLS-1$
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(res, CLIPrompter.promptNonEmpty(test,
|
||||
"My message", "my reprompt")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user