Search in sources :

Example 1 with FilteredTodoList

use of com.armueller.fluxytodo.data.FilteredTodoList in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method updateRawTodoListConnectedTest.

// Test:
// todoActionPerformed
@Test(timeout = 100)
public void updateRawTodoListConnectedTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    RawTodoList rawTodoList = new RawTodoList();
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(FilteredTodoList filteredTodoList) {
            assertThat(filteredTodoList.list.size()).isEqualTo(0);
            testDone.set(true);
        }
    });
    dataBus.post(rawTodoList);
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) Subscribe(com.squareup.otto.Subscribe) RawTodoList(com.armueller.fluxytodo.data.RawTodoList) Test(org.junit.Test)

Example 2 with FilteredTodoList

use of com.armueller.fluxytodo.data.FilteredTodoList in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method changeActiveFilterToAllTest.

@Test(timeout = 100)
public void changeActiveFilterToAllTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    ArrayList<TodoItem> list = new ArrayList<TodoItem>();
    list.add(new TodoItem(1, "Test", false));
    list.add(new TodoItem(2, "Test", true));
    list.add(new TodoItem(3, "Test", false));
    RawTodoList rawTodoList = new RawTodoList(list);
    dataBus.post(rawTodoList);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(FilteredTodoList filteredTodoList) {
            assertThat(filteredTodoList.list.size()).isEqualTo(3);
            assertThat(filteredTodoList.filter).isEqualTo(FilteredTodoList.Filter.ALL);
            testDone.set(true);
        }
    });
    dataBus.post(new ViewAction(ViewAction.ActionTypes.VIEW_ALL));
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TodoItem(com.armueller.fluxytodo.models.TodoItem) FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) ViewAction(com.armueller.fluxytodo.actions.ViewAction) ArrayList(java.util.ArrayList) Subscribe(com.squareup.otto.Subscribe) RawTodoList(com.armueller.fluxytodo.data.RawTodoList) Test(org.junit.Test)

Example 3 with FilteredTodoList

use of com.armueller.fluxytodo.data.FilteredTodoList in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method changeActiveFilterToCompleteTest.

@Test(timeout = 100)
public void changeActiveFilterToCompleteTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    ArrayList<TodoItem> list = new ArrayList<TodoItem>();
    list.add(new TodoItem(1, "Test", false));
    list.add(new TodoItem(2, "Test", true));
    list.add(new TodoItem(3, "Test", false));
    RawTodoList rawTodoList = new RawTodoList(list);
    dataBus.post(rawTodoList);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(FilteredTodoList filteredTodoList) {
            assertThat(filteredTodoList.list.size()).isEqualTo(1);
            assertThat(filteredTodoList.filter).isEqualTo(FilteredTodoList.Filter.COMPLETE);
            testDone.set(true);
        }
    });
    dataBus.post(new ViewAction(ViewAction.ActionTypes.VIEW_COMPLETE));
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TodoItem(com.armueller.fluxytodo.models.TodoItem) FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) ViewAction(com.armueller.fluxytodo.actions.ViewAction) ArrayList(java.util.ArrayList) Subscribe(com.squareup.otto.Subscribe) RawTodoList(com.armueller.fluxytodo.data.RawTodoList) Test(org.junit.Test)

Example 4 with FilteredTodoList

use of com.armueller.fluxytodo.data.FilteredTodoList in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method changeActiveFilterToActiveTest.

@Test(timeout = 100)
public void changeActiveFilterToActiveTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    ArrayList<TodoItem> list = new ArrayList<TodoItem>();
    list.add(new TodoItem(1, "Test", false));
    list.add(new TodoItem(2, "Test", true));
    list.add(new TodoItem(3, "Test", false));
    RawTodoList rawTodoList = new RawTodoList(list);
    dataBus.post(rawTodoList);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(FilteredTodoList filteredTodoList) {
            assertThat(filteredTodoList.list.size()).isEqualTo(2);
            assertThat(filteredTodoList.filter).isEqualTo(FilteredTodoList.Filter.ACTIVE);
            testDone.set(true);
        }
    });
    dataBus.post(new ViewAction(ViewAction.ActionTypes.VIEW_ACTIVE));
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TodoItem(com.armueller.fluxytodo.models.TodoItem) FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) ViewAction(com.armueller.fluxytodo.actions.ViewAction) ArrayList(java.util.ArrayList) Subscribe(com.squareup.otto.Subscribe) RawTodoList(com.armueller.fluxytodo.data.RawTodoList) Test(org.junit.Test)

Example 5 with FilteredTodoList

use of com.armueller.fluxytodo.data.FilteredTodoList in project FluxyAndroidTodo by armueller.

the class TodosActivityStore method reactToViewAction.

@Subscribe
public final void reactToViewAction(ViewAction action) {
    DataBundle<ViewAction.DataKeys> data = action.getData();
    long id = (long) data.get(ViewAction.DataKeys.ID, -1);
    switch(action.getType()) {
        case VIEW_ALL:
            activeFilter = FilteredTodoList.Filter.ACTIVE;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case VIEW_ACTIVE:
            activeFilter = FilteredTodoList.Filter.COMPLETE;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case VIEW_COMPLETE:
            activeFilter = FilteredTodoList.Filter.ALL;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case MARK_EDITABLE:
            editModeActiveForTodoId = new Long(id);
            dataBus.post(editModeActiveForTodoId);
            break;
    }
}
Also used : FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) Subscribe(com.squareup.otto.Subscribe)

Aggregations

FilteredTodoList (com.armueller.fluxytodo.data.FilteredTodoList)6 Subscribe (com.squareup.otto.Subscribe)6 RawTodoList (com.armueller.fluxytodo.data.RawTodoList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.Test)4 ViewAction (com.armueller.fluxytodo.actions.ViewAction)3 TodoItem (com.armueller.fluxytodo.models.TodoItem)3 ArrayList (java.util.ArrayList)3