@Before
  public void setUp() throws Exception {
    Activity context = Robolectric.buildActivity(Activity.class).create().get();
    relativeLayout = new RelativeLayout(context);
    relativeLayout.setId((int) Utils.generateUniqueId());
    viewGroup = new LinearLayout(context);

    BaseForwardingNativeAd baseForwardingNativeAd = new BaseForwardingNativeAd() {};
    baseForwardingNativeAd.setTitle("test title");
    baseForwardingNativeAd.setText("test text");
    baseForwardingNativeAd.setCallToAction("test call to action");
    baseForwardingNativeAd.setClickDestinationUrl("destinationUrl");

    nativeResponse =
        new NativeResponse(
            context,
            "impressionTrackerUrl",
            "clickTrackerUrl",
            "test ID",
            baseForwardingNativeAd,
            mock(MoPubNative.MoPubNativeListener.class));

    titleView = new TextView(context);
    titleView.setId((int) Utils.generateUniqueId());
    textView = new TextView(context);
    textView.setId((int) Utils.generateUniqueId());
    callToActionView = new Button(context);
    callToActionView.setId((int) Utils.generateUniqueId());
    mainImageView = new ImageView(context);
    mainImageView.setId((int) Utils.generateUniqueId());
    iconImageView = new ImageView(context);
    iconImageView.setId((int) Utils.generateUniqueId());
    badView = new ImageView(context);
    badView.setId((int) Utils.generateUniqueId());

    relativeLayout.addView(titleView);
    relativeLayout.addView(textView);
    relativeLayout.addView(callToActionView);
    relativeLayout.addView(mainImageView);
    relativeLayout.addView(iconImageView);
    relativeLayout.addView(badView);

    viewBinder =
        new ViewBinder.Builder(relativeLayout.getId())
            .titleId(titleView.getId())
            .textId(textView.getId())
            .callToActionId(callToActionView.getId())
            .mainImageId(mainImageView.getId())
            .iconImageId(iconImageView.getId())
            .build();

    subject = new MoPubNativeAdRenderer(viewBinder);
  }
  @Test
  public void handleOpen_withHttpApplicationUrl_shouldStartMoPubBrowser() {
    String applicationUrl = "https://www.mopub.com/";

    subject.handleOpen(applicationUrl);

    Robolectric.getBackgroundThreadScheduler().advanceBy(0);
    Intent startedIntent = ShadowApplication.getInstance().getNextStartedActivity();
    assertThat(startedIntent).isNotNull();
    // Since we are not using an Activity context, we should have FLAG_ACTIVITY_NEW_TASK
    assertThat(Utils.bitMaskContainsFlag(startedIntent.getFlags(), Intent.FLAG_ACTIVITY_NEW_TASK))
        .isTrue();
    assertThat(startedIntent.getComponent().getClassName())
        .isEqualTo("com.mopub.common.MoPubBrowser");

    verify(mockMraidListener).onOpen();
  }
  @Test
  public void handleOpen_withApplicationUrl_shouldStartNewIntent() {
    String applicationUrl = "amzn://blah";
    RuntimeEnvironment.getRobolectricPackageManager()
        .addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW, Uri.parse(applicationUrl)), new ResolveInfo());

    subject.handleOpen(applicationUrl);

    Intent startedIntent = ShadowApplication.getInstance().getNextStartedActivity();
    assertThat(startedIntent).isNotNull();
    // Since we are not using an Activity context, we should have FLAG_ACTIVITY_NEW_TASK
    assertThat(Utils.bitMaskContainsFlag(startedIntent.getFlags(), Intent.FLAG_ACTIVITY_NEW_TASK))
        .isTrue();
    assertThat(startedIntent.getComponent()).isNull();

    verify(mockMraidListener).onOpen();
  }