Search in sources :

Example 81 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method setEditModeInactiveForTodoIdTest.

@Test(timeout = 100)
public void setEditModeInactiveForTodoIdTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(TodoAction todoAction) {
            assertThat(todoAction.getType()).isEqualTo(TodoAction.ActionTypes.EDIT);
            assertThat(todoAction.getData().get(TodoAction.DataKeys.ID, -1)).isEqualTo(2);
            assertThat(todoAction.getData().get(TodoAction.DataKeys.DESCRIPTION, "")).isEqualTo("Test");
            testDone.set(true);
        }
    });
    DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
    bundle.put(TodoAction.DataKeys.ID, 2);
    bundle.put(TodoAction.DataKeys.DESCRIPTION, "Test");
    dataBus.post(new TodoAction(TodoAction.ActionTypes.EDIT, bundle));
    // Wait for test to finish or timeout
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataBundle(com.armueller.fluxytodo.actions.DataBundle) Subscribe(com.squareup.otto.Subscribe) TodoAction(com.armueller.fluxytodo.actions.TodoAction) Test(org.junit.Test)

Example 82 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method shouldShowUndoButtonTest.

@Test(timeout = 100)
public void shouldShowUndoButtonTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    dataBus.post(new TodoAction(TodoAction.ActionTypes.DELETE_ALL));
    dataBus.register(new Object() {

        @Subscribe
        public void onListUpdated(Boolean shouldShowUndoButton) {
            assertThat(shouldShowUndoButton).isTrue();
            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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TodoAction(com.armueller.fluxytodo.actions.TodoAction) Test(org.junit.Test)

Example 83 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method changeActiveFilterToCompleteTest.

@Test(timeout = 100)
public void changeActiveFilterToCompleteTest() {
    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(1);
            assertThat(filteredTodoList.filter).isEqualTo(FilteredTodoList.Filter.COMPLETE);
            testDone.set(true);
        }
    });
    dataBus.post(new ViewAction(ViewAction.ActionTypes.VIEW_COMPLETE));
    // 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 84 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class TodosActivityStoreTest method changeActiveFilterToActiveTest.

@Test(timeout = 100)
public void changeActiveFilterToActiveTest() {
    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(2);
            assertThat(filteredTodoList.filter).isEqualTo(FilteredTodoList.Filter.ACTIVE);
            testDone.set(true);
        }
    });
    dataBus.post(new ViewAction(ViewAction.ActionTypes.VIEW_ACTIVE));
    // 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 85 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class TodosActivityStore method reactToViewAction.

@Subscribe
public final void reactToViewAction(ViewAction action) {
    DataBundle<ViewAction.DataKeys> data = action.getData();
    long id = (long) data.get(ViewAction.DataKeys.ID, -1);
    switch(action.getType()) {
        case VIEW_ALL:
            activeFilter = FilteredTodoList.Filter.ACTIVE;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case VIEW_ACTIVE:
            activeFilter = FilteredTodoList.Filter.COMPLETE;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case VIEW_COMPLETE:
            activeFilter = FilteredTodoList.Filter.ALL;
            dataBus.post(new FilteredTodoList(activeFilter, rawTodoList));
            break;
        case MARK_EDITABLE:
            editModeActiveForTodoId = new Long(id);
            dataBus.post(editModeActiveForTodoId);
            break;
    }
}
Also used : FilteredTodoList(com.armueller.fluxytodo.data.FilteredTodoList) Subscribe(com.squareup.otto.Subscribe)

Aggregations

Subscribe (com.squareup.otto.Subscribe)86 Test (org.junit.Test)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 RawTodoList (com.armueller.fluxytodo.data.RawTodoList)13 ArrayList (java.util.ArrayList)12 TodoAction (com.armueller.fluxytodo.actions.TodoAction)9 VideoData (com.zype.android.webapi.model.video.VideoData)8 DataBundle (com.armueller.fluxytodo.actions.DataBundle)7 File (com.zype.android.webapi.model.player.File)7 Intent (android.content.Intent)6 FilteredTodoList (com.armueller.fluxytodo.data.FilteredTodoList)6 ConsumerFavoriteVideoData (com.zype.android.webapi.model.consumers.ConsumerFavoriteVideoData)6 Bundle (android.os.Bundle)5 Video (com.zype.android.Db.Entity.Video)5 Consumer (com.zype.android.webapi.model.consumers.Consumer)5 IOException (java.io.IOException)5 Context (android.content.Context)4 ConnectivityManager (android.net.ConnectivityManager)4 NetworkInfo (android.net.NetworkInfo)4 Dialog (android.app.Dialog)3