Search in sources :

Example 1 with DataBindingHolder

use of com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder 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());
}
Also used : DataBindingHolder(com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder) ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) Test(org.junit.Test)

Example 2 with DataBindingHolder

use of com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder 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());
}
Also used : DataBindingHolder(com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder) ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) Test(org.junit.Test)

Aggregations

DataBindingHolder (com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder)2 ModelWithDataBindingBindingModel_ (com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_)2 Test (org.junit.Test)2