Search in sources :

Example 1 with DataBundle

use of com.armueller.fluxytodo.actions.DataBundle in project FluxyAndroidTodo by armueller.

the class TodoListManagerTest method createTodos.

private void createTodos(final int numberOfTodos) throws InterruptedException {
    for (int i = 0; i < numberOfTodos; i++) {
        DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
        bundle.put(TodoAction.DataKeys.DESCRIPTION, "Testing " + i);
        actionBus.post(new TodoAction(TodoAction.ActionTypes.ADD, bundle));
        Thread.sleep(10);
    }
}
Also used : DataBundle(com.armueller.fluxytodo.actions.DataBundle) TodoAction(com.armueller.fluxytodo.actions.TodoAction)

Example 2 with DataBundle

use of com.armueller.fluxytodo.actions.DataBundle in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method setEditModeActiveForTodoIdTest.

@Test(timeout = 100)
public void setEditModeActiveForTodoIdTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    DataBundle<ViewAction.DataKeys> bundle = new DataBundle<>();
    bundle.put(ViewAction.DataKeys.ID, 2);
    dataBus.post(new ViewAction(ViewAction.ActionTypes.MARK_EDITABLE, bundle));
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(Long todoId) {
            assertThat(todoId).isEqualTo(2);
            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) ViewAction(com.armueller.fluxytodo.actions.ViewAction) Subscribe(com.squareup.otto.Subscribe) Test(org.junit.Test)

Example 3 with DataBundle

use of com.armueller.fluxytodo.actions.DataBundle 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)

Example 4 with DataBundle

use of com.armueller.fluxytodo.actions.DataBundle in project FluxyAndroidTodo by armueller.

the class TodoListManagerTest method completeTodoTest.

@Test(timeout = 100)
public void completeTodoTest() throws InterruptedException {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    final ArrayList<TodoItem> todoItems = new ArrayList<TodoItem>();
    createTodos(2);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(RawTodoList rawTodoList) {
            todoItems.clear();
            todoItems.addAll(rawTodoList.list);
            if (!todoItems.get(1).isComplete()) {
                DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
                bundle.put(TodoAction.DataKeys.ID, todoItems.get(1).getId());
                actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle));
            } else {
                assertThat(todoItems.get(0).isComplete()).isFalse();
                assertThat(todoItems.get(1).isComplete()).isTrue();
                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)

Example 5 with DataBundle

use of com.armueller.fluxytodo.actions.DataBundle in project FluxyAndroidTodo by armueller.

the class TodoListManagerTest method deleteTodoTest.

@Test(timeout = 100)
public void deleteTodoTest() throws InterruptedException {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    final AtomicLong deletedId = new AtomicLong(-1);
    final ArrayList<TodoItem> todoItems = new ArrayList<TodoItem>();
    createTodos(3);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(RawTodoList rawTodoList) {
            todoItems.clear();
            todoItems.addAll(rawTodoList.list);
            if (todoItems.size() == 3) {
                deletedId.set(todoItems.get(1).getId());
                DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
                bundle.put(TodoAction.DataKeys.ID, todoItems.get(1).getId());
                actionBus.post(new TodoAction(TodoAction.ActionTypes.DELETE, bundle));
            } else {
                assertThat(todoItems.size()).isEqualTo(2);
                assertThat(todoItems.get(0).getId()).isNotEqualTo(deletedId.get());
                assertThat(todoItems.get(1).getId()).isNotEqualTo(deletedId.get());
                testDone.set(true);
            }
        }
    });
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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

DataBundle (com.armueller.fluxytodo.actions.DataBundle)8 TodoAction (com.armueller.fluxytodo.actions.TodoAction)7 Subscribe (com.squareup.otto.Subscribe)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Test (org.junit.Test)7 RawTodoList (com.armueller.fluxytodo.data.RawTodoList)5 ArrayList (java.util.ArrayList)5 ViewAction (com.armueller.fluxytodo.actions.ViewAction)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1