Search in sources :

Example 26 with ClassNode

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

the class TestTryCatch3 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsString("try {"));
    assertThat(code, containsString("exc(obj);"));
    assertThat(code, containsString("} catch (Exception e) {"));
    assertThat(code, not(containsString("throw th;")));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 27 with ClassNode

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

the class TestTryCatch4 method test.

@Test
public void test() {
    disableCompilation();
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsString("try {"));
    assertThat(code, containsString("output = new FileOutputStream(new File(\"f\"));"));
    assertThat(code, containsString("return new Object();"));
    assertThat(code, containsString("} catch (FileNotFoundException e) {"));
    assertThat(code, containsString("System.out.println(\"Exception\");"));
    assertThat(code, containsString("return null;"));
    assertThat(code, not(containsString("output = output;")));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 28 with ClassNode

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

the class TestTryCatch6 method test.

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

Example 29 with ClassNode

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

the class TestTryCatch7 method test.

@Test
public void test() {
    noDebugInfo();
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    String excVarName = "exception";
    assertThat(code, containsOne("Exception " + excVarName + " = new Exception();"));
    assertThat(code, containsOne("} catch (Exception e) {"));
    assertThat(code, containsOne(excVarName + " = e;"));
    assertThat(code, containsOne(excVarName + ".printStackTrace();"));
    assertThat(code, containsOne("return " + excVarName + ";"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 30 with ClassNode

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

the class TestTryCatch8 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("synchronized (this) {"));
    assertThat(code, containsOne("throw new MyException();"));
    assertThat(code, containsOne("} catch (MyException e) {"));
    assertThat(code, containsOne("this.e = e;"));
    assertThat(code, containsOne("} catch (Exception x) {"));
    assertThat(code, containsOne("this.e = new MyException(\"MyExc\", x);"));
}
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