Search in sources :

Example 36 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestTypeResolver2 method test.

@Test
public void test() {
    noDebugInfo();
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("if (obj != null) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 37 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestRedundantThis method test.

// @Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, not(containsString("this.f1();")));
    assertThat(code, not(containsString("return this.field1;")));
    assertThat(code, containsString("this.field2 = field2;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 38 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestFieldInit method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("List<String> s = new ArrayList"));
    assertThat(code, containsOne("A a = new A();"));
    assertThat(code, containsOne("int i = (Random.class.getSimpleName().length() + 1);"));
    assertThat(code, containsOne("int n = 0;"));
    assertThat(code, not(containsString("static {")));
    assertThat(code, containsOne("this.n = z;"));
    assertThat(code, containsOne("this.n = 0;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) Matchers.containsString(org.hamcrest.Matchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 39 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestFieldInitInTryCatch method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("private static final URL a;"));
    assertThat(code, containsOne("a = new URL(\"http://www.example.com/\");"));
    assertThat(code, containsLines(2, "try {", indent(1) + "a = new URL(\"http://www.example.com/\");", "} catch (MalformedURLException e) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 40 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestIfInTry method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("if (a != 0) {"));
    assertThat(code, containsOne("} catch (Exception e) {"));
    assertThat(code, countString(2, "try {"));
    assertThat(code, countString(3, "f()"));
    assertThat(code, containsOne("return 1;"));
    assertThat(code, containsOne("} catch (IOException e"));
    assertThat(code, containsOne("return -1;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JadxMatchers.countString(jadx.tests.api.utils.JadxMatchers.countString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Aggregations

ClassNode (jadx.core.dex.nodes.ClassNode)236 Test (org.junit.Test)201 IntegrationTest (jadx.tests.api.IntegrationTest)197 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)93 JadxMatchers.countString (jadx.tests.api.utils.JadxMatchers.countString)17 MethodNode (jadx.core.dex.nodes.MethodNode)12 FieldNode (jadx.core.dex.nodes.FieldNode)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)7 InsnNode (jadx.core.dex.nodes.InsnNode)7 ClassInfo (jadx.core.dex.info.ClassInfo)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)6 DexNode (jadx.core.dex.nodes.DexNode)5 InsnArg (jadx.core.dex.instructions.args.InsnArg)4 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)4 SmaliTest (jadx.tests.api.SmaliTest)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 MethodInfo (jadx.core.dex.info.MethodInfo)3