[test] Use assert equals

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2021-11-07 12:13:13 +01:00
parent b38980eeb5
commit ea01d346d3

View File

@ -72,7 +72,6 @@ package net.bigeon.gclc;
* #L%
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
@ -87,52 +86,77 @@ import net.bigeon.gclc.exception.CommandParsingException;
@SuppressWarnings({ "nls", "static-method" })
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
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
*
* @throws CommandParsingException if an error occured */
@Test
public void testSplitCommand() throws CommandParsingException {
public void testSplitCommandMultiSpaces() throws CommandParsingException {
List<String> res;
res = GCLCConstants.splitCommand("aCommand");
assertTrue("single word command should have one element", res.size() == 1);
assertTrue("Command should be preserved", res.get(0).equals("aCommand"));
res = GCLCConstants.splitCommand("aCommand with some arguments");
assertEquals("Command size", 4, res.size());
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"));
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));
}
public void testSplitCommandWithString() throws CommandParsingException {
List<String> res;
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 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"));
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));
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"));
assertTrue("Elements should be preserved", res.get(2).equals("some arguments"));
assertEquals("Command should be preserved", "aCommand", res.get(0));
assertEquals("Command should be preserved", "with", res.get(1));
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 {
// Wrong lines?
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");