Adds some tests to ListUtil, Parser and StringUtil
This commit is contained in:
parent
922185157e
commit
f4afb63f32
@ -1,6 +1,5 @@
|
||||
package net.knarcraft.ffmpegconverter;
|
||||
package net.knarcraft.ffmpegconverter.converter;
|
||||
|
||||
import net.knarcraft.ffmpegconverter.converter.AnimeConverter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -0,0 +1,61 @@
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class ListUtilTest {
|
||||
private static List<Integer> matchesList;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
matchesList = new ArrayList<>();
|
||||
matchesList.add(5);
|
||||
matchesList.add(7);
|
||||
matchesList.add(9);
|
||||
matchesList.add(11);
|
||||
matchesList.add(13);
|
||||
matchesList.add(15);
|
||||
matchesList.add(17);
|
||||
matchesList.add(19);
|
||||
matchesList.add(21);
|
||||
matchesList.add(23);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concatenate() {
|
||||
Integer[] list1 = new Integer[]{5, 2, 34, 56, 12, 78, 43, 4, 2, 43};
|
||||
Integer[] list2 = new Integer[]{7, 5, 2, 35, 234, 6, 1, 23, 76, 45, 4};
|
||||
Integer[] expected = new Integer[]{5, 2, 34, 56, 12, 78, 43, 4, 2, 43, 7, 5, 2, 35, 234, 6, 1, 23, 76, 45, 4};
|
||||
Integer[] result = ListUtil.concatenate(list1, list2);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMatchingNoMatches() {
|
||||
List<Integer> result = ListUtil.getMatching(matchesList, (item) -> item % 2 == 0);
|
||||
assertEquals(new ArrayList<>(), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMatchingAllMatches() {
|
||||
List<Integer> result = ListUtil.getMatching(matchesList, (item) -> item % 2 != 0);
|
||||
assertEquals(matchesList, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMatchingSomeMatches() {
|
||||
List<Integer> result = ListUtil.getMatching(matchesList, (item) -> item < 10);
|
||||
List<Integer> expected = new ArrayList<>();
|
||||
expected.add(5);
|
||||
expected.add(7);
|
||||
expected.add(9);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class ParserTest {
|
||||
|
||||
@Test
|
||||
public void tokenize() {
|
||||
List<String> tokens = Parser.tokenize("arg1 \"arg 2 long\" arg3 \"arg 4\"");
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("arg1");
|
||||
expected.add("arg 2 long");
|
||||
expected.add("arg3");
|
||||
expected.add("arg 4");
|
||||
assertEquals(expected, tokens);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class StringUtilTest {
|
||||
|
||||
@Test
|
||||
public void stringBetweenNoMatches() {
|
||||
String[] result = StringUtil.stringBetween("a test string", "[", "]");
|
||||
assertArrayEquals(new String[]{}, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringBetweenOneMatch() {
|
||||
String[] result = StringUtil.stringBetween("a [test] string", "[", "]");
|
||||
assertArrayEquals(new String[]{"test"}, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringBetweenSeveralMatches() {
|
||||
String[] result = StringUtil.stringBetween("a long string containing a lot of potential matches for " +
|
||||
"the string between method defined in the StringUtil class", " ", "a");
|
||||
assertArrayEquals(new String[]{"long string cont", "", "lot of potenti", "m",
|
||||
"for the string between method defined in the StringUtil cl"}, result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user