### Question:
FeaturesAdapter extends RecyclerView.Adapter<ViewHolder> { @VisibleForTesting void validateNewViewItems(FeatureController<MODEL> controller, List<ViewItem> viewItems) { if (viewItems == null || viewItems.isEmpty()) { return; } for (ViewItem viewItem : viewItems) { if(viewItem.viewType == RecyclerView.INVALID_TYPE) { String template = "The Model %s of a ViewItem is associated to a " + "ViewTypeDelegate that has not been " + "registered in the controller %s"; throw new RuntimeException(String.format(template, viewItem.model, controller)); } } } FeaturesAdapter(List<FeatureController<MODEL>> featureControllers); @Override ViewHolder onCreateViewHolder(ViewGroup parent, int viewType); @Override void onBindViewHolder(ViewHolder holder, int position); @Override void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads); @Override int getItemCount(); @Override int getItemViewType(int position); @Override void onViewAttachedToWindow(ViewHolder holder); @Override void onViewDetachedFromWindow(ViewHolder holder); @Override void onViewRecycled(ViewHolder holder); @SuppressWarnings("WeakerAccess") void updateFeatureItems(MODEL model); @SuppressWarnings("unused") int getFirstItemPositionForAdapterViewTypeDelegate(
      AdapterViewTypeDelegate adapterViewTypeDelegate); FeaturesAdapterErrorHandler getFeaturesAdapterErrorHandler(); void setFeaturesAdapterErrorHandler(
      FeaturesAdapterErrorHandler featuresAdapterErrorHandler); AdapterViewTypeDelegate getAdapterViewTypeDelegateForViewType(int viewType);  }### Answer:
@Test(expected = RuntimeException.class) public void registerFeatures_should_throwException_when_delegateIsNotRegistered() throws Exception { StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate = createNiceMock(StubAdapterViewTypeDelegate.class); expect(stubAdapterViewTypeDelegate.getViewType()).andReturn(RecyclerView.INVALID_TYPE).anyTimes(); replay(stubAdapterViewTypeDelegate); List<ViewItem> items = new ArrayList<>(); items.add(new ViewItem<>("a0", stubAdapterViewTypeDelegate)); StubFeatureController<String> controller = new StubFeatureController<>(asList(stubAdapterViewTypeDelegate), items); List<FeatureController<String>> featureControllers = singletonList(controller); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); featuresAdapter.validateNewViewItems(controller, items); }
@Test public void registerFeatures_should_notThrowException_when_listOfViewItemsIsNull() { StubFeatureController<String> controller = new StubFeatureController<>(emptyList(), null); List<FeatureController<String>> featureControllers = singletonList(controller); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); featuresAdapter.validateNewViewItems(controller, null); }
@Test public void registerFeatures_should_notThrowException_when_listOfViewItemsIsEmpty() { StubFeatureController<String> controller = new StubFeatureController<>(emptyList(), emptyList()); List<FeatureController<String>> featureControllers = singletonList(controller); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); featuresAdapter.validateNewViewItems(controller, emptyList()); }
@Test public void registerFeatures_should_notThrowException_when_delegateIsRegistered() { StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate = createNiceMock(StubAdapterViewTypeDelegate.class); expect(stubAdapterViewTypeDelegate.getViewType()).andReturn(0).anyTimes(); replay(stubAdapterViewTypeDelegate); List<ViewItem> items = new ArrayList<>(); items.add(new ViewItem<>("a0", stubAdapterViewTypeDelegate)); items.add(new ViewItem<>("a1", stubAdapterViewTypeDelegate)); StubFeatureController<String> controller = new StubFeatureController<>(asList(stubAdapterViewTypeDelegate), items); List<FeatureController<String>> featureControllers = singletonList(controller); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); featuresAdapter.validateNewViewItems(controller, items); verify(stubAdapterViewTypeDelegate); }