Adds tests for the parser
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2021-01-21 13:49:20 +01:00
parent 6eec3d7969
commit 9c189b5dff

View File

@ -1,14 +1,28 @@
package net.knarcraft.ffmpegconverter.utility; 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 org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
public class ParserTest { 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 @Test
public void tokenize() { public void tokenize() {
List<String> tokens = Parser.tokenize("arg1 \"arg 2 long\" arg3 \"arg 4\""); List<String> tokens = Parser.tokenize("arg1 \"arg 2 long\" arg3 \"arg 4\"");
@ -20,4 +34,27 @@ public class ParserTest {
assertEquals(expected, tokens); 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);
}
} }