CollectionView extends FrameLayout { void showError(Throwable throwable) { if (adapter == null) { throw new NullPointerException("adapter is null"); } refreshLayout.setRefreshing(false); final View errorView; final Class<? extends Throwable> errorClass = throwable.getClass(); if (errorViewHolder.containsKey(errorClass)) { errorView = errorViewHolder.get(errorClass); } else { errorView = adapter.onCreateErrorView(this, throwable); errorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (presenter != null) { presenter.onLoad(); } } }); errorViewHolder.put(errorClass, errorView); } addView(errorView, lpWrapWrapCenter()); } CollectionView(
      @NonNull Context context,
      @Nullable AttributeSet attrs); @SuppressWarnings("unchecked") @Override void onAttachedToWindow(); @Override void onDetachedFromWindow(); void setAdapter(@NonNull Adapter adapter);  }
@Test public void testShowError() throws Exception { tested.showLoading(); tested.showError(emptyError); assertThat(tested.refreshLayout.isRefreshing()).isFalse(); assertThat(tested.getChildAt(1)).isEqualTo(emptyView); tested.showLoading(); tested.showError(networkError); assertThat(tested.refreshLayout.isRefreshing()).isFalse(); assertThat(tested.getChildAt(1)).isEqualTo(errorView); }