@Test
  public void getKeywordsTest() throws Exception {
    subject.setInterstitialView(interstitialView);

    subject.getKeywords();
    verify(interstitialView).getKeywords();
  }
  @Test
  public void dismissingCustomEventInterstitial_shouldNotBecomeReadyToShowCustomEventAd()
      throws Exception {
    subject.onCustomEventInterstitialLoaded();
    subject.onCustomEventInterstitialDismissed();

    assertShowsCustomEventInterstitial(false);
  }
  @Test
  public void failingCustomEventInterstitial_shouldNotBecomeReadyToShowCustomEventAd()
      throws Exception {
    subject.onCustomEventInterstitialLoaded();
    subject.onCustomEventInterstitialFailed(CANCELLED);

    assertShowsCustomEventInterstitial(false);
  }
  @Test
  public void setKeywordsTest() throws Exception {
    subject.setInterstitialView(interstitialView);
    String keywords = "these_are_keywords";

    subject.setKeywords(keywords);
    verify(interstitialView).setKeywords(eq(keywords));
  }
  @Test
  public void destroy_shouldPreventOnCustomEventShownNotification() throws Exception {
    subject.destroy();

    subject.onCustomEventInterstitialShown();

    verify(interstitialAdListener, never()).onInterstitialShown(eq(subject));
  }
 @Test
 public void
     onCustomEventInterstitialDismissed_whenInterstitialAdListenerIsNull_shouldNotNotifyListener()
         throws Exception {
   subject.setInterstitialAdListener(null);
   subject.onCustomEventInterstitialDismissed();
   verify(interstitialAdListener, never()).onInterstitialDismissed(eq(subject));
 }
  @Test
  public void onCustomEventInterstitialFailed_shouldLoadFailUrl() throws Exception {
    subject.setInterstitialView(interstitialView);

    subject.onCustomEventInterstitialFailed(INTERNAL_ERROR);

    verify(interstitialView).loadFailUrl(INTERNAL_ERROR);
  }
  @Test
  public void loadingCustomEventInterstitial_shouldBecomeReadyToShowCustomEventAd()
      throws Exception {
    subject.load();
    subject.onCustomEventInterstitialLoaded();

    assertShowsCustomEventInterstitial(true);
  }
  @Test
  public void destroy_shouldPreventOnCustomEventInterstitialFailedNotification() throws Exception {
    subject.setInterstitialView(interstitialView);
    subject.destroy();

    subject.onCustomEventInterstitialFailed(UNSPECIFIED);

    verify(interstitialView, never()).loadFailUrl(UNSPECIFIED);
  }
  @Test
  public void onCustomEventInterstitialShown_shouldTrackImpressionAndNotifyListener()
      throws Exception {
    subject.setInterstitialView(interstitialView);
    subject.onCustomEventInterstitialShown();

    verify(interstitialView).trackImpression();
    verify(interstitialAdListener).onInterstitialShown(eq(subject));
  }
  @Test
  public void onCustomEventInterstitialLoaded_shouldNotifyListener() throws Exception {
    subject.setInterstitialView(interstitialView);

    subject.onCustomEventInterstitialLoaded();
    verify(interstitialAdListener).onInterstitialLoaded(eq(subject));

    verify(interstitialView, never()).trackImpression();
  }
  @Test
  public void destroy_shouldPreventOnCustomEventInterstitialClickedFromRegisteringClick()
      throws Exception {
    subject.setInterstitialView(interstitialView);
    subject.destroy();

    subject.onCustomEventInterstitialClicked();

    verify(interstitialView, never()).registerClick();
  }
  @Test
  public void onCustomEventInterstitialClicked_shouldRegisterClickAndNotifyListener()
      throws Exception {
    subject.setInterstitialView(interstitialView);

    subject.onCustomEventInterstitialClicked();

    verify(interstitialView).registerClick();
    verify(interstitialAdListener).onInterstitialClicked(eq(subject));
  }
  @Test
  public void forceRefresh_shouldResetInterstitialViewAndMarkNotDestroyed() throws Exception {
    subject.setInterstitialView(interstitialView);
    subject.onCustomEventInterstitialLoaded();
    subject.forceRefresh();

    assertThat(subject.isReady()).isFalse();
    assertThat(subject.isDestroyed()).isFalse();
    verify(interstitialView).forceRefresh();
  }
  @Test
  public void setLocalExtrasTest() throws Exception {
    subject.setInterstitialView(interstitialView);

    Map<String, Object> localExtras = new HashMap<String, Object>();
    localExtras.put("guy", new Activity());
    localExtras.put("other guy", new BigDecimal(27f));

    subject.setLocalExtras(localExtras);
    verify(interstitialView).setLocalExtras(eq(localExtras));
  }
  private void assertShowsCustomEventInterstitial(boolean shouldBeReady) {
    MoPubInterstitial.MoPubInterstitialView moPubInterstitialView =
        subject.new MoPubInterstitialView(activity);
    moPubInterstitialView.loadCustomEvent(customEventClassName, serverExtras);

    assertThat(subject.isReady()).isEqualTo(shouldBeReady);
    assertThat(subject.show()).isEqualTo(shouldBeReady);

    if (shouldBeReady) {
      verify(customEventInterstitialAdapter).showInterstitial();
    } else {
      verify(customEventInterstitialAdapter, never()).showInterstitial();
    }
  }
  public CustomEventInterstitialAdapter(
      MoPubInterstitial moPubInterstitial, String className, String jsonParams) {
    mHandler = new Handler();
    mServerExtras = new HashMap<String, String>();
    mLocalExtras = new HashMap<String, Object>();
    mContext = moPubInterstitial.getActivity();
    mTimeout =
        new Runnable() {
          @Override
          public void run() {
            Log.d("MoPub", "Third-party network timed out.");
            onInterstitialFailed(NETWORK_TIMEOUT);
            invalidate();
          }
        };

    Log.d("MoPub", "Attempting to invoke custom event: " + className);
    try {
      mCustomEventInterstitial = CustomEventInterstitialFactory.create(className);
    } catch (Exception exception) {
      Log.d("MoPub", "Couldn't locate or instantiate custom event: " + className + ".");
      if (mCustomEventInterstitialAdapterListener != null)
        mCustomEventInterstitialAdapterListener.onCustomEventInterstitialFailed(ADAPTER_NOT_FOUND);
    }

    // Attempt to load the JSON extras into mServerExtras.
    try {
      mServerExtras = Utils.jsonStringToMap(jsonParams);
    } catch (Exception exception) {
      Log.d("MoPub", "Failed to create Map from JSON: " + jsonParams);
    }

    mLocalExtras = moPubInterstitial.getLocalExtras();
    if (moPubInterstitial.getLocation() != null)
      mLocalExtras.put("location", moPubInterstitial.getLocation());
  }
  @Before
  public void setUp() throws Exception {
    activity = Robolectric.buildActivity(Activity.class).create().get();
    subject = new MoPubInterstitial(activity, AD_UNIT_ID_VALUE);
    interstitialAdListener = mock(MoPubInterstitial.InterstitialAdListener.class);
    subject.setInterstitialAdListener(interstitialAdListener);

    interstitialView = mock(MoPubInterstitial.MoPubInterstitialView.class);

    customEventClassName = "class name";
    serverExtras = new HashMap<String, String>();
    serverExtras.put("testExtra", "class data");

    customEventInterstitialAdapter = TestCustomEventInterstitialAdapterFactory.getSingletonMock();
    reset(customEventInterstitialAdapter);
    adViewController = TestAdViewControllerFactory.getSingletonMock();
  }
 @Test
 public void setTestingTest() throws Exception {
   subject.setInterstitialView(interstitialView);
   subject.setTesting(true);
   verify(interstitialView).setTesting(eq(true));
 }
  @Test
  public void onCustomEventInterstitialDismissed_shouldNotifyListener() throws Exception {
    subject.onCustomEventInterstitialDismissed();

    verify(interstitialAdListener).onInterstitialDismissed(eq(subject));
  }
 @Test
 public void getInterstitialAdListenerTest() throws Exception {
   interstitialAdListener = mock(MoPubInterstitial.InterstitialAdListener.class);
   subject.setInterstitialAdListener(interstitialAdListener);
   assertThat(subject.getInterstitialAdListener()).isSameAs(interstitialAdListener);
 }
  @Test
  public void attemptStateTransition_withIdleStartState() {
    /**
     * IDLE can go to LOADING when load is called. IDLE can also go to DESTROYED if the interstitial
     * view is destroyed.
     */
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    boolean stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange = subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setInterstitialView(interstitialView);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.LOADING);
    verify(customEventInterstitialAdapter).invalidate();
    verify(interstitialView).loadAd();

    reset(customEventInterstitialAdapter, interstitialView);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setInterstitialView(interstitialView);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.LOADING);
    verify(customEventInterstitialAdapter).invalidate();
    verify(interstitialView).forceRefresh();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.IDLE);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();
  }
  @Test
  public void attemptStateTransition_withLoadingStartState() {
    /**
     * LOADING can go to IDLE if and only if it's a hard reset to IDLE. LOADING should go to READY
     * when the interstitial is done loading. LOADING can go to DESTROYED if the interstitial view
     * is destroyed.
     */
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    boolean stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.LOADING);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange = subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verify(customEventInterstitialAdapter).invalidate();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.LOADING);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.LOADING);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.LOADING);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();
  }
  @Test
  public void attemptStateTransition_withDestroyedStartState() {
    // All state transitions should fail if starting from a destroyed state
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    boolean stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange = subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.DESTROYED);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
  }
  @Test
  public void attemptStateTransition_withReadyStartState() {
    /**
     * This state should succeed for going to IDLE. When it's forced, it's implicitly resetting the
     * internals into ready state. If it's not forced, this is when the interstitial is shown. Also,
     * READY can go into DESTROYED.
     */
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    boolean stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verify(customEventInterstitialAdapter).showInterstitial();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange = subject.attemptStateTransition(MoPubInterstitial.InterstitialState.IDLE, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.IDLE);
    verify(customEventInterstitialAdapter).invalidate();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);
    verify(interstitialAdListener).onInterstitialLoaded(subject);

    reset(customEventInterstitialAdapter, interstitialAdListener);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.LOADING, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);
    verify(interstitialAdListener).onInterstitialLoaded(subject);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, false);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.READY, true);
    assertThat(stateDidChange).isFalse();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.READY);
    verifyZeroInteractions(customEventInterstitialAdapter);

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, false);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();

    reset(customEventInterstitialAdapter);
    subject.setCustomEventInterstitialAdapter(customEventInterstitialAdapter);
    subject.setCurrentInterstitialState(MoPubInterstitial.InterstitialState.READY);
    stateDidChange =
        subject.attemptStateTransition(MoPubInterstitial.InterstitialState.DESTROYED, true);
    assertThat(stateDidChange).isTrue();
    assertThat(subject.getCurrentInterstitialState())
        .isEqualTo(MoPubInterstitial.InterstitialState.DESTROYED);
    verify(customEventInterstitialAdapter).invalidate();
  }