Fixed tests

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2017-11-18 08:13:51 -05:00
parent e5d5edcf63
commit d32ea6b4b0
7 changed files with 317 additions and 229 deletions

View File

@@ -63,7 +63,7 @@ public class CommandTestingApplication implements AutoCloseable {
/** @throws IOException if the streams cannot be build */
public CommandTestingApplication() throws IOException {
out = new PipedConsoleOutput();
in = new PipedConsoleInput();
in = new PipedConsoleInput(null);
application = new ConsoleApplication(out, in, "", "");
new ConsoleTestApplication().attach(application);
th = new Thread(new Runnable() {

View File

@@ -44,7 +44,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
@@ -72,8 +78,13 @@ public class ConsoleApplicationTest {
@Test
public void testConsoleApplication() {
try (PipedConsoleInput manager = new PipedConsoleInput()) {
final ConsoleApplication app = new ConsoleApplication(null, manager,
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 ConsoleApplication app = new ConsoleApplication(null, in,
"", "");
app.exit();
} catch (final IOException e) {
@@ -146,7 +157,12 @@ public class ConsoleApplicationTest {
ConsoleApplication appli = null;
try (PipedConsoleOutput manager = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 ConsoleApplication app = new ConsoleApplication(manager, in,
null, null);
appli = app;
@@ -176,7 +192,7 @@ public class ConsoleApplicationTest {
@Test
public void testInterpretCommand() throws InvalidCommandName, IOException {
try (PipedConsoleInput test = new PipedConsoleInput();
try (PipedConsoleInput test = new PipedConsoleInput(null);
PipedConsoleOutput out = new PipedConsoleOutput()) {
final ConsoleApplication appl = new ConsoleApplication(out, test,
"", "");

View File

@@ -44,7 +44,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
@@ -425,7 +431,12 @@ public class ParametrizedCommandTest {
}
// TODO Test of interactive not providing and providing all needed
try (PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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))) {
cmd = new ParametrizedCommand("name", false) {
{
try {
@@ -468,15 +479,15 @@ public class ParametrizedCommandTest {
public void run() {
try {
assertEquals("value of " + str1 + "? ",
in.readNextLine());
buf.readLine());
in.type("");
assertEquals(
"value of " + str1 + "? (cannot be empty) ",
in.readNextLine());
buf.readLine());
in.type("");
assertEquals(
"value of " + str1 + "? (cannot be empty) ",
in.readNextLine());
buf.readLine());
in.type(str2);
} catch (final IOException e) {
assertNull(e);
@@ -495,7 +506,7 @@ public class ParametrizedCommandTest {
public void run() {
try {
assertEquals("value of " + str1 + "? ",
in.readNextLine());
buf.readLine());
in.type(str2);
} catch (final IOException e) {
assertNull(e);
@@ -510,7 +521,7 @@ public class ParametrizedCommandTest {
}
try {
final PipedConsoleOutput out = new PipedConsoleOutput();
final PipedConsoleInput test = new PipedConsoleInput();
final PipedConsoleInput test = new PipedConsoleInput(null);
cmd = new ParametrizedCommand("name") {
{
try {

View File

@@ -69,7 +69,7 @@ public class ScriptExecutionTest {
PipedConsoleOutput test;
PipedConsoleInput in;
try {
in = new PipedConsoleInput();
in = new PipedConsoleInput(null);
test = new PipedConsoleOutput();
} catch (final IOException e2) {
fail("creation of console manager failed"); //$NON-NLS-1$

View File

@@ -43,7 +43,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -80,7 +86,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptBoolean() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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() {
@Override
@@ -101,16 +112,16 @@ public class CLIPrompterTest {
}
});
th.start();
assertTrue(in.readNextLine().startsWith("My message")); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type(""); //$NON-NLS-1$
out.readNextLine();
assertTrue(in.readNextLine().startsWith("My message")); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("Y"); //$NON-NLS-1$
assertTrue(in.readNextLine().startsWith("My message")); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("yes"); //$NON-NLS-1$
assertTrue(in.readNextLine().startsWith("My message")); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("N"); //$NON-NLS-1$
assertTrue(in.readNextLine().startsWith("My message")); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("nO"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -125,7 +136,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptChoiceConsoleManagerListOfStringListOfUStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<String> keys = new ArrayList<>();
final List<Object> choices = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -140,12 +156,15 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(choices.get(0), CLIPrompter.promptChoice(
out, in, keys, choices, message, cancel));
assertEquals(choices.get(0), CLIPrompter.promptChoice(
out, in, keys, choices, message, null));
assertEquals(null, 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, 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();
@@ -158,7 +177,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1)));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -171,14 +190,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1)));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -188,7 +207,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
@@ -196,7 +215,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1)));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -208,7 +227,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
final Map<Object, Object> choices = new HashMap<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -223,14 +247,17 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(choices.get(keys.get(0)),
CLIPrompter.promptChoice(out, in, keys,
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));
assertEquals(choices.get(keys.get(0)),
CLIPrompter.promptChoice(out, in, keys,
choices, message, null));
assertEquals(null, CLIPrompter.promptChoice(out, in,
keys, choices, message, cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
@@ -243,7 +270,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -256,14 +283,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -273,7 +300,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
@@ -281,7 +308,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -293,7 +320,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptChoiceConsoleManagerListOfUStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
keys.add("An other"); //$NON-NLS-1$
@@ -305,15 +337,18 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(Integer.valueOf(0),
CLIPrompter.promptChoice(out, in, keys,
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));
assertEquals(Integer.valueOf(0), CLIPrompter
.promptChoice(out, in, keys, message, null));
assertEquals(Integer.valueOf(1), CLIPrompter
.promptChoice(out, in, keys, message, null));
assertEquals(null, CLIPrompter.promptChoice(out, in,
keys, message, cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
@@ -326,7 +361,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -339,14 +374,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -356,14 +391,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Success do it again
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("1"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
@@ -371,7 +406,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -385,7 +420,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptChoiceConsoleManagerMapOfUTStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
final Map<Object, Object> choices = new HashMap<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -400,14 +440,17 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(choices.get(keys.get(0)),
CLIPrompter.promptChoice(out, in, keys,
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));
assertEquals(choices.get(keys.get(0)),
CLIPrompter.promptChoice(out, in, keys,
choices, message, null));
assertEquals(null, CLIPrompter.promptChoice(out, in,
keys, choices, message, cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
@@ -422,7 +465,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -435,14 +478,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -452,7 +495,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
@@ -460,7 +503,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertTrue(out.readNextLine().contains(cancel));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -473,16 +516,23 @@ public class CLIPrompterTest {
* {@link fr.bigeon.gclc.prompt.CLIPrompter#promptInteger(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String)}. */
@Test
public final void testPromptInteger() {
try (final PipedConsoleInput test = new PipedConsoleInput()) {
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() {
@Override
public void run() {
try {
assertEquals(10,
CLIPrompter.promptInteger(test, "My message")); //$NON-NLS-1$
assertEquals(-15,
CLIPrompter.promptInteger(test, "My message")); //$NON-NLS-1$
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();
@@ -490,14 +540,14 @@ public class CLIPrompterTest {
}
});
th.start();
assertTrue(test.readNextLine().startsWith("My message")); //$NON-NLS-1$
test.type(""); //$NON-NLS-1$
assertTrue(test.readNextLine().startsWith("My message")); //$NON-NLS-1$
test.type("Y"); //$NON-NLS-1$
assertTrue(test.readNextLine().startsWith("My message")); //$NON-NLS-1$
test.type("10"); //$NON-NLS-1$
assertTrue(test.readNextLine().startsWith("My message")); //$NON-NLS-1$
test.type("-15"); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type(""); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("Y"); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
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) {
@@ -511,7 +561,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptListConsoleManagerString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<String> keys = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
keys.add("An other"); //$NON-NLS-1$
@@ -522,10 +577,11 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(new ArrayList<String>(),
CLIPrompter.promptList(out, in, message));
assertEquals(keys,
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();
@@ -539,7 +595,7 @@ public class CLIPrompterTest {
.getString("promptlist.exit.dispkey", CLIPrompterMessages //$NON-NLS-1$
.getString("promptlist.exit.defaultkey")))); //$NON-NLS-1$
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type(CLIPrompterMessages
.getString("promptlist.exit.defaultkey")); //$NON-NLS-1$
// enter keys list
@@ -549,11 +605,11 @@ public class CLIPrompterTest {
.getString("promptlist.exit.dispkey", CLIPrompterMessages //$NON-NLS-1$
.getString("promptlist.exit.defaultkey")))); //$NON-NLS-1$
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
for (int i = 0; i < keys.size(); i++) {
in.type(keys.get(i));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
}
in.type(CLIPrompterMessages
.getString("promptlist.exit.defaultkey")); //$NON-NLS-1$
@@ -569,7 +625,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptListConsoleManagerStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<String> keys = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
keys.add("An other"); //$NON-NLS-1$
@@ -581,10 +642,12 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals(new ArrayList<String>(), CLIPrompter
.promptList(out, in, message, ender));
assertEquals(keys, CLIPrompter.promptList(out, in,
message, ender));
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();
@@ -597,7 +660,7 @@ public class CLIPrompterTest {
assertTrue(nLine.endsWith(CLIPrompterMessages
.getString("promptlist.exit.dispkey", ender))); //$NON-NLS-1$
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type(ender);
// enter keys list
nLine = out.readNextLine();
@@ -605,11 +668,11 @@ public class CLIPrompterTest {
assertTrue(nLine.endsWith(CLIPrompterMessages
.getString("promptlist.exit.dispkey", ender))); //$NON-NLS-1$
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
for (int i = 0; i < keys.size(); i++) {
in.type(keys.get(i));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
}
in.type(ender);
th.join();
@@ -624,7 +687,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptLongTextConsoleManagerString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 String message = "My message";
final String longText = "Some text with" + System.lineSeparator() +
"line feeds and other" +
@@ -637,11 +705,12 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals("", CLIPrompter.promptLongText(out, in,
message));
assertEquals(longText + System.lineSeparator(),
CLIPrompter.promptLongText(out, in,
message));
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();
@@ -655,7 +724,7 @@ public class CLIPrompterTest {
"promptlongtext.exit.dispkey", CLIPrompterMessages
.getString("promptlongtext.exit.defaultkey"))));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
in.type(CLIPrompterMessages
.getString("promptlongtext.exit.defaultkey"));
// enter long text
@@ -665,12 +734,12 @@ public class CLIPrompterTest {
"promptlongtext.exit.dispkey", CLIPrompterMessages
.getString("promptlongtext.exit.defaultkey"))));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
final String[] text = longText.split(System.lineSeparator());
for (final String element : text) {
in.type(element);
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
}
in.type(CLIPrompterMessages
.getString("promptlongtext.exit.defaultkey"));
@@ -686,7 +755,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptLongTextConsoleManagerStringString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 String message = "My message";
final String ender = "\\quit";
final String[] text = new String[] {"Some text with",
@@ -699,10 +773,11 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertEquals("", //$NON-NLS-1$
CLIPrompter.promptLongText(out, in, message,
assertEquals("Asserted provided value to be retrieved", //$NON-NLS-1$
"", CLIPrompter.promptLongText(out, in, message,
ender));
assertEquals(longText + System.lineSeparator(),
assertEquals("Asserted provided value to be retrieved",
longText + System.lineSeparator(),
CLIPrompter.promptLongText(out, in, message,
ender));
} catch (final IOException e) {
@@ -717,7 +792,7 @@ public class CLIPrompterTest {
assertTrue(nLine.endsWith(CLIPrompterMessages
.getString("promptlongtext.exit.dispkey", ender)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
in.type(ender);
// enter long text
nLine = out.readNextLine();
@@ -725,11 +800,11 @@ public class CLIPrompterTest {
assertTrue(nLine.endsWith(CLIPrompterMessages
.getString("promptlongtext.exit.dispkey", ender)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
for (final String element : text) {
in.type(element);
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"),
in.readNextLine());
buf.readLine());
}
in.type(ender);
th.join();
@@ -744,7 +819,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptMultiChoiceConsoleManagerListOfStringListOfUString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<String> keys = new ArrayList<>();
final List<Object> choices = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -758,15 +838,18 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertTrue(CLIPrompter.promptMultiChoice(out, in,
keys, choices, message).isEmpty());
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(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
assertEquals("Asserted provided value to be retrieved",
l, CLIPrompter.promptMultiChoice(out, in, keys,
choices, message));
l.add(choices.get(1));
assertEquals(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
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();
@@ -778,7 +861,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -790,14 +873,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type(""); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -807,14 +890,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0)));
assertTrue(out.readNextLine().contains(keys.get(1)));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -828,7 +911,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptMultiChoiceConsoleManagerListOfUMapOfUTString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
final Map<Object, Object> choices = new HashMap<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -842,15 +930,18 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertTrue(CLIPrompter.promptMultiChoice(out, in,
keys, choices, message).isEmpty());
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(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
assertEquals("Asserted provided value to be retrieved",
l, CLIPrompter.promptMultiChoice(out, in, keys,
choices, message));
l.add(choices.get(keys.get(1)));
assertEquals(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
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();
@@ -862,7 +953,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -874,14 +965,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type(""); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -891,14 +982,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -912,7 +1003,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptMultiChoiceConsoleManagerListOfUString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
keys.add("A choice"); //$NON-NLS-1$
keys.add("An other"); //$NON-NLS-1$
@@ -923,16 +1019,18 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertTrue(CLIPrompter
.promptMultiChoice(out, in, keys, message)
.isEmpty());
assertTrue("Asserted provided value to be retrieved",
CLIPrompter.promptMultiChoice(out, in, keys,
message).isEmpty());
final ArrayList<Integer> l = new ArrayList<>();
l.add(0);
assertEquals(l, CLIPrompter.promptMultiChoice(out, in,
keys, message));
assertEquals("Asserted provided value to be retrieved",
l, CLIPrompter.promptMultiChoice(out, in, keys,
message));
l.add(1);
assertEquals(l, CLIPrompter.promptMultiChoice(out, in,
keys, message));
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();
@@ -944,7 +1042,7 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("yoyo"); //$NON-NLS-1$
// fail, reprompt
final String msg = CLIPrompterMessages.getString(
@@ -956,14 +1054,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type(""); //$NON-NLS-1$
// Sucess, reprompt without cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("2"); //$NON-NLS-1$
// fail, reprompt
assertEquals(
@@ -973,14 +1071,14 @@ public class CLIPrompterTest {
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0"); //$NON-NLS-1$
// Sucess, prompt with cancel
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
assertTrue(out.readNextLine().contains(keys.get(1).toString()));
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
in.readNextLine());
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
@@ -994,7 +1092,12 @@ public class CLIPrompterTest {
@Test
public final void testPromptMultiChoiceConsoleManagerMapOfUTString() {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedConsoleInput in = new PipedConsoleInput()) {
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 List<Object> keys = new ArrayList<>();
final Map<Object, Object> choices = new HashMap<>();
keys.add("A choice"); //$NON-NLS-1$
@@ -1008,15 +1111,18 @@ public class CLIPrompterTest {
@Override
public void run() {
try {
assertTrue(CLIPrompter.promptMultiChoice(out, in, keys,
choices, message).isEmpty());
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(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
assertEquals("Asserted provided value to be retrieved",
l, CLIPrompter.promptMultiChoice(out, in, keys,
choices, message));
l.add(choices.get(keys.get(1)));
assertEquals(l, CLIPrompter.promptMultiChoice(out, in,
keys, choices, message));
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();
@@ -1069,15 +1175,21 @@ public class CLIPrompterTest {
* {@link fr.bigeon.gclc.prompt.CLIPrompter#promptNonEmpty(fr.bigeon.gclc.manager.ConsoleManager, java.lang.String, java.lang.String)}. */
@Test
public final void testPromptNonEmpty() {
try (final PipedConsoleInput test = new PipedConsoleInput()) {
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 String res = "some content"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
@Override
public void run() {
try {
assertEquals(res, CLIPrompter.promptNonEmpty(test,
"My message", "my reprompt")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Expected provided message to be returned",
res, CLIPrompter.promptNonEmpty(in,
"My message", "my reprompt")); //$NON-NLS-1$ //$NON-NLS-2$
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
@@ -1085,10 +1197,10 @@ public class CLIPrompterTest {
}
});
th.start();
assertTrue(test.readNextLine().startsWith("My message")); //$NON-NLS-1$
test.type(""); //$NON-NLS-1$
assertTrue(test.readNextLine().startsWith("my reprompt")); //$NON-NLS-1$
test.type(res);
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type(""); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("my reprompt")); //$NON-NLS-1$
in.type(res);
th.join();
} catch (IOException | InterruptedException e) {