test: rewrite Spock tests to JUnit 5
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package jadx.gui.update;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
class VersionComparatorTest {
|
||||
|
||||
@Test
|
||||
public void testCompare() {
|
||||
checkCompare("", "", 0);
|
||||
checkCompare("1", "1", 0);
|
||||
checkCompare("1", "2", -1);
|
||||
checkCompare("1.1", "1.1", 0);
|
||||
checkCompare("0.5", "0.5", 0);
|
||||
checkCompare("0.5", "0.5.0", 0);
|
||||
checkCompare("0.5", "0.5.00", 0);
|
||||
checkCompare("0.5", "0.5.0.0", 0);
|
||||
checkCompare("0.5", "0.5.0.1", -1);
|
||||
checkCompare("0.5.0", "0.5.0", 0);
|
||||
checkCompare("0.5.0", "0.5.1", -1);
|
||||
checkCompare("0.5", "0.5.1", -1);
|
||||
checkCompare("0.4.8", "0.5", -1);
|
||||
checkCompare("0.4.8", "0.5.0", -1);
|
||||
checkCompare("0.4.8", "0.6", -1);
|
||||
}
|
||||
|
||||
private static void checkCompare(String a, String b, int result) {
|
||||
assertThat(VersionComparator.compare(a, b), is(result));
|
||||
assertThat(VersionComparator.compare(b, a), is(-result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package jadx.gui.utils;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.gui.treemodel.TextNode;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
||||
class JumpManagerTest {
|
||||
private JumpManager jm;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
jm = new JumpManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyHistory() {
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyHistory2() {
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneElement() {
|
||||
jm.addPosition(makeJumpPos());
|
||||
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoElements() {
|
||||
JumpPosition pos1 = makeJumpPos();
|
||||
jm.addPosition(pos1);
|
||||
JumpPosition pos2 = makeJumpPos();
|
||||
jm.addPosition(pos2);
|
||||
|
||||
assertThat(jm.getPrev(), sameInstance(pos1));
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), sameInstance(pos2));
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigation() {
|
||||
JumpPosition pos1 = makeJumpPos();
|
||||
jm.addPosition(pos1);
|
||||
// 1@
|
||||
JumpPosition pos2 = makeJumpPos();
|
||||
jm.addPosition(pos2);
|
||||
// 1 - 2@
|
||||
assertThat(jm.getPrev(), sameInstance(pos1));
|
||||
// 1@ - 2
|
||||
JumpPosition pos3 = makeJumpPos();
|
||||
jm.addPosition(pos3);
|
||||
// 1 - 3@
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
assertThat(jm.getPrev(), sameInstance(pos1));
|
||||
// 1@ - 3
|
||||
assertThat(jm.getNext(), sameInstance(pos3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigation2() {
|
||||
JumpPosition pos1 = makeJumpPos();
|
||||
jm.addPosition(pos1);
|
||||
// 1@
|
||||
JumpPosition pos2 = makeJumpPos();
|
||||
jm.addPosition(pos2);
|
||||
// 1 - 2@
|
||||
JumpPosition pos3 = makeJumpPos();
|
||||
jm.addPosition(pos3);
|
||||
// 1 - 2 - 3@
|
||||
JumpPosition pos4 = makeJumpPos();
|
||||
jm.addPosition(pos4);
|
||||
// 1 - 2 - 3 - 4@
|
||||
assertThat(jm.getPrev(), sameInstance(pos3));
|
||||
// 1 - 2 - 3@ - 4
|
||||
assertThat(jm.getPrev(), sameInstance(pos2));
|
||||
// 1 - 2@ - 3 - 4
|
||||
JumpPosition pos5 = makeJumpPos();
|
||||
jm.addPosition(pos5);
|
||||
// 1 - 2 - 5@
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
assertThat(jm.getPrev(), sameInstance(pos2));
|
||||
// 1 - 2@ - 5
|
||||
assertThat(jm.getPrev(), sameInstance(pos1));
|
||||
// 1@ - 2 - 5
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), sameInstance(pos2));
|
||||
// 1 - 2@ - 5
|
||||
assertThat(jm.getNext(), sameInstance(pos5));
|
||||
// 1 - 2 - 5@
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addSame() {
|
||||
JumpPosition pos = makeJumpPos();
|
||||
jm.addPosition(pos);
|
||||
jm.addPosition(pos);
|
||||
|
||||
assertThat(jm.getPrev(), nullValue());
|
||||
assertThat(jm.getNext(), nullValue());
|
||||
}
|
||||
|
||||
private JumpPosition makeJumpPos() {
|
||||
return new JumpPosition(new TextNode(""), 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package jadx.gui.utils.search;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static jadx.gui.utils.search.StringRef.fromStr;
|
||||
import static jadx.gui.utils.search.StringRef.subString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
class StringRefTest {
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertThat(fromStr("a").toString(), is("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstring() {
|
||||
checkStr(subString("a", 0), "a");
|
||||
checkStr(subString("a", 1), "");
|
||||
checkStr(subString("a", 0, 0), "");
|
||||
checkStr(subString("a", 0, 1), "a");
|
||||
checkStr(subString("abc", 1, 2), "b");
|
||||
checkStr(subString("abc", 2), "c");
|
||||
checkStr(subString("abc", 2, 3), "c");
|
||||
}
|
||||
|
||||
public static void checkStr(StringRef ref, String str) {
|
||||
assertThat(ref.toString(), is(str));
|
||||
assertThat(ref, is(fromStr(str)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrim() {
|
||||
checkTrim(fromStr("a"), "a");
|
||||
checkTrim(fromStr(" a "), "a");
|
||||
checkTrim(fromStr("\ta"), "a");
|
||||
checkTrim(subString("a b c", 1), "b c");
|
||||
checkTrim(subString("a b\tc", 1, 4), "b");
|
||||
checkTrim(subString("a b\tc", 2, 3), "b");
|
||||
}
|
||||
|
||||
private static void checkTrim(StringRef ref, String result) {
|
||||
assertThat(ref.trim().toString(), is(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit() {
|
||||
checkSplit("abc", "b", "a", "c");
|
||||
checkSplit("abc", "a", "", "bc");
|
||||
checkSplit("abc", "c", "ab");
|
||||
checkSplit("abc", "d", "abc");
|
||||
checkSplit("abbbc", "b", "a", "", "", "c");
|
||||
checkSplit("abbbc", "bb", "a", "bc");
|
||||
checkSplit("abbbc", "bbb", "a", "c");
|
||||
checkSplit("abbbc", "bbc", "ab");
|
||||
checkSplit("abbbc", "bbbc", "a");
|
||||
}
|
||||
|
||||
private static void checkSplit(String str, String splitBy, String... result) {
|
||||
List<StringRef> expectedStringRegList = Arrays.stream(result).map(StringRef::fromStr).collect(Collectors.toList());
|
||||
assertThat(StringRef.split(str, splitBy), is(expectedStringRegList));
|
||||
|
||||
// compare with original split
|
||||
assertThat(str.split(splitBy), is(result));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user