Package jadx.tests.integration.loops

Source Code of jadx.tests.integration.loops.TestIterableForEach2$TestCls

package jadx.tests.integration.loops;

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

import java.io.IOException;
import java.util.List;

import org.junit.Test;

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

public class TestIterableForEach2 extends IntegrationTest {

  public static class TestCls {
    public static String test(final Service service) throws IOException {
      for (Authorization auth : service.getAuthorizations()) {
        if (isValid(auth)) {
          return auth.getToken();
        }
      }
      return null;
    }

    private static boolean isValid(Authorization auth) {
      return false;
    }

    private static class Service {
      public List<Authorization> getAuthorizations() {
        return null;
      }
    }

    private static class Authorization {
      public String getToken() {
        return "";
      }
    }
  }

  @Test
  public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();

    assertThat(code, containsOne("for (Authorization auth : service.getAuthorizations()) {"));
    assertThat(code, containsOne("if (isValid(auth)) {"));
    assertThat(code, containsOne("return auth.getToken();"));
  }
}
TOP

Related Classes of jadx.tests.integration.loops.TestIterableForEach2$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.