NativeAdViewHelper { @Deprecated @NonNull static View getAdView(@Nullable View convertView, @Nullable final ViewGroup parent, @NonNull final Context context, @NonNull final NativeResponse nativeResponse, @NonNull final ViewBinder viewBinder) { final MoPubNativeAdRenderer moPubNativeAdRenderer = new MoPubNativeAdRenderer(viewBinder); if (convertView == null) { convertView = moPubNativeAdRenderer.createAdView(context, parent); } clearNativeResponse(context, convertView); if (nativeResponse.isDestroyed()) { MoPubLog.d("NativeResponse is destroyed, returning hidden view."); convertView.setVisibility(GONE); } else { prepareNativeResponse(context, convertView, nativeResponse); moPubNativeAdRenderer.renderAdView(convertView, nativeResponse); } return convertView; } private  NativeAdViewHelper();   }
@Test public void getAdView_shouldReturnPopulatedView() throws Exception { when(mockNativeResponse1.getTitle()).thenReturn("test title"); when(mockNativeResponse1.getText()).thenReturn("test text"); when(mockNativeResponse1.getCallToAction()).thenReturn("test call to action"); View view = NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); assertThat(((TextView)view.findViewById(titleView.getId())).getText()).isEqualTo("test title"); assertThat(((TextView)view.findViewById(textView.getId())).getText()).isEqualTo("test text"); assertThat(((TextView)view.findViewById(callToActionView.getId())).getText()).isEqualTo("test call to action"); }
@Test public void getAdView_withDestroyedNativeResponse_shouldReturnGONEConvertView() throws Exception { when(mockNativeResponse1.isDestroyed()).thenReturn(true); View view = NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); assertThat(view).isEqualTo(relativeLayout); assertThat(view.getVisibility()).isEqualTo(View.GONE); }
@Test public void getAdView_shouldRemoveViewFromImpressionTracker_shouldClearPreviousNativeResponse() throws Exception { NativeAdViewHelper.sImpressionTrackerMap.put(context, mockImpressionTracker); NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); verify(mockImpressionTracker).removeView(relativeLayout); NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse2, viewBinder); verify(mockImpressionTracker, times(2)).removeView(relativeLayout); verify(mockNativeResponse1).clear(relativeLayout); NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); verify(mockImpressionTracker, times(3)).removeView(relativeLayout); verify(mockNativeResponse2).clear(relativeLayout); }
@Test public void getAdView_withNetworkImpressionTracker_shouldNotAddViewToImpressionTracker_shouldPrepareNativeResponse() throws Exception { NativeAdViewHelper.sImpressionTrackerMap.put(context, mockImpressionTracker); when(mockNativeResponse1.isOverridingImpressionTracker()).thenReturn(true); NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); verify(mockImpressionTracker, never()).addView(any(View.class), any(NativeResponse.class)); verify(mockNativeResponse1).prepare(relativeLayout); }
@Test public void getAdView_withoutNetworkImpressionTracker_shouldAddViewToImpressionTracker_shouldPrepareNativeResponse() throws Exception { NativeAdViewHelper.sImpressionTrackerMap.put(context, mockImpressionTracker); when(mockNativeResponse1.isOverridingImpressionTracker()).thenReturn(false); NativeAdViewHelper.getAdView(relativeLayout, viewGroup, context, mockNativeResponse1, viewBinder); verify(mockImpressionTracker).addView(relativeLayout, mockNativeResponse1); verify(mockNativeResponse1).prepare(relativeLayout); }