use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.
the class DataBindingModelIntegrationTest method createDataBindingModel.
@Test
public void createDataBindingModel() {
SimpleEpoxyController controller = new SimpleEpoxyController();
ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("hello").id(1);
controller.setModels(Collections.singletonList(firstModel));
ControllerLifecycleHelper lifecycleHelper = new ControllerLifecycleHelper();
EpoxyViewHolder viewHolder = lifecycleHelper.createViewHolder(controller.getAdapter(), 0);
controller.getAdapter().onBindViewHolder(viewHolder, 0);
DataBindingHolder dataBindingHolder = ((DataBindingHolder) viewHolder.objectToBind());
assertNotNull(dataBindingHolder.getDataBinding());
// Check that the requiredText was set on the view
assertEquals(firstModel.stringValue(), ((Button) viewHolder.itemView).getText());
ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("hello again").id(1);
controller.setModels(Collections.singletonList(secondModel));
List<Object> payloads = DiffPayloadTestUtil.payloadsWithChangedModels(firstModel);
controller.getAdapter().onBindViewHolder(viewHolder, 0, payloads);
// Check that the requiredText was updated after the change payload
assertEquals(secondModel.stringValue(), ((Button) viewHolder.itemView).getText());
}
use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ 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 com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.
the class DataBindingModelIntegrationTest method fullyCreateDataBindingModel.
@Test
public void fullyCreateDataBindingModel() {
SimpleEpoxyController controller = new SimpleEpoxyController();
ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("hello").id(1);
controller.setModels(Collections.singletonList(firstModel));
ControllerLifecycleHelper lifecycleHelper = new ControllerLifecycleHelper();
EpoxyViewHolder viewHolder = lifecycleHelper.createViewHolder(controller.getAdapter(), 0);
controller.getAdapter().onBindViewHolder(viewHolder, 0);
DataBindingHolder dataBindingHolder = ((DataBindingHolder) viewHolder.objectToBind());
assertNotNull(dataBindingHolder.getDataBinding());
// Check that the requiredText was set on the view
assertEquals(firstModel.stringValue(), ((Button) viewHolder.itemView).getText());
ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("hello again").id(1);
controller.setModels(Collections.singletonList(secondModel));
List<Object> payloads = DiffPayloadTestUtil.payloadsWithChangedModels(firstModel);
controller.getAdapter().onBindViewHolder(viewHolder, 0, payloads);
// Check that the requiredText was updated after the change payload
assertEquals(secondModel.stringValue(), ((Button) viewHolder.itemView).getText());
}
use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ 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);
}
Aggregations