Update to next mechanism, with stream passed at command execution
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -42,7 +42,8 @@ import java.io.IOException;
|
||||
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -56,12 +57,14 @@ public class CommandTestingApplication implements AutoCloseable {
|
||||
|
||||
private final ConsoleApplication application;
|
||||
private final Thread th;
|
||||
private final PipedConsoleManager manager;
|
||||
private final PipedConsoleOutput out;
|
||||
private final PipedConsoleInput in;
|
||||
|
||||
/** @throws IOException if the streams cannot be build */
|
||||
public CommandTestingApplication() throws IOException {
|
||||
manager = new PipedConsoleManager();
|
||||
application = new ConsoleApplication(manager, "", "");
|
||||
out = new PipedConsoleOutput();
|
||||
in = new PipedConsoleInput();
|
||||
application = new ConsoleApplication(out, in, "", "");
|
||||
new ConsoleTestApplication().attach(application);
|
||||
th = new Thread(new Runnable() {
|
||||
|
||||
@@ -75,49 +78,47 @@ public class CommandTestingApplication implements AutoCloseable {
|
||||
th.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
application.exit();
|
||||
manager.close();
|
||||
}
|
||||
|
||||
public void sendCommand(String cmd) throws IOException {
|
||||
manager.type(cmd);
|
||||
}
|
||||
|
||||
/** @param cmd the command
|
||||
* @return if the command was added
|
||||
* @throws InvalidCommandName if the command name is invalid
|
||||
* @see fr.bigeon.gclc.ConsoleApplication#add(fr.bigeon.gclc.command.ICommand) */
|
||||
public final boolean add(ICommand cmd) throws InvalidCommandName {
|
||||
public final boolean add(final ICommand cmd) throws InvalidCommandName {
|
||||
return application.add(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
application.exit();
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
|
||||
/** @return the application */
|
||||
public ConsoleApplication getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
/** @return the next written line, null if it is the prompt
|
||||
* @throws IOException if the reading failed
|
||||
* @see fr.bigeon.gclc.manager.PipedConsoleManager#readNextLine() */
|
||||
public String readNextLine() throws IOException {
|
||||
final String ret = out.readNextLine();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void sendCommand(final String cmd) throws IOException {
|
||||
in.type(cmd);
|
||||
}
|
||||
|
||||
/** @throws IOException if the writing failed */
|
||||
public void waitAndStop() throws IOException {
|
||||
manager.type(ConsoleTestApplication.EXIT);
|
||||
in.type(ConsoleTestApplication.EXIT);
|
||||
try {
|
||||
th.join();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the next written line, null if it is the prompt
|
||||
* @throws IOException if the reading failed
|
||||
* @see fr.bigeon.gclc.manager.PipedConsoleManager#readNextLine() */
|
||||
public String readNextLine() throws IOException {
|
||||
String ret = manager.readNextLine();
|
||||
if (ret.equals(manager.getPrompt())) {
|
||||
return null;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,10 @@ import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.i18n.Messages;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** Test class for ConsoleApplication
|
||||
*
|
||||
@@ -71,8 +73,9 @@ public class ConsoleApplicationTest {
|
||||
@Test
|
||||
public void testConsoleApplication() {
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(manager, "", "");
|
||||
try (PipedConsoleInput manager = new PipedConsoleInput()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(null,
|
||||
manager, "", "");
|
||||
app.exit();
|
||||
} catch (final IOException e) {
|
||||
fail("System Console Manager failed");
|
||||
@@ -88,12 +91,9 @@ public class ConsoleApplicationTest {
|
||||
assertEquals(application.getApplication().header,
|
||||
application.readNextLine());
|
||||
// Remove first prompt
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("");
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("test");
|
||||
assertEquals("Test command ran fine", application.readNextLine());
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("toto");
|
||||
assertEquals(
|
||||
Messages.getString("ConsoleApplication.cmd.failed", "toto"),
|
||||
@@ -101,7 +101,6 @@ public class ConsoleApplicationTest {
|
||||
assertEquals(
|
||||
Messages.getString("CommandProvider.unrecognized", "toto"),
|
||||
application.readNextLine());
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("long");
|
||||
assertEquals("Waita minute", application.readNextLine());
|
||||
assertEquals("done!", application.readNextLine());
|
||||
@@ -122,7 +121,6 @@ public class ConsoleApplicationTest {
|
||||
};
|
||||
application.getApplication().addListener(crl);
|
||||
application.getApplication().addListener(crl2);
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("test");
|
||||
assertEquals("Test command ran fine", application.readNextLine());
|
||||
application.getApplication().removeListener(crl2);
|
||||
@@ -131,7 +129,6 @@ public class ConsoleApplicationTest {
|
||||
|
||||
assertTrue(application.getApplication().isRunning());
|
||||
|
||||
assertNull(application.readNextLine());
|
||||
application.sendCommand("exit");
|
||||
assertEquals(application.getApplication().footer,
|
||||
application.readNextLine());
|
||||
@@ -141,8 +138,10 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
ConsoleApplication appli = null;
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(manager, null,
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput();
|
||||
PipedConsoleInput in = new PipedConsoleInput()) {
|
||||
final ConsoleApplication app = new ConsoleApplication(manager,
|
||||
in, null,
|
||||
null);
|
||||
appli = app;
|
||||
app.add(new ExitCommand("exit", app));
|
||||
@@ -158,7 +157,7 @@ public class ConsoleApplicationTest {
|
||||
|
||||
th.start();
|
||||
|
||||
manager.type("exit");
|
||||
in.type("exit");
|
||||
th.join();
|
||||
|
||||
} catch (IOException | InvalidCommandName |
|
||||
@@ -175,8 +174,10 @@ public class ConsoleApplicationTest {
|
||||
|
||||
@Test
|
||||
public void testInterpretCommand() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final ConsoleApplication appl = new ConsoleApplication(test, "", "");
|
||||
try (PipedConsoleInput test = new PipedConsoleInput();
|
||||
PipedConsoleOutput out = new PipedConsoleOutput()) {
|
||||
final ConsoleApplication appl = new ConsoleApplication(out, test,
|
||||
"", "");
|
||||
|
||||
appl.interpretCommand("invalid cmd \"due to misplaced\"quote");
|
||||
assertEquals("Command line cannot be parsed", test.readNextLine());
|
||||
@@ -187,8 +188,16 @@ public class ConsoleApplicationTest {
|
||||
try {
|
||||
appl.add(new ICommand() {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see
|
||||
* fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput,
|
||||
* fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException(
|
||||
CommandRunExceptionType.USAGE, message, this);
|
||||
}
|
||||
@@ -199,7 +208,7 @@ public class ConsoleApplicationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(final ConsoleManager manager,
|
||||
public void help(final ConsoleOutput manager,
|
||||
final String... args) throws IOException {
|
||||
manager.println(message);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import fr.bigeon.gclc.command.ExitCommand;
|
||||
import fr.bigeon.gclc.command.HelpExecutor;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
|
||||
/** A test-purpose application
|
||||
*
|
||||
@@ -58,14 +60,20 @@ public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
public void attach(final ConsoleApplication application) {
|
||||
try {
|
||||
application.add(new ExitCommand(EXIT, application));
|
||||
application.add(new HelpExecutor("help", application.manager,
|
||||
application.add(new HelpExecutor("help",
|
||||
application.root));
|
||||
application.add(new Command("test") {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
try {
|
||||
application.manager.println("Test command ran fine");
|
||||
out.println("Test command ran fine");
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
@@ -83,12 +91,18 @@ public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
}
|
||||
});
|
||||
application.add(new Command("long") {
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
try {
|
||||
application.manager.println("Waita minute");
|
||||
out.println("Waita minute");
|
||||
Thread.sleep(TWO_SECONDS);
|
||||
application.manager.println("done!");
|
||||
out.println("done!");
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
@@ -109,8 +123,14 @@ public class ConsoleTestApplication implements ApplicationAttachement {
|
||||
}
|
||||
});
|
||||
application.add(new Command("failingCmd") {
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
||||
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
||||
* java.lang.String[]) */
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** <p>
|
||||
* TODO
|
||||
@@ -55,12 +57,14 @@ public class CommandTest {
|
||||
|
||||
@Test
|
||||
public final void testCommand() {
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
Command cmd;
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -79,7 +83,9 @@ public class CommandTest {
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -105,7 +111,9 @@ public class CommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -131,7 +139,9 @@ public class CommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -150,7 +160,9 @@ public class CommandTest {
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -171,7 +183,9 @@ public class CommandTest {
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -191,7 +205,9 @@ public class CommandTest {
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -212,7 +228,9 @@ public class CommandTest {
|
||||
cmd = new Command("name") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@@ -47,29 +47,30 @@ import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public class HelpExecutorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.HelpExecutor#execute(java.lang.String[])}.
|
||||
*/
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.command.HelpExecutor#execute(java.lang.String[])}. */
|
||||
@Test
|
||||
public final void testExecute(){
|
||||
public final void testExecute() {
|
||||
try {
|
||||
final PipedConsoleManager test = new PipedConsoleManager();
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
final PipedConsoleOutput test = new PipedConsoleOutput();
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new Command("mock") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -77,18 +78,19 @@ public class HelpExecutorTest {
|
||||
public String tip() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
help.execute();
|
||||
help.execute(test, null);
|
||||
test.close();
|
||||
|
||||
try {
|
||||
help.execute();
|
||||
help.execute(test, null);
|
||||
fail("manager closed shall provoke failure of help command execution");
|
||||
} catch (final Exception e) {
|
||||
assertNotNull(e);
|
||||
@@ -100,31 +102,27 @@ 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)}.
|
||||
*
|
||||
*
|
||||
* @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"));
|
||||
}
|
||||
help = new HelpExecutor("?", new MockCommand("mock"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.HelpExecutor#tip()}.
|
||||
*/
|
||||
/** Test method for {@link fr.bigeon.gclc.command.HelpExecutor#tip()}. */
|
||||
@Test
|
||||
public final void testTip(){
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
public final void testTip() {
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new MockCommand("mock"));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
} catch (final Exception e) {
|
||||
assertNull(e);
|
||||
}
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
final HelpExecutor help = new HelpExecutor("?", test,
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
final HelpExecutor help = new HelpExecutor("?",
|
||||
new SubedCommand("sub", new MockCommand("mock")));
|
||||
help.tip();
|
||||
help.help(test);
|
||||
|
||||
@@ -51,9 +51,13 @@ import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidParameterException;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@@ -63,10 +67,12 @@ public class ParametrizedCommandTest {
|
||||
* {@link fr.bigeon.gclc.command.ParametrizedCommand#addParameter(java.lang.String, boolean, boolean)}. */
|
||||
@Test
|
||||
public final void testAddParameter() {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand(null, "name") {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand("name") {
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -80,10 +86,12 @@ public class ParametrizedCommandTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
cmd = new ParametrizedCommand(null, "name", true) {
|
||||
cmd = new ParametrizedCommand("name", true) {
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -142,7 +150,9 @@ public class ParametrizedCommandTest {
|
||||
private boolean evenCall = true;
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertTrue(parameters.getBooleanArgumentKeys().isEmpty());
|
||||
assertTrue(parameters.getStringArgumentKeys().isEmpty());
|
||||
if (evenCall) {
|
||||
@@ -162,14 +172,14 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute("-" + addParam);
|
||||
cmd.execute(addParam);
|
||||
cmd.execute("-" + addParam, addParam);
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
@@ -190,7 +200,9 @@ public class ParametrizedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertEquals(2, parameters.getBooleanArgumentKeys().size());
|
||||
assertEquals(2, parameters.getStringArgumentKeys().size());
|
||||
switch (call) {
|
||||
@@ -230,16 +242,16 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute("-" + addParam);
|
||||
cmd.execute(addParam);
|
||||
cmd.execute("-" + addParam, addParam);
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
cmd.execute(null, null, "-" + addParam, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
@@ -258,8 +270,11 @@ public class ParametrizedCommandTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertEquals(2, parameters.getBooleanArgumentKeys().size());
|
||||
assertEquals(2, parameters.getStringArgumentKeys().size());
|
||||
switch (call) {
|
||||
@@ -296,25 +311,25 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unexpected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute(addParam);
|
||||
cmd.execute(null, null, addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + addParam);
|
||||
cmd.execute(null, null, "-" + addParam);
|
||||
fail("Strict should fail with unexpected argument");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
@@ -334,8 +349,11 @@ public class ParametrizedCommandTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@@ -346,21 +364,21 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam, addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute(null, null);
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
@@ -381,7 +399,9 @@ public class ParametrizedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
@@ -393,43 +413,44 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(null, null, "-" + str1, str2);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + bool1);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, addParam);
|
||||
fail("Additional parameter should cause failure");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute(null, null);
|
||||
fail("needed " + str1 + " not provided shall fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam);
|
||||
fail("unepected error");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
cmd.execute(null, null, "-" + str1, str2, "-" + addParam, addParam);
|
||||
fail("unepected error");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
// TODO Test of interactive not providing and providing all needed
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
cmd = new ParametrizedCommand(test, "name", false) {
|
||||
try (PipedConsoleOutput out = new PipedConsoleOutput();
|
||||
PipedConsoleInput in = new PipedConsoleInput()) {
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
{
|
||||
try {
|
||||
addStringParameter(str1, true);
|
||||
@@ -441,8 +462,11 @@ public class ParametrizedCommandTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@@ -453,15 +477,16 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + str1, str2, "-" + bool1);
|
||||
cmd.execute("-" + str1, str2, addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam);
|
||||
cmd.execute("-" + str1, str2, "-" + addParam, addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + bool1);
|
||||
cmd.execute(out, in, "-" + str1, str2, addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
|
||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam,
|
||||
addParam);
|
||||
} catch (final CommandRunException e) {
|
||||
assertNull(e);
|
||||
fail("unepected error");
|
||||
@@ -474,16 +499,16 @@ public class ParametrizedCommandTest {
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
test.readNextLine());
|
||||
test.type("");
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
test.readNextLine());
|
||||
test.type("");
|
||||
in.readNextLine());
|
||||
in.type("");
|
||||
assertEquals(
|
||||
"value of " + str1 + "? (cannot be empty) ",
|
||||
test.readNextLine());
|
||||
test.type(str2);
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
@@ -491,7 +516,7 @@ public class ParametrizedCommandTest {
|
||||
});
|
||||
th.start();
|
||||
|
||||
cmd.execute();
|
||||
cmd.execute(out, in);
|
||||
|
||||
th.join();
|
||||
|
||||
@@ -501,8 +526,8 @@ public class ParametrizedCommandTest {
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals("value of " + str1 + "? ",
|
||||
test.readNextLine());
|
||||
test.type(str2);
|
||||
in.readNextLine());
|
||||
in.type(str2);
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
@@ -510,7 +535,7 @@ public class ParametrizedCommandTest {
|
||||
});
|
||||
th.start();
|
||||
|
||||
cmd.execute("-" + addParam);
|
||||
cmd.execute(out, in, "-" + addParam);
|
||||
|
||||
th.join();
|
||||
} catch (CommandRunException | InterruptedException e) {
|
||||
@@ -522,8 +547,9 @@ public class ParametrizedCommandTest {
|
||||
fail("unepected error");
|
||||
}
|
||||
try {
|
||||
final PipedConsoleManager test = new PipedConsoleManager();
|
||||
cmd = new ParametrizedCommand(test, "name") {
|
||||
final PipedConsoleOutput out = new PipedConsoleOutput();
|
||||
final PipedConsoleInput test = new PipedConsoleInput();
|
||||
cmd = new ParametrizedCommand("name") {
|
||||
{
|
||||
try {
|
||||
addStringParameter(str1, true);
|
||||
@@ -537,7 +563,9 @@ public class ParametrizedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
assertEquals(str2, parameters.get(str1));
|
||||
}
|
||||
|
||||
@@ -548,12 +576,13 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
test.close();
|
||||
cmd.execute("-" + str1, str2);
|
||||
cmd.execute("-" + addParam);
|
||||
out.close();
|
||||
cmd.execute(out, test, "-" + str1, str2);
|
||||
cmd.execute(out, test, "-" + addParam);
|
||||
fail("Closed manager shall cause error");
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
@@ -567,32 +596,12 @@ public class ParametrizedCommandTest {
|
||||
* {@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") {
|
||||
ParametrizedCommand 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());
|
||||
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) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -603,14 +612,15 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name") {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -621,44 +631,40 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertTrue(cmd.isStrict());
|
||||
cmd = new ParametrizedCommand("name") {
|
||||
@Override
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
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) {
|
||||
ParametrizedCommand cmd = new ParametrizedCommand("name", false) {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -669,14 +675,15 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
@Override
|
||||
protected void doExecute(final CommandParameters parameters) {
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -687,11 +694,29 @@ public class ParametrizedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
cmd = new ParametrizedCommand("name", false) {
|
||||
@Override
|
||||
protected void doExecute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final CommandParameters parameters) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
assertFalse(cmd.isStrict());
|
||||
assertFalse(cmd.isInteractive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.ConsoleTestApplication;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** <p>
|
||||
* Test class for {@link ScriptExecution}
|
||||
@@ -65,21 +66,23 @@ public class ScriptExecutionTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() {
|
||||
PipedConsoleManager test;
|
||||
PipedConsoleOutput test;
|
||||
PipedConsoleInput in;
|
||||
try {
|
||||
test = new PipedConsoleManager();
|
||||
in = new PipedConsoleInput();
|
||||
test = new PipedConsoleOutput();
|
||||
} catch (final IOException e2) {
|
||||
fail("creation of console manager failed"); //$NON-NLS-1$
|
||||
assertNotNull(e2);
|
||||
return;
|
||||
}
|
||||
final ConsoleApplication app = new ConsoleApplication(
|
||||
test, "", "");
|
||||
test, in, "", "");
|
||||
new ConsoleTestApplication().attach(app);
|
||||
final ScriptExecution exec = new ScriptExecution("script", app, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
try {
|
||||
exec.execute();
|
||||
exec.execute(test, in);
|
||||
fail("execution of script command with no file should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -88,7 +91,8 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/withprependSpace.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in,
|
||||
"src/test/resources/scripts/withprependSpace.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with lines begining with space should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -97,7 +101,8 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/invalidCmdParse.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in,
|
||||
"src/test/resources/scripts/invalidCmdParse.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with invalid command line should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -106,7 +111,8 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/invalidCmd.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in,
|
||||
"src/test/resources/scripts/invalidCmd.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with invalid command should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -115,7 +121,8 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/failingCmdInvoc.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in,
|
||||
"src/test/resources/scripts/failingCmdInvoc.txt"); //$NON-NLS-1$
|
||||
fail("execution of script with failing command should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -124,7 +131,8 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/scripts/someNonExisting.file"); //$NON-NLS-1$
|
||||
exec.execute(test, in,
|
||||
"src/test/resources/scripts/someNonExisting.file"); //$NON-NLS-1$
|
||||
fail("execution of script with unexisting file should fail"); //$NON-NLS-1$
|
||||
} catch (final CommandRunException e1) {
|
||||
// ok
|
||||
@@ -133,11 +141,11 @@ public class ScriptExecutionTest {
|
||||
}
|
||||
|
||||
try {
|
||||
exec.execute("src/test/resources/script1.txt"); //$NON-NLS-1$
|
||||
exec.execute("src/test/resources/script2.txt"); //$NON-NLS-1$
|
||||
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$
|
||||
exec.execute(test, in, "src/test/resources/script1.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in, "src/test/resources/script2.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in, "src/test/resources/script3.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in, "src/test/resources/script4.txt"); //$NON-NLS-1$
|
||||
exec.execute(test, in, "src/test/resources/script5.txt", "test"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (final CommandRunException e) {
|
||||
e.printStackTrace();
|
||||
fail("execution of wellformed script should not fail"); //$NON-NLS-1$
|
||||
@@ -156,7 +164,7 @@ public class ScriptExecutionTest {
|
||||
public void testHelp() {
|
||||
final ScriptExecution exec = new ScriptExecution("script", null, "#", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Charset.forName("UTF-8"));
|
||||
try (PipedConsoleManager test = new PipedConsoleManager()) {
|
||||
try (PipedConsoleOutput test = new PipedConsoleOutput()) {
|
||||
exec.help(test);
|
||||
exec.help(test, "ignored element");
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -49,10 +49,12 @@ import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** <p>
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@@ -100,9 +102,12 @@ public class SubedCommandTest {
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
@@ -110,7 +115,7 @@ public class SubedCommandTest {
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
@@ -119,20 +124,20 @@ public class SubedCommandTest {
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
cmd.execute(null, null, "id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
cmd.execute(null, null, "fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd, e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute(null, null);
|
||||
fail("Request for inexistent default command should fail");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
@@ -145,17 +150,20 @@ public class SubedCommandTest {
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
@@ -164,20 +172,20 @@ public class SubedCommandTest {
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.execute("id");
|
||||
cmd.execute(null, null, "id");
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Unexpected exception when running mock command");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.execute("fail");
|
||||
cmd.execute(null, null, "fail");
|
||||
fail("Fail command error should be re thrown");
|
||||
} catch (final CommandRunException e) {
|
||||
assertNotNull(e);
|
||||
assertEquals(cmd.get("fail"), e.getSource());
|
||||
}
|
||||
try {
|
||||
cmd.execute();
|
||||
cmd.execute(null, null);
|
||||
} catch (final CommandRunException e) {
|
||||
fail("Request for default command should execute default command");
|
||||
assertNotNull(e);
|
||||
@@ -196,17 +204,20 @@ public class SubedCommandTest {
|
||||
cmd.add(new Command("fail") {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out,
|
||||
final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
throw new CommandRunException("Failing command", this);
|
||||
}
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
@@ -277,8 +288,7 @@ public class SubedCommandTest {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
cmd.help(manager, "id");
|
||||
@@ -297,8 +307,7 @@ public class SubedCommandTest {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\tid", manager.readNextLine());
|
||||
} catch (final IOException e) {
|
||||
@@ -309,7 +318,8 @@ public class SubedCommandTest {
|
||||
mock = new ICommand() {
|
||||
|
||||
@Override
|
||||
public void execute(final String... args) throws CommandRunException {
|
||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -319,7 +329,7 @@ public class SubedCommandTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(final ConsoleManager manager,
|
||||
public void help(final ConsoleOutput manager,
|
||||
final String... args) throws IOException {
|
||||
//
|
||||
}
|
||||
@@ -338,8 +348,7 @@ public class SubedCommandTest {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager();
|
||||
PipedConsoleManager manager2 = new PipedConsoleManager()) {
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
||||
cmd.help(manager);
|
||||
assertEquals("\ttip", manager.readNextLine());
|
||||
assertEquals("\tid: tip", manager.readNextLine());
|
||||
|
||||
@@ -60,6 +60,45 @@ import org.junit.Test;
|
||||
* @author Emmanuel Bigeon */
|
||||
public class SystemConsoleManagerTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#isClosed()}. */
|
||||
@Test
|
||||
public final void testIsClosed() {
|
||||
try {
|
||||
final PipedOutputStream outStream = new PipedOutputStream();
|
||||
final InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
final String test = "test";
|
||||
final SystemConsoleInput manager = new SystemConsoleInput(
|
||||
System.out,
|
||||
in, Charset.forName("UTF-8"));
|
||||
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
out.println(test);
|
||||
}
|
||||
});
|
||||
|
||||
th.start();
|
||||
assertEquals(test, manager.prompt());
|
||||
assertFalse(manager.isClosed());
|
||||
manager.close();
|
||||
assertTrue(manager.isClosed());
|
||||
try {
|
||||
manager.prompt();
|
||||
fail("prompt on closed manager");
|
||||
} catch (final IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#prompt()}. */
|
||||
@Test
|
||||
@@ -69,10 +108,10 @@ public class SystemConsoleManagerTest {
|
||||
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
||||
SystemConsoleInput manager = new SystemConsoleInput(System.out,
|
||||
in, Charset.forName("UTF-8"))) {
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
@@ -97,57 +136,13 @@ public class SystemConsoleManagerTest {
|
||||
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
||||
SystemConsoleInput manager = new SystemConsoleInput(System.out,
|
||||
in, Charset.forName("UTF-8"))) {
|
||||
|
||||
String prt = "++";
|
||||
final String prt = "++";
|
||||
manager.setPrompt(prt);
|
||||
assertEquals(prt, manager.getPrompt());
|
||||
} catch (IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#isClosed()}. */
|
||||
@Test
|
||||
public final void testIsClosed() {
|
||||
try {
|
||||
PipedOutputStream outStream = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(outStream);
|
||||
final PrintStream out = new PrintStream(outStream);
|
||||
final String test = "test";
|
||||
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
||||
in, Charset.forName("UTF-8"));
|
||||
|
||||
Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
out.println(test);
|
||||
}
|
||||
});
|
||||
|
||||
th.start();
|
||||
assertEquals(test, manager.prompt());
|
||||
assertFalse(manager.isClosed());
|
||||
manager.close();
|
||||
assertTrue(manager.isClosed());
|
||||
try {
|
||||
manager.prompt();
|
||||
fail("prompt on closed manager");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
manager.println(test);
|
||||
fail("prompt on closed manager");
|
||||
} catch (IOException e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
th.join();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch (final IOException e) {
|
||||
assertNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a generic framework for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.proc.ProcessListTest.java
|
||||
* Created on: Aug 19, 2017
|
||||
*/
|
||||
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;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @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 {
|
||||
final TaskPool pool = new TaskPool();
|
||||
try (PipedConsoleManager pcm = new PipedConsoleManager()) {
|
||||
final ProcessList pl = new ProcessList("list", pool, pcm);
|
||||
pl.execute();
|
||||
pool.add(new Task() {
|
||||
|
||||
@Override
|
||||
public void addInterruptionListener(final InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rmInterruptionListener(final InterruptionListener listener) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
//
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunning(final boolean running) {
|
||||
//
|
||||
}
|
||||
});
|
||||
pl.execute();
|
||||
assertTrue("List should give the process",
|
||||
pcm.readNextLine().endsWith("name"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTip() throws IOException {
|
||||
try (PipedConsoleManager pcm = new PipedConsoleManager()) {
|
||||
assertNotNull("Tip should not be null", new ProcessList("list",
|
||||
new TaskPool(), pcm).tip());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a generic framework for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.proc.TaskPoolTest.java
|
||||
* Created on: Aug 19, 2017
|
||||
*/
|
||||
package fr.bigeon.gclc.proc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class TaskPoolTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.proc.TaskPool#add(fr.bigeon.gclc.proc.Task)}. */
|
||||
@Test
|
||||
public final void testAdd() {
|
||||
final TaskPool pool = new TaskPool();
|
||||
Task task = null;
|
||||
try {
|
||||
pool.add(task);
|
||||
fail("Expected a null pointer exception");
|
||||
} 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 (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
listener.interrupted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunning(final boolean running) {
|
||||
synchronized (lock) {
|
||||
this.running = running;
|
||||
}
|
||||
//
|
||||
}
|
||||
};
|
||||
pool.add(task);
|
||||
assertEquals(1, pool.getPIDs().size());
|
||||
|
||||
for (final String pid : pool.getPIDs()) {
|
||||
assertEquals(task, pool.get(pid));
|
||||
}
|
||||
final Thread th = new Thread(task);
|
||||
th.start();
|
||||
task.setRunning(false);
|
||||
try {
|
||||
th.join(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assertEquals(0, pool.getPIDs().size());
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,7 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||
import fr.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
|
||||
/** <p>
|
||||
* TODO
|
||||
@@ -62,24 +62,19 @@ public class AOutputForwardRunnableTest {
|
||||
private String message;
|
||||
|
||||
/** @param manager */
|
||||
private AOutputForwardTestRunnable(PipedConsoleManager manager) {
|
||||
private AOutputForwardTestRunnable(final PipedConsoleOutput manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunning() {
|
||||
return count != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forwardLine(String m) {
|
||||
protected void forwardLine(final String m) {
|
||||
// Do nothing
|
||||
message = m;
|
||||
synchronized (this) {
|
||||
notify();
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -92,13 +87,13 @@ public class AOutputForwardRunnableTest {
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
String m = message;
|
||||
final String m = message;
|
||||
count--;
|
||||
message = null;
|
||||
synchronized (this) {
|
||||
@@ -106,17 +101,22 @@ public class AOutputForwardRunnableTest {
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunning() {
|
||||
return count != 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link fr.bigeon.gclc.tools.AOutputForwardRunnable#run()}. */
|
||||
@Test
|
||||
public final void testRun() {
|
||||
try (PipedConsoleManager manager = new PipedConsoleManager()) {
|
||||
AOutputForwardTestRunnable runnable = new AOutputForwardTestRunnable(
|
||||
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
||||
final AOutputForwardTestRunnable runnable = new AOutputForwardTestRunnable(
|
||||
manager);
|
||||
|
||||
Thread th = new Thread(runnable, "forward");
|
||||
final Thread th = new Thread(runnable, "forward");
|
||||
manager.println("before");
|
||||
th.start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user