[test] Use assert equals
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
b38980eeb5
commit
ea01d346d3
@ -72,7 +72,6 @@ package net.bigeon.gclc;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -87,52 +86,77 @@ import net.bigeon.gclc.exception.CommandParsingException;
|
|||||||
@SuppressWarnings({ "nls", "static-method" })
|
@SuppressWarnings({ "nls", "static-method" })
|
||||||
public class GCLCConstantsTest {
|
public class GCLCConstantsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplitCommandSingle() throws CommandParsingException {
|
||||||
|
List<String> res;
|
||||||
|
res = GCLCConstants.splitCommand("aCommand");
|
||||||
|
assertEquals("single word command should have one element", 1, res.size());
|
||||||
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplitCommandSeveral() throws CommandParsingException {
|
||||||
|
List<String> res;
|
||||||
|
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||||
|
assertEquals("Command size", 4, res.size());
|
||||||
|
assertEquals("Elements should be preserved", "aCommand", res.get(0));
|
||||||
|
assertEquals("Command should be preserved", "with", res.get(1));
|
||||||
|
assertEquals("Command should be preserved", "some", res.get(2));
|
||||||
|
assertEquals("Command should be preserved", "arguments", res.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
||||||
*
|
*
|
||||||
* @throws CommandParsingException if an error occured */
|
* @throws CommandParsingException if an error occured */
|
||||||
@Test
|
@Test
|
||||||
public void testSplitCommand() throws CommandParsingException {
|
public void testSplitCommandMultiSpaces() throws CommandParsingException {
|
||||||
List<String> res;
|
List<String> res;
|
||||||
res = GCLCConstants.splitCommand("aCommand");
|
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||||
assertTrue("single word command should have one element", res.size() == 1);
|
assertEquals("Command size", 4, res.size());
|
||||||
assertTrue("Command should be preserved", res.get(0).equals("aCommand"));
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
|
assertEquals("Command should be preserved", "with", res.get(1));
|
||||||
|
assertEquals("Command should be preserved", "some", res.get(2));
|
||||||
|
assertEquals("Command should be preserved", "arguments", res.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
public void testSplitCommandWithString() throws CommandParsingException {
|
||||||
assertEquals("Command size", 4, res.size());
|
List<String> res;
|
||||||
assertEquals("Elements should be preserved", "aCommand", res.get(0));
|
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
|
||||||
assertEquals("Command size", 4, res.size());
|
|
||||||
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
|
||||||
res = GCLCConstants.splitCommand("aCommand \"with some\" arguments");
|
res = GCLCConstants.splitCommand("aCommand \"with some\" arguments");
|
||||||
assertEquals("Command size", 3, res.size());
|
assertEquals("Command size", 3, res.size());
|
||||||
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("with some"));
|
assertEquals("Command should be preserved", "with some", res.get(1));
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("arguments"));
|
assertEquals("Command should be preserved", "arguments", res.get(2));
|
||||||
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
|
||||||
assertEquals("Command size", 3, res.size());
|
|
||||||
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("with some"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("arguments"));
|
|
||||||
res = GCLCConstants.splitCommand("aCommand wi\\\"th some arguments");
|
|
||||||
assertEquals("Command size", 4, res.size());
|
|
||||||
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("wi\"th"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
|
||||||
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
|
||||||
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with \"some arguments\"");
|
res = GCLCConstants.splitCommand("aCommand with \"some arguments\"");
|
||||||
assertEquals("Command size", 3, res.size());
|
assertEquals("Command size", 3, res.size());
|
||||||
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
assertEquals("Command should be preserved", "with", res.get(1));
|
||||||
assertTrue("Elements should be preserved", res.get(2).equals("some arguments"));
|
assertEquals("Command should be preserved", "some arguments", res.get(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSplitCommandWithEscape() throws CommandParsingException {
|
||||||
|
List<String> res;
|
||||||
|
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
||||||
|
assertEquals("Command size", 3, res.size());
|
||||||
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
|
assertEquals("Command should be preserved", "with some", res.get(1));
|
||||||
|
assertEquals("Command should be preserved", "arguments", res.get(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSplitCommandWithQuoteInString() throws CommandParsingException {
|
||||||
|
List<String> res;
|
||||||
|
res = GCLCConstants.splitCommand("aCommand wi\\\"th some arguments");
|
||||||
|
assertEquals("Command size", 4, res.size());
|
||||||
|
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
||||||
|
assertEquals("Command should be preserved", "wi\"th", res.get(1));
|
||||||
|
assertEquals("Command should be preserved", "some", res.get(2));
|
||||||
|
assertEquals("Command should be preserved", "arguments", res.get(3));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSplitCommandInvalidQuoting() throws CommandParsingException {
|
||||||
|
List<String> res;
|
||||||
try {
|
try {
|
||||||
// Wrong lines?
|
// Wrong lines?
|
||||||
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");
|
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");
|
||||||
|
Loading…
Reference in New Issue
Block a user