use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class ModelClickListenerTest method modelClickListenerIsDiffed.
@Test
public void modelClickListenerIsDiffed() {
// Internally we wrap the model click listener with an anonymous click listener. We can't hash
// the anonymous click listener since that changes the model state, instead our anonymous
// click listener should use the hashCode of the user's click listener
ModelClickListener modelClickListener = new ModelClickListener();
ViewClickListener viewClickListener = new ViewClickListener();
TestController controller = new TestController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithClickListener_ model = new ModelWithClickListener_();
controller.setModel(model);
controller.requestModelBuild();
verify(observerMock).onItemRangeInserted(eq(0), eq(1));
model = new ModelWithClickListener_();
model.clickListener(modelClickListener);
controller.setModel(model);
lifecycleHelper.buildModelsAndBind(controller);
// The second update shouldn't cause a item change
model = new ModelWithClickListener_();
model.clickListener(modelClickListener);
controller.setModel(model);
lifecycleHelper.buildModelsAndBind(controller);
model = new ModelWithClickListener_();
model.clickListener(viewClickListener);
controller.setModel(model);
lifecycleHelper.buildModelsAndBind(controller);
verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any());
verifyNoMoreInteractions(observerMock);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class DataBindingModelIntegrationTest method typesWithOutHashCodeAreNotDiffed.
@Test
public void typesWithOutHashCodeAreNotDiffed() {
SimpleEpoxyController controller = new SimpleEpoxyController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().clickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
}).id(1);
controller.setModels(Collections.singletonList(firstModel));
verify(observerMock).onItemRangeInserted(0, 1);
ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().clickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
}).id(1);
controller.setModels(Collections.singletonList(secondModel));
verifyNoMoreInteractions(observerMock);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class EpoxyControllerTest method basicBuildModels.
@Test
public void basicBuildModels() {
AdapterDataObserver observer = mock(AdapterDataObserver.class);
EpoxyController controller = new EpoxyController() {
@Override
protected void buildModels() {
new TestModel().addTo(this);
}
@Override
protected void onExceptionSwallowed(RuntimeException exception) {
noExceptionsDuringBasicBuildModels = false;
}
};
controller.getAdapter().registerAdapterDataObserver(observer);
controller.requestModelBuild();
assertTrue(noExceptionsDuringBasicBuildModels);
assertEquals(1, controller.getAdapter().getItemCount());
verify(observer).onItemRangeInserted(0, 1);
verifyNoMoreInteractions(observer);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class DataBindingModelIntegrationTest method typesWithHashCodeAreDiffed.
@Test
public void typesWithHashCodeAreDiffed() {
SimpleEpoxyController controller = new SimpleEpoxyController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("value1").id(1);
controller.setModels(Collections.singletonList(firstModel));
verify(observerMock).onItemRangeInserted(0, 1);
ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("value2").id(1);
controller.setModels(Collections.singletonList(secondModel));
verify(observerMock).onItemRangeChanged(eq(0), eq(1), any());
verifyNoMoreInteractions(observerMock);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class ModelClickListenerTest method viewClickListenerIsDiffed.
@Test
public void viewClickListenerIsDiffed() {
TestController controller = new TestController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithClickListener_ model = new ModelWithClickListener_();
controller.setModel(model);
controller.requestModelBuild();
verify(observerMock).onItemRangeInserted(eq(0), eq(1));
ViewClickListener viewClickListener = new ViewClickListener();
model = new ModelWithClickListener_();
model.clickListener(viewClickListener);
controller.setModel(model);
controller.requestModelBuild();
// The second update shouldn't cause a item change
model = new ModelWithClickListener_();
model.clickListener(viewClickListener);
controller.setModel(model);
controller.requestModelBuild();
ModelClickListener modelClickListener = new ModelClickListener();
model = new ModelWithClickListener_();
model.clickListener(modelClickListener);
controller.setModel(model);
controller.requestModelBuild();
verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any());
verifyNoMoreInteractions(observerMock);
}
Aggregations