Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,41 @@ public void testDestroy_nullifiesAdViewAndBannerLayout() throws Exception {
assertThat(adView).isNull();
assertThat(bannerLayout).isNull();
}

@Test
public void testLoad_afterDestroy_resetsIsDestroyedAndLoadsAd() {
unityBannerAd.destroy();
View fakeView = simulateAdLoadSuccess();
verify(mockCallback, timeout(1000)).onAdLoaded();
assertThat(fakeView).isNotNull();
}

@Test
public void testDestroy_calledMultipleTimes_doesNotCrash() throws Exception {
unityBannerAd.destroy();
unityBannerAd.destroy();
ShadowLooper.idleMainLooper();

Field isDestroyedField = UnityBannerAd.class.getDeclaredField("isDestroyed");
isDestroyedField.setAccessible(true);
boolean isDestroyed = (boolean) isDestroyedField.get(unityBannerAd);

Field adViewField = UnityBannerAd.class.getDeclaredField("adView");
adViewField.setAccessible(true);
View adView = (View) adViewField.get(unityBannerAd);

Field bannerLayoutField = UnityBannerAd.class.getDeclaredField("bannerLayout");
bannerLayoutField.setAccessible(true);
FrameLayout bannerLayout = (FrameLayout) bannerLayoutField.get(unityBannerAd);

Field layoutChangeListenerField = UnityBannerAd.class.getDeclaredField("layoutChangeListener");
layoutChangeListenerField.setAccessible(true);
View.OnLayoutChangeListener layoutChangeListener =
(View.OnLayoutChangeListener) layoutChangeListenerField.get(unityBannerAd);

assertThat(isDestroyed).isTrue();
assertThat(adView).isNull();
assertThat(bannerLayout).isNull();
assertThat(layoutChangeListener).isNull();
}
}