|
|
|
|
@@ -95,6 +95,8 @@ import org.junit.Test;
|
|
|
|
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
|
|
|
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
|
|
|
|
import net.bigeon.test.junitmt.ATestRunnable;
|
|
|
|
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
|
|
|
|
import net.bigeon.test.junitmt.TestFunction;
|
|
|
|
|
import net.bigeon.test.junitmt.ThreadTest;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -128,20 +130,17 @@ public class CLIPrompterTest {
|
|
|
|
|
BufferedReader buf = new BufferedReader(
|
|
|
|
|
new InputStreamReader(pis, StandardCharsets.UTF_8));
|
|
|
|
|
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
|
|
|
|
|
final ATestRunnable target = new ATestRunnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testRun() {
|
|
|
|
|
try {
|
|
|
|
|
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
|
|
|
|
|
@@ -161,9 +160,12 @@ public class CLIPrompterTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if an IO occurred */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfStringListOfUStringString() {
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfStringListOfUStringString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -179,26 +181,23 @@ public class CLIPrompterTest {
|
|
|
|
|
final String cancel = "Cancel"; //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(0), CLIPrompter.promptChoice(out, in, keys,
|
|
|
|
|
choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(0), CLIPrompter.promptChoice(out, in, keys,
|
|
|
|
|
choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(0), CLIPrompter.promptChoice(out, in, keys,
|
|
|
|
|
choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(0), CLIPrompter.promptChoice(out, in, keys,
|
|
|
|
|
choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0)));
|
|
|
|
|
@@ -242,15 +241,13 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("2"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString() {
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -265,27 +262,23 @@ public class CLIPrompterTest {
|
|
|
|
|
choices.put(keys.get(1), "The actual 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() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
|
|
|
|
|
in, keys, choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
|
|
|
|
|
in, keys, choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
|
|
|
|
|
keys, choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
|
|
|
|
|
keys, choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
|
|
|
|
|
@@ -329,15 +322,13 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("2"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfUStringString() {
|
|
|
|
|
public final void testPromptChoiceConsoleManagerListOfUStringString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -349,29 +340,26 @@ public class CLIPrompterTest {
|
|
|
|
|
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() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(0),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(0),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(1),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, cancel));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(0),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(0),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
Integer.valueOf(1),
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, message, cancel));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
|
|
|
|
|
@@ -422,17 +410,17 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("2"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, Map, String, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, Map, String, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptChoiceConsoleManagerMapOfUTStringString() {
|
|
|
|
|
public final void testPromptChoiceConsoleManagerMapOfUTStringString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -448,26 +436,23 @@ public class CLIPrompterTest {
|
|
|
|
|
final String cancel = "Cancel"; //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
|
|
|
|
|
in, keys, choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
|
|
|
|
|
in, keys, choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
|
|
|
|
|
keys, choices, message, cancel));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
|
|
|
|
|
keys, choices, message, null));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", null,
|
|
|
|
|
CLIPrompter.promptChoice(out, in, keys, choices, message,
|
|
|
|
|
cancel));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
final String readNextLine = out.readNextLine();
|
|
|
|
|
@@ -513,37 +498,33 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("2"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptInteger(net.bigeon.gclc.manager.ConsoleInput, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptInteger(net.bigeon.gclc.manager.ConsoleInput, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptInteger() {
|
|
|
|
|
public final void testPromptInteger() throws IOException {
|
|
|
|
|
try (PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
BufferedReader buf = new BufferedReader(
|
|
|
|
|
new InputStreamReader(pis, StandardCharsets.UTF_8));
|
|
|
|
|
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", 10,
|
|
|
|
|
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", -15,
|
|
|
|
|
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", 10,
|
|
|
|
|
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", -15,
|
|
|
|
|
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
|
|
|
|
|
in.type(""); //$NON-NLS-1$
|
|
|
|
|
@@ -553,18 +534,16 @@ public class CLIPrompterTest {
|
|
|
|
|
in.type("10"); //$NON-NLS-1$
|
|
|
|
|
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
|
|
|
|
|
in.type("-15"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptListConsoleManagerString() {
|
|
|
|
|
public final void testPromptListConsoleManagerString() throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -576,22 +555,19 @@ public class CLIPrompterTest {
|
|
|
|
|
keys.add("An other"); //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
new ArrayList<String>(),
|
|
|
|
|
CLIPrompter.promptList(out, in, message));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", keys,
|
|
|
|
|
CLIPrompter.promptList(out, in, message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
new ArrayList<String>(),
|
|
|
|
|
CLIPrompter.promptList(out, in, message));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", keys,
|
|
|
|
|
CLIPrompter.promptList(out, in, message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
String nLine = out.readNextLine();
|
|
|
|
|
assertTrue(nLine.startsWith(message));
|
|
|
|
|
@@ -615,17 +591,16 @@ public class CLIPrompterTest {
|
|
|
|
|
buf.readLine());
|
|
|
|
|
}
|
|
|
|
|
in.type(CLIPrompterMessages.getString("promptlist.exit.defaultkey")); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptListConsoleManagerStringString() {
|
|
|
|
|
public final void testPromptListConsoleManagerStringString() throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -638,22 +613,19 @@ public class CLIPrompterTest {
|
|
|
|
|
final String ender = "*"; //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
new ArrayList<String>(),
|
|
|
|
|
CLIPrompter.promptList(out, in, message, ender));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", keys,
|
|
|
|
|
CLIPrompter.promptList(out, in, message, ender));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
new ArrayList<String>(),
|
|
|
|
|
CLIPrompter.promptList(out, in, message, ender));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", keys,
|
|
|
|
|
CLIPrompter.promptList(out, in, message, ender));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
String nLine = out.readNextLine();
|
|
|
|
|
assertTrue(nLine.startsWith(message));
|
|
|
|
|
@@ -675,17 +647,16 @@ public class CLIPrompterTest {
|
|
|
|
|
buf.readLine());
|
|
|
|
|
}
|
|
|
|
|
in.type(ender);
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptLongTextConsoleManagerString() {
|
|
|
|
|
public final void testPromptLongTextConsoleManagerString() throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -697,22 +668,19 @@ public class CLIPrompterTest {
|
|
|
|
|
+ "line feeds and other" + System.lineSeparator()
|
|
|
|
|
+ System.lineSeparator() + " \tspecial characters";
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", "",
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
longText + System.lineSeparator(),
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", "",
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
longText + System.lineSeparator(),
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
String nLine = out.readNextLine();
|
|
|
|
|
assertTrue(nLine.startsWith(message));
|
|
|
|
|
@@ -737,17 +705,16 @@ public class CLIPrompterTest {
|
|
|
|
|
buf.readLine());
|
|
|
|
|
}
|
|
|
|
|
in.type(CLIPrompterMessages.getString("promptlongtext.exit.defaultkey"));
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptLongTextConsoleManagerStringString() {
|
|
|
|
|
public final void testPromptLongTextConsoleManagerStringString() throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -761,22 +728,19 @@ public class CLIPrompterTest {
|
|
|
|
|
final String longText = text[0] + System.lineSeparator() + text[1]
|
|
|
|
|
+ System.lineSeparator() + text[2];
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", //$NON-NLS-1$
|
|
|
|
|
"", CLIPrompter.promptLongText(out, in, message, ender));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
longText + System.lineSeparator(),
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message, ender));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", //$NON-NLS-1$
|
|
|
|
|
"", CLIPrompter.promptLongText(out, in, message, ender));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved",
|
|
|
|
|
longText + System.lineSeparator(),
|
|
|
|
|
CLIPrompter.promptLongText(out, in, message, ender));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
String nLine = out.readNextLine();
|
|
|
|
|
assertTrue(nLine.startsWith(message));
|
|
|
|
|
@@ -798,17 +762,17 @@ public class CLIPrompterTest {
|
|
|
|
|
buf.readLine());
|
|
|
|
|
}
|
|
|
|
|
in.type(ender);
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfStringListOfUString() {
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfStringListOfUString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -823,29 +787,24 @@ public class CLIPrompterTest {
|
|
|
|
|
choices.add("The actual other"); //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved", CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message)
|
|
|
|
|
.isEmpty());
|
|
|
|
|
final ArrayList<Object> l = new ArrayList<>();
|
|
|
|
|
l.add(choices.get(0));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices,
|
|
|
|
|
message));
|
|
|
|
|
l.add(choices.get(1));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices,
|
|
|
|
|
message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved",
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices, message)
|
|
|
|
|
.isEmpty());
|
|
|
|
|
final ArrayList<Object> l = new ArrayList<>();
|
|
|
|
|
l.add(choices.get(0));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message));
|
|
|
|
|
l.add(choices.get(1));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable runnable = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(runnable);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0)));
|
|
|
|
|
@@ -886,17 +845,17 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("0 1"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, runnable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, Map, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, Map, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if errors */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfUMapOfUTString() {
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfUMapOfUTString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -910,30 +869,24 @@ public class CLIPrompterTest {
|
|
|
|
|
keys.add("An other"); //$NON-NLS-1$
|
|
|
|
|
choices.put(keys.get(1), "The actual other"); //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved", CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message)
|
|
|
|
|
.isEmpty());
|
|
|
|
|
final ArrayList<Object> l = new ArrayList<>();
|
|
|
|
|
l.add(choices.get(keys.get(0)));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices,
|
|
|
|
|
message));
|
|
|
|
|
l.add(choices.get(keys.get(1)));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices,
|
|
|
|
|
message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved",
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices, message)
|
|
|
|
|
.isEmpty());
|
|
|
|
|
final ArrayList<Object> l = new ArrayList<>();
|
|
|
|
|
l.add(choices.get(keys.get(0)));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message));
|
|
|
|
|
l.add(choices.get(keys.get(1)));
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
|
|
|
|
|
@@ -974,17 +927,17 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("0 1"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Test method for
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, String)}. */
|
|
|
|
|
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, String)}.
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException if error */
|
|
|
|
|
@Test
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfUString() {
|
|
|
|
|
public final void testPromptMultiChoiceConsoleManagerListOfUString()
|
|
|
|
|
throws IOException {
|
|
|
|
|
try (final PipedConsoleOutput out = new PipedConsoleOutput();
|
|
|
|
|
PipedOutputStream pout = new PipedOutputStream();
|
|
|
|
|
PipedInputStream pis = new PipedInputStream(pout);
|
|
|
|
|
@@ -995,27 +948,23 @@ public class CLIPrompterTest {
|
|
|
|
|
keys.add("A choice"); //$NON-NLS-1$
|
|
|
|
|
keys.add("An other"); //$NON-NLS-1$
|
|
|
|
|
final String message = "My message"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
final Thread th = new Thread(new Runnable() {
|
|
|
|
|
final TestFunction func = new TestFunction() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved", CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, message).isEmpty());
|
|
|
|
|
final ArrayList<Integer> l = new ArrayList<>();
|
|
|
|
|
l.add(0);
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, message));
|
|
|
|
|
l.add(1);
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
public void apply() throws Exception {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved", CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, message).isEmpty());
|
|
|
|
|
final ArrayList<Integer> l = new ArrayList<>();
|
|
|
|
|
l.add(0);
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, message));
|
|
|
|
|
l.add(1);
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, message));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
final ATestRunnable target = new FunctionalTestRunnable(func);
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
th.start();
|
|
|
|
|
assertTrue(out.readNextLine().startsWith(message));
|
|
|
|
|
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
|
|
|
|
|
@@ -1056,10 +1005,7 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
|
|
|
|
|
buf.readLine());
|
|
|
|
|
in.type("0 1"); //$NON-NLS-1$
|
|
|
|
|
th.join();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
fail("Unexpected excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ThreadTest.assertRuns(th, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1084,8 +1030,7 @@ public class CLIPrompterTest {
|
|
|
|
|
final ATestRunnable target = new ATestRunnable() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testRun() {
|
|
|
|
|
try {
|
|
|
|
|
public void testRun() throws IOException {
|
|
|
|
|
assertTrue("Asserted provided value to be retrieved", CLIPrompter
|
|
|
|
|
.promptMultiChoice(out, in, keys, choices, message)
|
|
|
|
|
.isEmpty());
|
|
|
|
|
@@ -1098,10 +1043,6 @@ public class CLIPrompterTest {
|
|
|
|
|
assertEquals("Asserted provided value to be retrieved", l,
|
|
|
|
|
CLIPrompter.promptMultiChoice(out, in, keys, choices,
|
|
|
|
|
message));
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
@@ -1157,14 +1098,10 @@ public class CLIPrompterTest {
|
|
|
|
|
final ATestRunnable target = new ATestRunnable() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testRun() {
|
|
|
|
|
try {
|
|
|
|
|
public void testRun() throws IOException {
|
|
|
|
|
assertEquals("Expected provided message to be returned", res,
|
|
|
|
|
CLIPrompter.promptNonEmpty(in, "My message", //$NON-NLS-1$
|
|
|
|
|
"my reprompt")); //$NON-NLS-1$
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
fail("Unexpected io excpetion"); //$NON-NLS-1$
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
final Thread th = new Thread(target);
|
|
|
|
|
|