use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class EpoxyControllerTest method multipleMoves.
@Test
public void multipleMoves() {
AdapterDataObserver observer = mock(AdapterDataObserver.class);
final List<TestModel> testModels = new ArrayList<>();
testModels.add(new TestModel(1));
testModels.add(new TestModel(2));
testModels.add(new TestModel(3));
EpoxyController controller = new EpoxyController() {
@Override
protected void buildModels() {
add(testModels);
}
};
EpoxyControllerAdapter adapter = controller.getAdapter();
adapter.registerAdapterDataObserver(observer);
controller.requestModelBuild();
testModels.add(0, testModels.remove(1));
controller.moveModel(1, 0);
verify(observer).onItemRangeMoved(1, 0, 1);
testModels.add(2, testModels.remove(1));
controller.moveModel(1, 2);
verify(observer).onItemRangeMoved(1, 2, 1);
assertEquals(testModels, adapter.getCurrentModels());
controller.requestModelBuild();
assertEquals(testModels, adapter.getCurrentModels());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class EpoxyControllerTest method moveModelOtherWay.
@Test
public void moveModelOtherWay() {
AdapterDataObserver observer = mock(AdapterDataObserver.class);
final List<TestModel> testModels = new ArrayList<>();
testModels.add(new TestModel(1));
testModels.add(new TestModel(2));
testModels.add(new TestModel(3));
EpoxyController controller = new EpoxyController() {
@Override
protected void buildModels() {
add(testModels);
}
};
EpoxyControllerAdapter adapter = controller.getAdapter();
adapter.registerAdapterDataObserver(observer);
controller.requestModelBuild();
verify(observer).onItemRangeInserted(0, 3);
testModels.add(2, testModels.remove(1));
controller.moveModel(1, 2);
verify(observer).onItemRangeMoved(1, 2, 1);
assertEquals(testModels, adapter.getCurrentModels());
controller.requestModelBuild();
assertEquals(testModels, adapter.getCurrentModels());
verifyNoMoreInteractions(observer);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class EpoxyControllerTest method moveModel.
@Test
public void moveModel() {
AdapterDataObserver observer = mock(AdapterDataObserver.class);
final List<TestModel> testModels = new ArrayList<>();
testModels.add(new TestModel(1));
testModels.add(new TestModel(2));
testModels.add(new TestModel(3));
EpoxyController controller = new EpoxyController() {
@Override
protected void buildModels() {
add(testModels);
}
};
EpoxyControllerAdapter adapter = controller.getAdapter();
adapter.registerAdapterDataObserver(observer);
controller.requestModelBuild();
verify(observer).onItemRangeInserted(0, 3);
testModels.add(0, testModels.remove(1));
controller.moveModel(1, 0);
verify(observer).onItemRangeMoved(1, 0, 1);
assertEquals(testModels, adapter.getCurrentModels());
controller.requestModelBuild();
assertEquals(testModels, adapter.getCurrentModels());
verifyNoMoreInteractions(observer);
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method bindListenerChangesHashCode.
@Test
public void bindListenerChangesHashCode() {
TestController controller = new TestController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithClickListener_ model = new ModelWithClickListener_();
controller.buildWithModel(model);
verify(observerMock).onItemRangeInserted(eq(0), eq(1));
// shouldn't change
model = new ModelWithClickListener_();
model.onBind(null);
controller.buildWithModel(model);
verify(observerMock, never()).onItemRangeChanged(eq(0), eq(1), any());
model = new ModelWithClickListener_();
BindListener listener1 = new BindListener();
model.onBind(listener1);
controller.buildWithModel(model);
verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any());
model = new ModelWithClickListener_();
model.onBind(listener1);
controller.buildWithModel(model);
verify(observerMock, times(1)).onItemRangeChanged(eq(0), eq(1), any());
}
use of androidx.recyclerview.widget.RecyclerView.AdapterDataObserver in project epoxy by airbnb.
the class OnModelBindListenerTest method nullUnbindListenerChangesHashCode.
@Test
public void nullUnbindListenerChangesHashCode() {
TestController controller = new TestController();
AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
controller.getAdapter().registerAdapterDataObserver(observerMock);
ModelWithClickListener_ model = new ModelWithClickListener_();
controller.buildWithModel(model);
verify(observerMock).onItemRangeInserted(eq(0), eq(1));
model = new ModelWithClickListener_();
model.onUnbind(new UnbindListener());
controller.buildWithModel(model);
model = new ModelWithClickListener_();
model.onUnbind(null);
controller.buildWithModel(model);
verify(observerMock, times(2)).onItemRangeChanged(eq(0), eq(1), any());
}
Aggregations