Search in sources :

Example 6 with RawTodoList

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

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

Example 8 with RawTodoList

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

the class TodoListManagerTest method createTodoTest.

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

        @Subscribe
        public void onListUpdated(RawTodoList rawTodoList) {
            assertThat(rawTodoList.list.size()).isEqualTo(1);
            assertThat(rawTodoList.list.get(0).getDescription()).isEqualTo("Testing 0");
            assertThat(rawTodoList.list.get(0).isComplete()).isFalse();
            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 9 with RawTodoList

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

the class TodoListManagerTest method editTodoTest.

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

        @Subscribe
        public void onListUpdated(RawTodoList rawTodoList) {
            todoItems.clear();
            todoItems.addAll(rawTodoList.list);
            if (todoItems.get(0).getDescription().equals("Testing 0")) {
                DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
                bundle.put(TodoAction.DataKeys.ID, todoItems.get(0).getId());
                bundle.put(TodoAction.DataKeys.DESCRIPTION, "New Todo Description");
                actionBus.post(new TodoAction(TodoAction.ActionTypes.EDIT, bundle));
            } else {
                assertThat(todoItems.get(0).getDescription()).isEqualTo("New Todo Description");
                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 10 with RawTodoList

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

the class TodoListManagerTest method deleteAllCompleteTodosTest.

@Test(timeout = 100)
public void deleteAllCompleteTodosTest() throws InterruptedException {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    final AtomicBoolean checkedTodo1 = new AtomicBoolean(false);
    final AtomicBoolean checkedTodo3 = new AtomicBoolean(false);
    final AtomicBoolean deleted = 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 (!deleted.get() && checkedTodo1.get() && checkedTodo3.get()) {
                deleted.set(true);
                actionBus.post(new TodoAction(TodoAction.ActionTypes.DELETE_ALL));
                return;
            }
            if (deleted.get()) {
                assertThat(todoItems.size()).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) 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