Search in sources :

Example 31 with ClassNode

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

the class TestTryCatchFinally method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("exc(obj);"));
    assertThat(code, containsOne("} catch (Exception e) {"));
    assertThat(code, containsOne("e.getMessage();"));
    assertThat(code, containsOne("} finally {"));
    assertThat(code, containsOne("f = true;"));
    assertThat(code, containsOne("return this.f;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 32 with ClassNode

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

the class TestTryCatchFinally2 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("} finally {"));
    assertThat(code, containsOne("out.close();"));
    assertThat(code, containsOne("for (NClass parent : parents) {"));
    // TODO
    //		assertThat(code, countString(2, "for (NClass cls : classes) {"));
    assertThat(code, containsOne("for (NClass cls : this.classes) {"));
    assertThat(code, containsOne("for (NClass cls2 : this.classes) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 33 with ClassNode

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

the class TestTryCatchFinally4 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("File file = File.createTempFile(\"test\", \"txt\");"));
    assertThat(code, containsOne("OutputStream outputStream = new FileOutputStream(file);"));
    assertThat(code, containsOne("outputStream.write(1);"));
    assertThat(code, containsOne("} finally {"));
    assertThat(code, containsOne("outputStream.close();"));
    assertThat(code, containsOne("} catch (IOException e) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 34 with ClassNode

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

the class TestTryCatchFinally6 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsLines(2, "InputStream is = null;", "try {", indent(1) + "is = new FileInputStream(\"1.txt\");", "} finally {", indent(1) + "if (is != null) {", indent(2) + "is.close();", indent(1) + "}", "}"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 35 with ClassNode

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

the class TestTryCatchInIf method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("try {"));
    assertThat(code, containsOne("} catch (NumberFormatException e) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) 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