Package jadx.tests.integration.others

Source Code of jadx.tests.integration.others.TestIfInTry$TestCls

package jadx.tests.integration.others;

import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static jadx.tests.api.utils.JadxMatchers.countString;
import static org.junit.Assert.assertThat;

public class TestIfInTry extends IntegrationTest {

  public static class TestCls {
    private File dir;

    public int test() {
      try {
        int a = f();
        if (a != 0) {
          return a;
        }
      } catch (Exception e) {
        // skip
      }
      try {
        f();
        return 1;
      } catch (IOException e) {
        return -1;
      }
    }

    private int f() throws IOException {
      return 0;
    }
  }

  @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;"));
  }
}
TOP

Related Classes of jadx.tests.integration.others.TestIfInTry$TestCls

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.