Fix test and wait
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
2a05366e31
commit
4301f2a15e
@ -102,7 +102,7 @@ public final class CommandParameters {
|
|||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @return if the key was specified */
|
* @return if the key was specified */
|
||||||
public boolean getBool(final String key) {
|
public boolean isActive(final String key) {
|
||||||
Boolean val = booleanArguments.get(key);
|
Boolean val = booleanArguments.get(key);
|
||||||
return val != null && val.booleanValue();
|
return val != null && val.booleanValue();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import net.bigeon.gclc.exception.CommandParsingException;
|
import net.bigeon.gclc.exception.CommandParsingException;
|
||||||
import net.bigeon.gclc.exception.InvalidParameterException;
|
import net.bigeon.gclc.exception.InvalidParameterException;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.EmptyInput;
|
import net.bigeon.gclc.utils.EmptyInput;
|
||||||
|
|
||||||
/** An object to handle standardized command parameters.
|
/** An object to handle standardized command parameters.
|
||||||
*
|
*
|
||||||
|
@ -70,6 +70,7 @@ package net.bigeon.gclc.prompt;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -162,33 +163,27 @@ public final class CLIPrompter {
|
|||||||
* @throws IOException if the manager was closed */
|
* @throws IOException if the manager was closed */
|
||||||
public static boolean promptBoolean(final ConsoleOutput manager,
|
public static boolean promptBoolean(final ConsoleOutput manager,
|
||||||
final ConsoleInput input, final String message) throws IOException {
|
final ConsoleInput input, final String message) throws IOException {
|
||||||
String result = input
|
String booleanChoices = message + CLIPrompterMessages.getString(BOOL_CHOICES);
|
||||||
.prompt(message + CLIPrompterMessages.getString(BOOL_CHOICES));
|
String result = input.prompt(booleanChoices);
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
final String choices = CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_YES1)
|
String booleanYesChoice = CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_YES1);
|
||||||
+ ", " + //$NON-NLS-1$
|
String booleanNoChoice = CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_NO1);
|
||||||
CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_NO1);
|
final String choices = MessageFormat.format("{0}, {1}", booleanYesChoice,
|
||||||
while (!(result
|
booleanNoChoice);
|
||||||
.equalsIgnoreCase(CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_YES1))
|
String yes2 = CLIPrompterMessages.getString("promptbool.choices.yes2");
|
||||||
|| CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_NO1)
|
String no2 = CLIPrompterMessages.getString("promptbool.choices.no2");
|
||||||
.equalsIgnoreCase(result)
|
while (!(result.equalsIgnoreCase(booleanYesChoice)
|
||||||
|| CLIPrompterMessages.getString("promptbool.choices.no2") //$NON-NLS-1$
|
|| booleanNoChoice.equalsIgnoreCase(result)
|
||||||
.equalsIgnoreCase(result)
|
|| no2.equalsIgnoreCase(result) || yes2.equalsIgnoreCase(result))) {
|
||||||
|| CLIPrompterMessages.getString("promptbool.choices.yes2") //$NON-NLS-1$
|
|
||||||
.equalsIgnoreCase(result))) {
|
|
||||||
if (!first) {
|
if (!first) {
|
||||||
|
|
||||||
manager.println(CLIPrompterMessages
|
manager.println(CLIPrompterMessages
|
||||||
.getString("promptbool.choices.invalid", choices)); //$NON-NLS-1$
|
.getString("promptbool.choices.invalid", choices)); //$NON-NLS-1$
|
||||||
result = input
|
result = input.prompt(booleanChoices);
|
||||||
.prompt(message + CLIPrompterMessages.getString(BOOL_CHOICES));
|
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
return result
|
return result.equalsIgnoreCase(booleanYesChoice) || result.equalsIgnoreCase(yes2); // $NON-NLS-1$
|
||||||
.equalsIgnoreCase(CLIPrompterMessages.getString(PROMPTBOOL_CHOICES_YES1))
|
|
||||||
|| result.equalsIgnoreCase(
|
|
||||||
CLIPrompterMessages.getString("promptbool.choices.yes2")); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prompt for a choice.
|
/** Prompt for a choice.
|
||||||
|
@ -36,7 +36,9 @@
|
|||||||
* gclc:net.bigeon.gclc.manager.EmptyInput.java
|
* gclc:net.bigeon.gclc.manager.EmptyInput.java
|
||||||
* Created on: Nov 13, 2017
|
* Created on: Nov 13, 2017
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.manager;
|
package net.bigeon.gclc.utils;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@ -80,6 +82,7 @@ import net.bigeon.gclc.tools.StringProvider;
|
|||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class EmptyInput implements ConsoleInput {
|
public final class EmptyInput implements ConsoleInput {
|
||||||
|
|
||||||
|
private static final ConstantString CONSTANT_STRING = new ConstantString("");
|
||||||
/** The empty prompter. */
|
/** The empty prompter. */
|
||||||
public static final ConsoleInput INSTANCE = new EmptyInput();
|
public static final ConsoleInput INSTANCE = new EmptyInput();
|
||||||
|
|
||||||
@ -99,7 +102,7 @@ public final class EmptyInput implements ConsoleInput {
|
|||||||
* @see net.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
* @see net.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
||||||
@Override
|
@Override
|
||||||
public StringProvider getPrompt() {
|
public StringProvider getPrompt() {
|
||||||
return new ConstantString(""); //$NON-NLS-1$
|
return CONSTANT_STRING; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
@ -143,10 +143,10 @@ public final class PipedConsoleOutput implements ConsoleOutput {
|
|||||||
* may not</em> be the next line of data.
|
* may not</em> be the next line of data.
|
||||||
*
|
*
|
||||||
* @param message the message
|
* @param message the message
|
||||||
* @return the thread to join to wait for message delivery
|
* @throws InterruptedException if the wait on the message was interrupted
|
||||||
* @see net.bigeon.gclc.utils.ReadingRunnable#getWaitForDelivery(java.lang.String) */
|
* @see net.bigeon.gclc.utils.ReadingRunnable#waitForDelivery(String) */
|
||||||
public Thread getWaitForDelivery(final String message) {
|
public void waitForDelivery(final String message) throws InterruptedException {
|
||||||
return reading.getWaitForDelivery(message);
|
reading.waitForDelivery(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -86,64 +86,6 @@ import java.util.logging.Logger;
|
|||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class ReadingRunnable implements Runnable {
|
public final class ReadingRunnable implements Runnable {
|
||||||
|
|
||||||
/** The runnable to wait for arrival of a message in the queue.
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
private final class ToWaitRunnable implements Runnable {
|
|
||||||
/** The Object. */
|
|
||||||
private final Object obj;
|
|
||||||
/** The locking object. */
|
|
||||||
private final Object start;
|
|
||||||
/** The message. */
|
|
||||||
private final String message;
|
|
||||||
/** The started status. */
|
|
||||||
private boolean started;
|
|
||||||
|
|
||||||
/** Create the waiting runnable.
|
|
||||||
*
|
|
||||||
* @param obj the object to lock on
|
|
||||||
* @param start the object to notify when ready to wait
|
|
||||||
* @param message the message to wait for */
|
|
||||||
public ToWaitRunnable(final Object obj, final Object start,
|
|
||||||
final String message) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.start = start;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test if the waiting runnable is started.
|
|
||||||
*
|
|
||||||
* @return the started */
|
|
||||||
public boolean isStarted() {
|
|
||||||
synchronized (start) {
|
|
||||||
return started;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Runnable#run() */
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
synchronized (obj) {
|
|
||||||
synchronized (start) {
|
|
||||||
started = true;
|
|
||||||
start.notifyAll();
|
|
||||||
}
|
|
||||||
while (isRunning()) {
|
|
||||||
try {
|
|
||||||
obj.wait();
|
|
||||||
if (delivering.equals(message)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The thread intteruption logging message. */
|
/** The thread intteruption logging message. */
|
||||||
private static final String THREAD_INTERRUPTION_EXCEPTION = "Thread interruption exception."; //$NON-NLS-1$
|
private static final String THREAD_INTERRUPTION_EXCEPTION = "Thread interruption exception."; //$NON-NLS-1$
|
||||||
/** The closed pipe message. */
|
/** The closed pipe message. */
|
||||||
@ -169,9 +111,6 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
private final Map<String, Object> messageBlocker = new ConcurrentHashMap<>();
|
private final Map<String, Object> messageBlocker = new ConcurrentHashMap<>();
|
||||||
/** The lock. */
|
/** The lock. */
|
||||||
private final Object messageBlockerLock = new Object();
|
private final Object messageBlockerLock = new Object();
|
||||||
/** The message being delivered. */
|
|
||||||
private String delivering;
|
|
||||||
|
|
||||||
/** Create a reading runnable.
|
/** Create a reading runnable.
|
||||||
*
|
*
|
||||||
* @param reader the input to read from */
|
* @param reader the input to read from */
|
||||||
@ -238,33 +177,16 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a waiting thread for a specific message delivery.
|
public void waitForDelivery(String message) throws InterruptedException {
|
||||||
*
|
Object mLock;
|
||||||
* @param message the message
|
|
||||||
* @return the thread to join to wait for message delivery */
|
|
||||||
public Thread getWaitForDelivery(final String message) {
|
|
||||||
synchronized (messageBlockerLock) {
|
synchronized (messageBlockerLock) {
|
||||||
if (!messageBlocker.containsKey(message)) {
|
if (!messageBlocker.containsKey(message)) {
|
||||||
messageBlocker.put(message, new Object());
|
messageBlocker.put(message, new Object());
|
||||||
}
|
}
|
||||||
final Object obj = messageBlocker.get(message);
|
mLock = messageBlocker.get(message);
|
||||||
final Object start = new Object();
|
}
|
||||||
final ToWaitRunnable waitRunn = new ToWaitRunnable(obj, start, message);
|
synchronized (mLock) {
|
||||||
final Thread th = new Thread(waitRunn);
|
mLock.wait();
|
||||||
|
|
||||||
// Wait for the thread to actually start before unlocking the message queue.
|
|
||||||
synchronized (start) {
|
|
||||||
th.start();
|
|
||||||
while (!waitRunn.isStarted()) {
|
|
||||||
try {
|
|
||||||
start.wait(TIMEOUT);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return th;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +227,6 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
* @param message the message */
|
* @param message the message */
|
||||||
private void notifyMessage(final String message) {
|
private void notifyMessage(final String message) {
|
||||||
synchronized (messageBlockerLock) {
|
synchronized (messageBlockerLock) {
|
||||||
delivering = message;
|
|
||||||
final Object mLock = messageBlocker.get(message);
|
final Object mLock = messageBlocker.get(message);
|
||||||
if (mLock!=null) {
|
if (mLock!=null) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
@ -154,7 +154,8 @@ public class CommandParametersTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.command.CommandParameters#getAdditionals()}. */
|
* {@link net.bigeon.gclc.command.CommandParameters#getAdditionals()}.
|
||||||
|
* @throws CommandParsingException if the parameter parsing failed*/
|
||||||
@Test
|
@Test
|
||||||
public final void testGetAdditionals() throws CommandParsingException {
|
public final void testGetAdditionals() throws CommandParsingException {
|
||||||
final Set<String> strings = new HashSet<>();
|
final Set<String> strings = new HashSet<>();
|
||||||
@ -187,7 +188,7 @@ public class CommandParametersTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.command.CommandParameters#getBool(java.lang.String)}.
|
* {@link net.bigeon.gclc.command.CommandParameters#isActive(String)}.
|
||||||
*
|
*
|
||||||
* @throws CommandParsingException if a command parsing failed */
|
* @throws CommandParsingException if a command parsing failed */
|
||||||
@Test
|
@Test
|
||||||
@ -200,12 +201,12 @@ public class CommandParametersTest {
|
|||||||
|
|
||||||
CommandParameters parameters = new CommandParameters(bools, strings, true);
|
CommandParameters parameters = new CommandParameters(bools, strings, true);
|
||||||
|
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertFalse(parameters.getBool("boolFlag"));
|
assertFalse(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
parameters.parseArgs("-boolFlag");
|
parameters.parseArgs("-boolFlag");
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parameters.parseArgs("-ungiven");
|
parameters.parseArgs("-ungiven");
|
||||||
@ -213,29 +214,29 @@ public class CommandParametersTest {
|
|||||||
} catch (final CommandParsingException e) {
|
} catch (final CommandParsingException e) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
parameters = new CommandParameters(bools, strings, false);
|
parameters = new CommandParameters(bools, strings, false);
|
||||||
|
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertFalse(parameters.getBool("boolFlag"));
|
assertFalse(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parameters.parseArgs("-boolFlag");
|
parameters.parseArgs("-boolFlag");
|
||||||
} catch (final CommandParsingException e) {
|
} catch (final CommandParsingException e) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parameters.parseArgs("-ungiven");
|
parameters.parseArgs("-ungiven");
|
||||||
} catch (final CommandParsingException e) {
|
} catch (final CommandParsingException e) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
@ -281,29 +282,29 @@ public class CommandParametersTest {
|
|||||||
|
|
||||||
CommandParameters parameters = new CommandParameters(bools, strings, true);
|
CommandParameters parameters = new CommandParameters(bools, strings, true);
|
||||||
|
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertFalse(parameters.getBool("boolFlag"));
|
assertFalse(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
parameters.set("boolFlag", true);
|
parameters.set("boolFlag", true);
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
|
|
||||||
parameters.set("ungiven", true);
|
parameters.set("ungiven", true);
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
parameters = new CommandParameters(bools, strings, false);
|
parameters = new CommandParameters(bools, strings, false);
|
||||||
|
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertFalse(parameters.getBool("boolFlag"));
|
assertFalse(parameters.isActive("boolFlag"));
|
||||||
|
|
||||||
parameters.set("boolFlag", true);
|
parameters.set("boolFlag", true);
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
|
|
||||||
parameters.set("ungiven", true);
|
parameters.set("ungiven", true);
|
||||||
assertFalse(parameters.getBool("ungiven"));
|
assertFalse(parameters.isActive("ungiven"));
|
||||||
assertTrue(parameters.getBool("boolFlag"));
|
assertTrue(parameters.isActive("boolFlag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package net.bigeon.gclc.command;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.exception.InvalidParameterException;
|
||||||
|
|
||||||
|
public class ParametrizedCommandDataTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddParameter() throws InvalidParameterException {
|
||||||
|
ParametrizedCommandData data = new ParametrizedCommandData();
|
||||||
|
data.addBooleanParameter("flag");
|
||||||
|
data.addStringParameter("arg", false);
|
||||||
|
try {
|
||||||
|
data.addBooleanParameter("arg");
|
||||||
|
fail("String parameter cannot be converted to flag");
|
||||||
|
} catch (InvalidParameterException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
data.addStringParameter("flag", false);
|
||||||
|
fail("Flag parameter cannot be converted to string");
|
||||||
|
} catch (InvalidParameterException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -241,22 +241,22 @@ public class ParametrizedCommandTest {
|
|||||||
case 3:
|
case 3:
|
||||||
assertNull(parameters.get(str1));
|
assertNull(parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertFalse(parameters.getBool(bool1));
|
assertFalse(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call++;
|
call++;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
assertEquals(str2, parameters.get(str1));
|
assertEquals(str2, parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertFalse(parameters.getBool(bool1));
|
assertFalse(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call++;
|
call++;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
assertEquals(str2, parameters.get(str1));
|
assertEquals(str2, parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertTrue(parameters.getBool(bool1));
|
assertTrue(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call = 0;
|
call = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -304,22 +304,22 @@ public class ParametrizedCommandTest {
|
|||||||
case 0:
|
case 0:
|
||||||
assertNull(parameters.get(str1));
|
assertNull(parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertFalse(parameters.getBool(bool1));
|
assertFalse(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call++;
|
call++;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
assertEquals(str2, parameters.get(str1));
|
assertEquals(str2, parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertFalse(parameters.getBool(bool1));
|
assertFalse(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call++;
|
call++;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
assertEquals(str2, parameters.get(str1));
|
assertEquals(str2, parameters.get(str1));
|
||||||
assertNull(parameters.get(str2));
|
assertNull(parameters.get(str2));
|
||||||
assertTrue(parameters.getBool(bool1));
|
assertTrue(parameters.isActive(bool1));
|
||||||
assertFalse(parameters.getBool(bool2));
|
assertFalse(parameters.isActive(bool2));
|
||||||
call = 0;
|
call = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -118,7 +118,7 @@ public class ReadingRunnableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.utils.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
* {@link net.bigeon.gclc.utils.ReadingRunnable#waitForDelivery(String)}.
|
||||||
*
|
*
|
||||||
* @throws InterruptedException if the test failed
|
* @throws InterruptedException if the test failed
|
||||||
* @throws IOException if the test failed */
|
* @throws IOException if the test failed */
|
||||||
@ -131,7 +131,19 @@ public class ReadingRunnableTest {
|
|||||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
final Thread th0 = new Thread(runnable, "read");
|
final Thread th0 = new Thread(runnable, "read");
|
||||||
th0.start();
|
th0.start();
|
||||||
final Thread th = runnable.getWaitForDelivery("msg");
|
Thread th = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
runnable.waitForDelivery("msg");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
th.start();
|
||||||
|
|
||||||
out.write(Charset.forName("UTF-8").encode("msg" + System.lineSeparator())
|
out.write(Charset.forName("UTF-8").encode("msg" + System.lineSeparator())
|
||||||
.array());
|
.array());
|
||||||
|
67
gclc/src/test/java/net/bigeon/gclc/utils/EmptyInputTest.java
Normal file
67
gclc/src/test/java/net/bigeon/gclc/utils/EmptyInputTest.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package net.bigeon.gclc.utils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
import net.bigeon.gclc.utils.EmptyInput;
|
||||||
|
|
||||||
|
public class EmptyInputTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClose() throws IOException {
|
||||||
|
ConsoleInput input = EmptyInput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
input.close();
|
||||||
|
input.close();
|
||||||
|
assertFalse("This source input should never be closed", input.isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPrompt() {
|
||||||
|
|
||||||
|
ConsoleInput input = EmptyInput.INSTANCE;
|
||||||
|
String init = input.getPrompt().apply();
|
||||||
|
input.setPrompt("some prompt different from "+init);
|
||||||
|
assertEquals("Prompts should not be changed", init, input.getPrompt().apply());
|
||||||
|
|
||||||
|
input.setPrompt(new ConstantString("some other prompt different from "+init));
|
||||||
|
assertEquals("Prompts should not be changed", init, input.getPrompt().apply());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterruptPrompt() {
|
||||||
|
// Nothing to test, really...
|
||||||
|
ConsoleInput input = EmptyInput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
input.interruptPrompt();
|
||||||
|
assertFalse("This source input should never be closed", input.isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsClosed() throws IOException {
|
||||||
|
ConsoleInput input = EmptyInput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
assertFalse("This source input should never be closed", input.isClosed());
|
||||||
|
input.close();
|
||||||
|
assertFalse("This source input should never be closed", input.isClosed());
|
||||||
|
input.close();
|
||||||
|
assertFalse("This source input should never be closed", input.isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrompt() throws IOException {
|
||||||
|
ConsoleInput input = EmptyInput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt());
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt(0));
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt(12));
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt("Test"));
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt("Test", 0));
|
||||||
|
assertEquals("Any prompt should return the empty value", "", input.prompt("Test", 12));
|
||||||
|
}
|
||||||
|
}
|
31
gclc/src/test/java/net/bigeon/gclc/utils/SinkOutputTest.java
Normal file
31
gclc/src/test/java/net/bigeon/gclc/utils/SinkOutputTest.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package net.bigeon.gclc.utils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
|
|
||||||
|
public class SinkOutputTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClose() throws Exception {
|
||||||
|
ConsoleOutput output = SinkOutput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
output.close();
|
||||||
|
output.close();
|
||||||
|
assertFalse("This source input should never be closed", output.isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrint() throws IOException {
|
||||||
|
ConsoleOutput output = SinkOutput.INSTANCE;
|
||||||
|
// several close operation shold create no error
|
||||||
|
output.print("Anything");
|
||||||
|
output.println("Anything");
|
||||||
|
output.println();
|
||||||
|
assertFalse("This source input should never be closed", output.isClosed());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user