core: add some integration tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package jadx.tests.internal.annotations;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestParamAnnotations extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public static @interface A {
|
||||
int i() default 7;
|
||||
}
|
||||
|
||||
void test1(@A int i) {
|
||||
}
|
||||
|
||||
void test2(int i, @A int j) {
|
||||
}
|
||||
|
||||
void test3(@A(i = 5) int i) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("void test1(@A int i) {"));
|
||||
assertThat(code, containsString("void test2(int i, @A int j) {"));
|
||||
assertThat(code, containsString("void test3(@A(i = 5) int i) {"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package jadx.tests.internal.annotations;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestVarArgAnnotation extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
void test1(int... a) {
|
||||
}
|
||||
|
||||
void test2(int i, Object... a) {
|
||||
}
|
||||
|
||||
void test3(int[] a) {
|
||||
}
|
||||
|
||||
void call() {
|
||||
test1(1, 2);
|
||||
test2(3, "1", 7);
|
||||
test3(new int[]{5, 8});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("void test1(int... a) {"));
|
||||
assertThat(code, containsString("void test2(int i, Object... a) {"));
|
||||
|
||||
// TODO:
|
||||
assertThat(code, containsString("test1(new int[]{1, 2});"));
|
||||
assertThat(code, containsString("test2(3, objArr);"));
|
||||
|
||||
// negative case
|
||||
assertThat(code, containsString("void test3(int[] a) {"));
|
||||
assertThat(code, containsString("test3(new int[]{5, 8});"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package jadx.tests.internal.inner;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.utils.JadxMatchers.containsOne;
|
||||
import static jadx.tests.utils.JadxMatchers.countString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass4 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
public static class Inner {
|
||||
private int f;
|
||||
private double d;
|
||||
|
||||
public void test() {
|
||||
new Thread() {
|
||||
{
|
||||
f = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
d = 7.5;
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsOne(indent(3) + "new Thread() {"));
|
||||
assertThat(code, containsOne(indent(4) + "{"));
|
||||
assertThat(code, containsOne("f = 1;"));
|
||||
assertThat(code, countString(2, indent(4) + "}"));
|
||||
assertThat(code, containsOne(indent(4) + "public void run() {"));
|
||||
assertThat(code, containsOne("d = 7.5"));
|
||||
assertThat(code, containsOne(indent(3) + "}.start();"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user