Router { public boolean goBack() { if (!backStack.isEmpty()) { List<Screen> fromPath = backStack.asList(); backStack.pop(); performRouteChange(fromPath, backStack.asList(), TransitionDirection.EXIT); if (!backStack.isEmpty() || allowEmptyStack) { return true; } } return false; } Router();  Router(boolean allowEmptyStack); boolean goBack(); void goTo(Screen nextScreen); void replaceWith(Screen nextScreen); void replaceAllWith(Screen... screens); void replaceAllWith(List<Screen> screens); void resetTo(Screen screen); void resetTo(Screen nextScreen, TransitionDirection direction); boolean hasActiveScreen();  }
@Test public void goBack() { router = new TestRouter(false); Screen screenA = new ScreenA(); Screen screenB = new ScreenB(); router.goTo(screenA); router.goTo(screenB); assertTrue(router.goBack()); assertEquals(screenA, router.fromPath.get(0)); assertEquals(screenB, router.fromPath.get(1)); assertEquals(screenA, router.toPath.get(0)); assertEquals(TransitionDirection.EXIT, router.direction); assertEquals(3, router.routeChangeCount); }
@Test public void goBackNoScreens() { router = new TestRouter(true); assertFalse(router.goBack()); assertEquals(0, router.routeChangeCount); }