Search in sources :

Example 1 with TodoItem

use of com.armueller.fluxytodo.models.TodoItem in project FluxyAndroidTodo by armueller.

the class FilteredTodoListTest method filteredTodoListHasActiveTodosTest.

@Test
public void filteredTodoListHasActiveTodosTest() {
    TodoItem t1 = new TodoItem(1, "T1", false);
    TodoItem t2 = new TodoItem(2, "T2", true);
    TodoItem t3 = new TodoItem(3, "T3", true);
    TodoItem t4 = new TodoItem(4, "T4", false);
    list.put(t1.getId(), t1);
    list.put(t2.getId(), t2);
    list.put(t3.getId(), t3);
    list.put(t4.getId(), t4);
    RawTodoList rawTodoList = new RawTodoList(list);
    FilteredTodoList filteredTodoList = new FilteredTodoList(FilteredTodoList.Filter.ACTIVE, rawTodoList);
    assertThat(filteredTodoList.list.size()).isEqualTo(2);
    assertThat(filteredTodoList.list).contains(t1, t4);
}
Also used : TodoItem(com.armueller.fluxytodo.models.TodoItem) Test(org.junit.Test)

Example 2 with TodoItem

use of com.armueller.fluxytodo.models.TodoItem in project FluxyAndroidTodo by armueller.

the class FilteredTodoListTest method filteredTodoListIsSortedTest.

@Test
public void filteredTodoListIsSortedTest() {
    TodoItem t1 = new TodoItem(1, "T1", false);
    TodoItem t2 = new TodoItem(4, "T4", true);
    TodoItem t3 = new TodoItem(2, "T2", true);
    TodoItem t4 = new TodoItem(3, "T3", false);
    list.put(t1.getId(), t1);
    list.put(t2.getId(), t2);
    list.put(t3.getId(), t3);
    list.put(t4.getId(), t4);
    RawTodoList rawTodoList = new RawTodoList(list);
    FilteredTodoList filteredTodoList = new FilteredTodoList(FilteredTodoList.Filter.ALL, rawTodoList);
    assertThat(filteredTodoList.list.get(0).getId()).isEqualTo(1);
    assertThat(filteredTodoList.list.get(1).getId()).isEqualTo(2);
    assertThat(filteredTodoList.list.get(2).getId()).isEqualTo(3);
    assertThat(filteredTodoList.list.get(3).getId()).isEqualTo(4);
}
Also used : TodoItem(com.armueller.fluxytodo.models.TodoItem) Test(org.junit.Test)

Example 3 with TodoItem

use of com.armueller.fluxytodo.models.TodoItem in project FluxyAndroidTodo by armueller.

the class FilteredTodoListTest method createFilteredTodoListFromRawTodoListTest.

@Test
public void createFilteredTodoListFromRawTodoListTest() {
    TodoItem t1 = new TodoItem(1, "T1", false);
    list.put(t1.getId(), t1);
    RawTodoList rawTodoList = new RawTodoList(list);
    FilteredTodoList filteredTodoList = new FilteredTodoList(FilteredTodoList.Filter.ALL, rawTodoList);
    assertThat(filteredTodoList.list).isNotNull();
}
Also used : TodoItem(com.armueller.fluxytodo.models.TodoItem) Test(org.junit.Test)

Example 4 with TodoItem

use of com.armueller.fluxytodo.models.TodoItem 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 TodoItem

use of com.armueller.fluxytodo.models.TodoItem in project FluxyAndroidTodo by armueller.

the class FilteredTodoList method makeFiltered.

private ArrayList<TodoItem> makeFiltered(Filter filter, RawTodoList rawTodoList) {
    ArrayList<TodoItem> newList = new ArrayList<TodoItem>();
    switch(filter) {
        case ALL:
            newList.addAll(rawTodoList.list);
            break;
        case ACTIVE:
            for (TodoItem item : rawTodoList.list) {
                if (!item.isComplete()) {
                    newList.add(item);
                }
            }
            break;
        case COMPLETE:
            for (TodoItem item : rawTodoList.list) {
                if (item.isComplete()) {
                    newList.add(item);
                }
            }
            break;
        default:
            break;
    }
    Collections.sort(newList, new Comparator<TodoItem>() {

        @Override
        public int compare(TodoItem lhs, TodoItem rhs) {
            return (int) (lhs.getId() - rhs.getId());
        }
    });
    return newList;
}
Also used : TodoItem(com.armueller.fluxytodo.models.TodoItem) ArrayList(java.util.ArrayList)

Aggregations

TodoItem (com.armueller.fluxytodo.models.TodoItem)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)5 ViewAction (com.armueller.fluxytodo.actions.ViewAction)3 FilteredTodoList (com.armueller.fluxytodo.data.FilteredTodoList)3 RawTodoList (com.armueller.fluxytodo.data.RawTodoList)3 Subscribe (com.squareup.otto.Subscribe)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 HashMap (java.util.HashMap)1