Search in sources :

Example 1 with RawTodoList

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

the class TodoListManager method reactToTodoAction.

@Subscribe
public void reactToTodoAction(TodoAction action) {
    DataBundle<TodoAction.DataKeys> data = action.getData();
    long id = (long) data.get(TodoAction.DataKeys.ID, -1L);
    String description = (String) data.get(TodoAction.DataKeys.DESCRIPTION, "");
    switch(action.getType()) {
        case ADD:
            addTodo(description);
            break;
        case TOGGLE:
            toggleTodoComplete(id);
            break;
        case TOGGLE_ALL:
            toggleAllTodosComplete();
            break;
        case EDIT:
            editTodo(id, description);
            break;
        case DELETE:
            deleteTodo(id);
            break;
        case DELETE_ALL:
            deleteAllCompleteTodos();
            break;
        case UNDO_DELETE_ALL:
            undoDeleteCompleteAllTodos();
            break;
    }
    dataBus.post(new RawTodoList(todoItems));
}
Also used : RawTodoList(com.armueller.fluxytodo.data.RawTodoList) Subscribe(com.squareup.otto.Subscribe)

Example 2 with RawTodoList

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

the class TodoListManagerTest method createMultipleTodosTest.

@Test(timeout = 100)
public void createMultipleTodosTest() throws InterruptedException {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    createTodos(4);
    dataBus.register(new Object() {

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

Example 3 with RawTodoList

use of com.armueller.fluxytodo.data.RawTodoList 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 4 with RawTodoList

use of com.armueller.fluxytodo.data.RawTodoList 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 5 with RawTodoList

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

the class TodoListManagerTest method undoDeleteAllCompleteTodosTest.

@Test(timeout = 100)
public void undoDeleteAllCompleteTodosTest() throws InterruptedException {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    final AtomicBoolean checkedTodo1 = new AtomicBoolean(false);
    final AtomicBoolean checkedTodo3 = new AtomicBoolean(false);
    final AtomicBoolean deletedTodos = new AtomicBoolean(false);
    final AtomicBoolean undidDelete = new AtomicBoolean(false);
    final ArrayList<TodoItem> todoItems = new ArrayList<TodoItem>();
    createTodos(4);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(RawTodoList rawTodoList) {
            todoItems.clear();
            todoItems.addAll(rawTodoList.list);
            if (!checkedTodo1.get()) {
                checkedTodo1.set(true);
                DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
                bundle.put(TodoAction.DataKeys.ID, todoItems.get(1).getId());
                actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle));
                return;
            }
            if (!checkedTodo3.get()) {
                checkedTodo3.set(true);
                DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
                bundle.put(TodoAction.DataKeys.ID, todoItems.get(3).getId());
                actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle));
                return;
            }
            if (!deletedTodos.get() && checkedTodo1.get() && checkedTodo3.get()) {
                deletedTodos.set(true);
                actionBus.post(new TodoAction(TodoAction.ActionTypes.DELETE_ALL));
                return;
            }
            if (!undidDelete.get() && deletedTodos.get()) {
                undidDelete.set(true);
                actionBus.post(new TodoAction(TodoAction.ActionTypes.UNDO_DELETE_ALL));
                return;
            }
            if (undidDelete.get() && deletedTodos.get()) {
                assertThat(todoItems.size()).isEqualTo(4);
                testDone.set(true);
            }
        }
    });
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataBundle(com.armueller.fluxytodo.actions.DataBundle) ArrayList(java.util.ArrayList) Subscribe(com.squareup.otto.Subscribe) RawTodoList(com.armueller.fluxytodo.data.RawTodoList) TodoAction(com.armueller.fluxytodo.actions.TodoAction) Test(org.junit.Test)

Aggregations

RawTodoList (com.armueller.fluxytodo.data.RawTodoList)13 Subscribe (com.squareup.otto.Subscribe)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 TodoAction (com.armueller.fluxytodo.actions.TodoAction)6 DataBundle (com.armueller.fluxytodo.actions.DataBundle)5 FilteredTodoList (com.armueller.fluxytodo.data.FilteredTodoList)4 ViewAction (com.armueller.fluxytodo.actions.ViewAction)3 TodoItem (com.armueller.fluxytodo.models.TodoItem)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)1