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);
}
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);
}
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();
}
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()) ;
}
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;
}
Aggregations