Skip to content

Commit

Permalink
Doc tweak for Flow.Listener#go, unit test for that contract.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrjr committed Sep 14, 2014
1 parent 2a1c1cd commit ce90f92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions flow-sample/src/main/java/com/example/flow/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override public void go(Backstack backstack, Flow.Direction direction) {
Object screen = backstack.current().getScreen();
@Override public void go(Backstack nextBackstack, Flow.Direction direction) {
Object screen = nextBackstack.current().getScreen();
containerView.displayView(getView(screen), direction);

setTitle(screen.getClass().getSimpleName());
Expand Down Expand Up @@ -155,7 +155,7 @@ class ActivityModule {
}

@Provides @Singleton Parcer<Object> provideParcer(Gson gson) {
return new GsonParcer<Object>(gson);
return new GsonParcer<>(gson);
}
}
}
7 changes: 6 additions & 1 deletion flow/src/main/java/flow/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public enum Direction {
}

public interface Listener {
void go(Backstack backstack, Direction direction);
/**
* Notifies the listener that the backstack is about to change. Note that the change
* will not take effect until this method returns. That is, {@code nextBackstack} is where
* the Flow is going next, and {@link Flow#getBackstack()} is where it's coming from.
*/
void go(Backstack nextBackstack, Direction direction);
}

private final Listener listener;
Expand Down
25 changes: 17 additions & 8 deletions flow/src/test/java/flow/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static class Tres implements HasParent<Dos> {
Flow.Direction lastDirection;

class FlowListener implements Flow.Listener {
@Override public void go(Backstack backstack, Flow.Direction direction) {
lastStack = backstack;
@Override public void go(Backstack nextBackstack, Flow.Direction direction) {
lastStack = nextBackstack;
lastDirection = direction;
}
}
Expand Down Expand Up @@ -69,6 +69,21 @@ class FlowListener implements Flow.Listener {
assertThat(flow.goBack()).isFalse();
}

@Test public void backstackChangesAfterListenerCall() {
final Backstack firstBackstack = Backstack.single(new Uno());

class Ourrobouros implements Flow.Listener {
Flow flow = new Flow(firstBackstack ,this);

@Override public void go(Backstack nextBackstack, Flow.Direction direction) {
assertThat(firstBackstack).isSameAs(flow.getBackstack());
}
}

Ourrobouros listener = new Ourrobouros();
listener.flow.goTo(new Dos());
}

@Test public void noUpNoUps() {
Backstack backstack = Backstack.single(new Uno());
Flow flow = new Flow(backstack, new FlowListener());
Expand Down Expand Up @@ -350,12 +365,6 @@ public int hashCode() {
}
}

private static abstract class ChildScreen extends Screen implements HasParent<Screen> {
ChildScreen(String name) {
super(name);
}
}

static class Able extends Screen {
Able() {
super("Able");
Expand Down

0 comments on commit ce90f92

Please sign in to comment.