@Test public void fromViewBinder_withNonExistantIds_shouldLeaveFieldsNull() throws Exception { viewBinder = new ViewBinder.Builder(relativeLayout.getId()) .titleId((int) Utils.generateUniqueId()) .textId((int) Utils.generateUniqueId()) .callToActionId((int) Utils.generateUniqueId()) .mainImageId((int) Utils.generateUniqueId()) .iconImageId((int) Utils.generateUniqueId()) .build(); NativeViewHolder nativeViewHolder = NativeViewHolder.fromViewBinder(relativeLayout, viewBinder); assertThat(nativeViewHolder.titleView).isNull(); assertThat(nativeViewHolder.textView).isNull(); assertThat(nativeViewHolder.callToActionView).isNull(); assertThat(nativeViewHolder.mainImageView).isNull(); assertThat(nativeViewHolder.iconImageView).isNull(); }
@NonNull static NativeViewHolder fromViewBinder(@NonNull final View view, @NonNull final ViewBinder viewBinder) { final NativeViewHolder nativeViewHolder = new NativeViewHolder(); try { nativeViewHolder.titleView = (TextView) view.findViewById(viewBinder.titleId); nativeViewHolder.textView = (TextView) view.findViewById(viewBinder.textId); nativeViewHolder.callToActionView = (TextView) view.findViewById(viewBinder.callToActionId); nativeViewHolder.mainImageView = (ImageView) view.findViewById(viewBinder.mainImageId); nativeViewHolder.iconImageView = (ImageView) view.findViewById(viewBinder.iconImageId); return nativeViewHolder; } catch (ClassCastException exception) { MoPubLog.w("Could not cast from id in ViewBinder to expected View type", exception); return EMPTY_VIEW_HOLDER; } }
NativeViewHolder { @NonNull static NativeViewHolder fromViewBinder(@NonNull final View view, @NonNull final ViewBinder viewBinder) { final NativeViewHolder nativeViewHolder = new NativeViewHolder(); try { nativeViewHolder.titleView = (TextView) view.findViewById(viewBinder.titleId); nativeViewHolder.textView = (TextView) view.findViewById(viewBinder.textId); nativeViewHolder.callToActionView = (TextView) view.findViewById(viewBinder.callToActionId); nativeViewHolder.mainImageView = (ImageView) view.findViewById(viewBinder.mainImageId); nativeViewHolder.iconImageView = (ImageView) view.findViewById(viewBinder.iconImageId); return nativeViewHolder; } catch (ClassCastException exception) { MoPubLog.w("Could not cast from id in ViewBinder to expected View type", exception); return EMPTY_VIEW_HOLDER; } } }
NativeViewHolder { @NonNull static NativeViewHolder fromViewBinder(@NonNull final View view, @NonNull final ViewBinder viewBinder) { final NativeViewHolder nativeViewHolder = new NativeViewHolder(); try { nativeViewHolder.titleView = (TextView) view.findViewById(viewBinder.titleId); nativeViewHolder.textView = (TextView) view.findViewById(viewBinder.textId); nativeViewHolder.callToActionView = (TextView) view.findViewById(viewBinder.callToActionId); nativeViewHolder.mainImageView = (ImageView) view.findViewById(viewBinder.mainImageId); nativeViewHolder.iconImageView = (ImageView) view.findViewById(viewBinder.iconImageId); return nativeViewHolder; } catch (ClassCastException exception) { MoPubLog.w("Could not cast from id in ViewBinder to expected View type", exception); return EMPTY_VIEW_HOLDER; } } private  NativeViewHolder(); }
NativeViewHolder { @NonNull static NativeViewHolder fromViewBinder(@NonNull final View view, @NonNull final ViewBinder viewBinder) { final NativeViewHolder nativeViewHolder = new NativeViewHolder(); try { nativeViewHolder.titleView = (TextView) view.findViewById(viewBinder.titleId); nativeViewHolder.textView = (TextView) view.findViewById(viewBinder.textId); nativeViewHolder.callToActionView = (TextView) view.findViewById(viewBinder.callToActionId); nativeViewHolder.mainImageView = (ImageView) view.findViewById(viewBinder.mainImageId); nativeViewHolder.iconImageView = (ImageView) view.findViewById(viewBinder.iconImageId); return nativeViewHolder; } catch (ClassCastException exception) { MoPubLog.w("Could not cast from id in ViewBinder to expected View type", exception); return EMPTY_VIEW_HOLDER; } } private  NativeViewHolder();  }
NativeViewHolder { @NonNull static NativeViewHolder fromViewBinder(@NonNull final View view, @NonNull final ViewBinder viewBinder) { final NativeViewHolder nativeViewHolder = new NativeViewHolder(); try { nativeViewHolder.titleView = (TextView) view.findViewById(viewBinder.titleId); nativeViewHolder.textView = (TextView) view.findViewById(viewBinder.textId); nativeViewHolder.callToActionView = (TextView) view.findViewById(viewBinder.callToActionId); nativeViewHolder.mainImageView = (ImageView) view.findViewById(viewBinder.mainImageId); nativeViewHolder.iconImageView = (ImageView) view.findViewById(viewBinder.iconImageId); return nativeViewHolder; } catch (ClassCastException exception) { MoPubLog.w("Could not cast from id in ViewBinder to expected View type", exception); return EMPTY_VIEW_HOLDER; } } private  NativeViewHolder();   }