This repository has been archived by the owner on May 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from trello/dlew/all-listener
Added Event.ALL which automatically emits all events
- Loading branch information
Showing
5 changed files
with
230 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.trello.navi; | ||
|
||
import android.os.Bundle; | ||
import android.os.PersistableBundle; | ||
import com.trello.navi.Event.Type; | ||
import com.trello.navi.internal.BaseNaviComponent; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
public final class AllEventTest { | ||
|
||
private final BaseNaviComponent activity = BaseNaviComponent.createActivityComponent(); | ||
|
||
// Test event without listener params works | ||
@Test public void startAllListener() { | ||
Listener<Type> listener = mock(Listener.class); | ||
activity.addListener(Event.ALL, listener); | ||
|
||
activity.onStart(); | ||
verify(listener).call(Type.START); | ||
|
||
activity.removeListener(Event.ALL, listener); | ||
activity.onStart(); | ||
verifyNoMoreInteractions(listener); | ||
} | ||
|
||
// Test event with listener params works | ||
@Test public void createAllListener() { | ||
Listener<Type> listener = mock(Listener.class); | ||
activity.addListener(Event.ALL, listener); | ||
|
||
Bundle bundle = new Bundle(); | ||
activity.onCreate(bundle); | ||
verify(listener).call(Type.CREATE); | ||
|
||
activity.removeListener(Event.ALL, listener); | ||
activity.onCreate(bundle); | ||
verifyNoMoreInteractions(listener); | ||
} | ||
|
||
// Test persistable Activities | ||
@Test public void createPersistableListener() { | ||
Listener<Type> listener = mock(Listener.class); | ||
activity.addListener(Event.ALL, listener); | ||
|
||
Bundle bundle = new Bundle(); | ||
PersistableBundle persistableBundle = mock(PersistableBundle.class); | ||
activity.onCreate(bundle, persistableBundle); | ||
verify(listener, times(2)).call(Type.CREATE); | ||
|
||
activity.removeListener(Event.ALL, listener); | ||
activity.onCreate(bundle, persistableBundle); | ||
verifyNoMoreInteractions(listener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
navi/src/test/java/com/trello/navi/rx/RxNaviAllEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.trello.navi.rx; | ||
|
||
import android.os.Bundle; | ||
import android.os.PersistableBundle; | ||
import com.trello.navi.Event; | ||
import com.trello.navi.Event.Type; | ||
import com.trello.navi.internal.BaseNaviComponent; | ||
import org.junit.Test; | ||
import rx.Subscription; | ||
import rx.observers.TestSubscriber; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
public final class RxNaviAllEventTest { | ||
|
||
private final BaseNaviComponent activity = BaseNaviComponent.createActivityComponent(); | ||
|
||
// Test event without listener params works | ||
@Test public void observeAllStart() { | ||
TestSubscriber<Type> testSubscriber = new TestSubscriber<>(); | ||
Subscription subscription = RxNavi.observe(activity, Event.ALL).subscribe(testSubscriber); | ||
testSubscriber.assertNoValues(); | ||
|
||
activity.onStart(); | ||
subscription.unsubscribe(); | ||
activity.onStart(); | ||
|
||
testSubscriber.assertValue(Type.START); | ||
testSubscriber.assertNoTerminalEvent(); | ||
testSubscriber.assertUnsubscribed(); | ||
} | ||
|
||
// Test event with listener params works | ||
@Test public void observeAllCreate() { | ||
TestSubscriber<Type> testSubscriber = new TestSubscriber<>(); | ||
Subscription subscription = RxNavi.observe(activity, Event.ALL).subscribe(testSubscriber); | ||
testSubscriber.assertNoValues(); | ||
|
||
Bundle bundle = new Bundle(); | ||
activity.onCreate(bundle); | ||
subscription.unsubscribe(); | ||
activity.onCreate(bundle); | ||
|
||
testSubscriber.assertValue(Type.CREATE); | ||
testSubscriber.assertNoTerminalEvent(); | ||
testSubscriber.assertUnsubscribed(); | ||
} | ||
|
||
// Test persistable Activities | ||
@Test public void observeAllCreatePersistable() { | ||
TestSubscriber<Type> testSubscriber = new TestSubscriber<>(); | ||
Subscription subscription = RxNavi.observe(activity, Event.ALL).subscribe(testSubscriber); | ||
testSubscriber.assertNoValues(); | ||
|
||
Bundle bundle = new Bundle(); | ||
PersistableBundle persistableBundle = mock(PersistableBundle.class); | ||
activity.onCreate(bundle, persistableBundle); | ||
subscription.unsubscribe(); | ||
activity.onCreate(bundle, persistableBundle); | ||
|
||
testSubscriber.assertValues(Type.CREATE, Type.CREATE); | ||
testSubscriber.assertNoTerminalEvent(); | ||
testSubscriber.assertUnsubscribed(); | ||
} | ||
} |