Skip to content
This repository has been archived by the owner on May 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request #47 from trello/dlew/all-events
Browse files Browse the repository at this point in the history
Fixed/simplified behavior around persistable methods
  • Loading branch information
dlew committed Feb 27, 2016
2 parents f726c4f + 5e54a75 commit 9527852
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
15 changes: 9 additions & 6 deletions navi/src/main/java/com/trello/navi/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class Event<T> {
* Emits {@link Activity#onCreate(Bundle, PersistableBundle)}. Emitted after super().
*/
public static final Event<BundleBundle> CREATE_PERSISTABLE =
new Event<>(Type.CREATE, BundleBundle.class);
new Event<>(Type.CREATE_PERSISTABLE, BundleBundle.class);

/**
* Emits {@link Activity#onStart()} and {@link Fragment#onStart()}. Emitted after super().
Expand Down Expand Up @@ -74,14 +74,14 @@ public final class Event<T> {
* Emits {@link Activity#onSaveInstanceState(Bundle)} and
* {@link Fragment#onSaveInstanceState(Bundle)}. Emitted after super().
*/
public static final Event<BundleBundle> SAVE_INSTANCE_STATE_PERSISTABLE =
new Event<>(Type.SAVE_INSTANCE_STATE, BundleBundle.class);
public static final Event<Bundle> SAVE_INSTANCE_STATE =
new Event<>(Type.SAVE_INSTANCE_STATE, Bundle.class);

/**
* Emits {@link Activity#onSaveInstanceState(Bundle, PersistableBundle)}. Emitted after super().
*/
public static final Event<Bundle> SAVE_INSTANCE_STATE =
new Event<>(Type.SAVE_INSTANCE_STATE, Bundle.class);
public static final Event<BundleBundle> SAVE_INSTANCE_STATE_PERSISTABLE =
new Event<>(Type.SAVE_INSTANCE_STATE_PERSISTABLE, BundleBundle.class);

/**
* Emits {@link Activity#onConfigurationChanged(Configuration)} and
Expand Down Expand Up @@ -120,7 +120,7 @@ public final class Event<T> {
* super().
*/
public static final Event<BundleBundle> RESTORE_INSTANCE_STATE_PERSISTABLE =
new Event<>(Type.RESTORE_INSTANCE_STATE, BundleBundle.class);
new Event<>(Type.RESTORE_INSTANCE_STATE_PERSISTABLE, BundleBundle.class);

/**
* Emits {@link Activity#onNewIntent(Intent)}. Emitted after super().
Expand Down Expand Up @@ -229,8 +229,11 @@ public enum Type {
REQUEST_PERMISSIONS_RESULT,

// Activity-only
CREATE_PERSISTABLE,
RESTART,
SAVE_INSTANCE_STATE_PERSISTABLE,
RESTORE_INSTANCE_STATE,
RESTORE_INSTANCE_STATE_PERSISTABLE,
NEW_INTENT,
BACK_PRESSED,
ATTACHED_TO_WINDOW,
Expand Down
3 changes: 0 additions & 3 deletions navi/src/main/java/com/trello/navi/internal/NaviEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void onCreate(Bundle savedInstanceState) {
}

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
emitEvent(Event.CREATE, savedInstanceState);
emitEvent(Event.CREATE_PERSISTABLE, new BundleBundle(savedInstanceState, persistentState));
}

Expand Down Expand Up @@ -214,7 +213,6 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
}

public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
emitEvent(Event.RESTORE_INSTANCE_STATE, savedInstanceState);
emitEvent(Event.RESTORE_INSTANCE_STATE_PERSISTABLE,
new BundleBundle(savedInstanceState, persistentState));
}
Expand All @@ -228,7 +226,6 @@ public void onSaveInstanceState(Bundle outState) {
}

public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
emitEvent(Event.SAVE_INSTANCE_STATE, outState);
emitEvent(Event.SAVE_INSTANCE_STATE_PERSISTABLE,
new BundleBundle(outState, outPersistentState));
}
Expand Down
5 changes: 3 additions & 2 deletions navi/src/test/java/com/trello/navi/AllEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;

Expand Down Expand Up @@ -49,8 +48,10 @@ public final class AllEventTest {

Bundle bundle = new Bundle();
PersistableBundle persistableBundle = mock(PersistableBundle.class);
emitter.onCreate(bundle);
emitter.onCreate(bundle, persistableBundle);
verify(listener, times(2)).call(Type.CREATE);
verify(listener).call(Type.CREATE);
verify(listener).call(Type.CREATE_PERSISTABLE);

emitter.removeListener(listener);
emitter.onCreate(bundle, persistableBundle);
Expand Down
7 changes: 4 additions & 3 deletions navi/src/test/java/com/trello/navi/NaviActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;

public final class NaviActivityTest {

Expand Down Expand Up @@ -45,7 +46,7 @@ public final class NaviActivityTest {
Bundle bundle = new Bundle();
PersistableBundle persistableBundle = mock(PersistableBundle.class);
emitter.onCreate(bundle, persistableBundle);
verify(listener).call(bundle);
verifyZeroInteractions(listener);
verify(persistableListener).call(new BundleBundle(bundle, persistableBundle));

emitter.removeListener(listener);
Expand Down Expand Up @@ -149,7 +150,7 @@ public final class NaviActivityTest {
Bundle bundle = new Bundle();
PersistableBundle persistableBundle = mock(PersistableBundle.class);
emitter.onSaveInstanceState(bundle, persistableBundle);
verify(listener).call(bundle);
verifyZeroInteractions(listener);
verify(persistableListener).call(new BundleBundle(bundle, persistableBundle));

emitter.removeListener(listener);
Expand Down Expand Up @@ -181,7 +182,7 @@ public final class NaviActivityTest {
Bundle bundle = new Bundle();
PersistableBundle persistableBundle = mock(PersistableBundle.class);
emitter.onRestoreInstanceState(bundle, persistableBundle);
verify(listener).call(bundle);
verifyZeroInteractions(listener);
verify(persistableListener).call(new BundleBundle(bundle, persistableBundle));

emitter.removeListener(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public final class RxNaviAllEventTest {

Bundle bundle = new Bundle();
PersistableBundle persistableBundle = mock(PersistableBundle.class);
emitter.onCreate(bundle);
emitter.onCreate(bundle, persistableBundle);
subscription.unsubscribe();
emitter.onCreate(bundle);
emitter.onCreate(bundle, persistableBundle);

testSubscriber.assertValues(Type.CREATE, Type.CREATE);
testSubscriber.assertValues(Type.CREATE, Type.CREATE_PERSISTABLE);
testSubscriber.assertNoTerminalEvent();
testSubscriber.assertUnsubscribed();
}
Expand Down

0 comments on commit 9527852

Please sign in to comment.