Adds tests for the parser
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
This commit is contained in:
parent
6eec3d7969
commit
9c189b5dff
@ -1,14 +1,28 @@
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import net.knarcraft.ffmpegconverter.parser.ConverterArgument;
|
||||
import net.knarcraft.ffmpegconverter.parser.ConverterArgumentValue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class ParserTest {
|
||||
|
||||
private List<ConverterArgument> validArguments;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
validArguments = new ArrayList<>();
|
||||
validArguments.add(new ConverterArgument("anargument", 'a', true, ConverterArgumentValue.STRING));
|
||||
validArguments.add(new ConverterArgument("turnoff", 't', false, ConverterArgumentValue.BOOLEAN));
|
||||
validArguments.add(new ConverterArgument("turnon", 'o', false, ConverterArgumentValue.BOOLEAN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenize() {
|
||||
List<String> tokens = Parser.tokenize("arg1 \"arg 2 long\" arg3 \"arg 4\"");
|
||||
@ -20,4 +34,27 @@ public class ParserTest {
|
||||
assertEquals(expected, tokens);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidInput() {
|
||||
Map<String, String> parsed = Parser.parse("-t -a \"some Value\" --turnon false", validArguments);
|
||||
assertEquals("some Value", parsed.get("anargument"));
|
||||
assertEquals("true", parsed.get("turnoff"));
|
||||
assertEquals("false", parsed.get("turnon"));
|
||||
}
|
||||
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void parseInvalidArgument() {
|
||||
Parser.parse("--someInvalidArgument hahaha", validArguments);
|
||||
}
|
||||
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void parseValueWhenExpectingArgument() {
|
||||
Parser.parse("somevalue", validArguments);
|
||||
}
|
||||
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void parseArgumentWithoutRequiredValue() {
|
||||
Parser.parse("--anargument -t", validArguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user