@Test public void getItemViewType_should_returnCorrectViewTypeOfAdapterViewTypeDelegateForAGivenPosition() throws Exception { //GIVEN StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate0 = new StubAdapterViewTypeDelegate(); StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate1 = new StubAdapterViewTypeDelegate(); List<ViewItem> items = new ArrayList<>(); List<FeatureController<String>> featureControllers = asList( new StubFeatureController<>( asList(stubAdapterViewTypeDelegate0, stubAdapterViewTypeDelegate1), items)); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); fixAdapterForTesting(featuresAdapter); items.add(new ViewItem<>("a0", stubAdapterViewTypeDelegate0)); items.add(new ViewItem<>("a1", stubAdapterViewTypeDelegate1)); featuresAdapter.updateFeatureItems("a"); //WHEN final int viewType0 = featuresAdapter.getItemViewType(0); final int viewType1 = featuresAdapter.getItemViewType(1); //THEN assertThat(viewType0, is(stubAdapterViewTypeDelegate0.getViewType())); assertThat(viewType1, is(stubAdapterViewTypeDelegate1.getViewType())); }
@Test public void updateFeatureItems_should_updateOldItems() throws Exception { //GIVEN StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate0 = new StubAdapterViewTypeDelegate(); StubAdapterViewTypeDelegate stubAdapterViewTypeDelegate1 = new StubAdapterViewTypeDelegate(); List<ViewItem> items = new ArrayList<>(); List<FeatureController<String>> featureControllers = asList( new StubFeatureController<>( asList(stubAdapterViewTypeDelegate0, stubAdapterViewTypeDelegate1), items)); FeaturesAdapter<String> featuresAdapter = new FeaturesAdapter<>(featureControllers); fixAdapterForTesting(featuresAdapter); items.add(new ViewItem<>("a0", stubAdapterViewTypeDelegate0)); items.add(new ViewItem<>("a1", stubAdapterViewTypeDelegate1)); featuresAdapter.updateFeatureItems("a"); items.clear(); items.add(new ViewItem<>("a0", stubAdapterViewTypeDelegate0)); items.add(new ViewItem<>("a1", stubAdapterViewTypeDelegate0)); featuresAdapter.updateFeatureItems("a"); //WHEN final int viewType0 = featuresAdapter.getItemViewType(0); final int viewType1 = featuresAdapter.getItemViewType(1); //THEN assertThat(viewType0, is(stubAdapterViewTypeDelegate0.getViewType())); assertThat(viewType1, is(stubAdapterViewTypeDelegate0.getViewType())); }