ScreenScooper { public Scoop create(Scoop rootScoop, Scoop currentScreenScoop, List<Screen> fromPath, List<Screen> toPath) { Scoop finalScoop = null; List<Scoop> scoops = getCurrentScoops(fromPath, currentScreenScoop); int index = 0; while (index < fromPath.size() && currentScreenScoop != null) { Screen fromScreen = safeElementGet(fromPath, index); Screen toScreen = safeElementGet(toPath, index); Scoop scoop = scoops.get(index); if (Screen.equals(fromScreen, toScreen)) { finalScoop = scoop; } else { scoop.destroy(); break; } index++; } while (index < toPath.size()) { Screen toScreen = safeElementGet(toPath, index); if (finalScoop == null) { finalScoop = rootScoop; } finalScoop = screenScoopFactory.createScreenScoop(toScreen, finalScoop); index++; } return finalScoop; } ScreenScooper(ScreenScoopFactory screenScoopFactory); Scoop create(Scoop rootScoop, Scoop currentScreenScoop, List<Screen> fromPath, List<Screen> toPath);  }
@Test public void createScoopFromEmptyPathToEmptyPath() { Scoop scoop = screenScooper.create(rootScoop, null, Collections.<Screen>emptyList(), Collections.<Screen>emptyList()); assertFalse(rootScoop.isDestroyed()); assertNull(scoop); }
@Test public void createScoopFromEmptyPathToAPath() { List<Screen> toPath = Arrays.<Screen>asList(new ScreenA()); Scoop aScoop = screenScooper.create(rootScoop, null, Collections.<Screen>emptyList(), toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertEquals(rootScoop, aScoop.getParent()); }
@Test public void createScoopFromEmptyPathToABPath() { List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); Scoop bScoop = screenScooper.create(rootScoop, null, Collections.<Screen>emptyList(), toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(bScoop.getParent().isDestroyed()); assertFalse(bScoop.isDestroyed()); assertEquals(rootScoop, bScoop.getParent().getParent()); }
@Test public void createScoopFromAPathToABPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScooper.create(rootScoop, aScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertFalse(bScoop.isDestroyed()); assertEquals(aScoop, bScoop.getParent()); }
@Test public void createScoopFromAPathToABPathWithNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); Scoop bScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(bScoop.isDestroyed()); assertEquals(rootScoop, bScoop.getParent().getParent()); }
@Test public void createScoopFromABPathToAPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop scoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertTrue(bScoop.isDestroyed()); assertEquals(aScoop, scoop); }
@Test public void createScoopFromABPathToAPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA()); Scoop scoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertEquals(rootScoop, scoop.getParent()); }
@Test public void createScoopFromABPathToEmptyPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop scoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertTrue(aScoop.isDestroyed()); assertTrue(bScoop.isDestroyed()); assertNull(scoop); }
@Test public void createScoopFromABPathToEmptyPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(); Scoop scoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertNull(scoop); }
@Test public void createScoopFromABCPathToAPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop cScoop = screenScoopFactory.createScreenScoop(new ScreenC(), bScoop); Scoop scoop = screenScooper.create(rootScoop, cScoop, fromPath, toPath); assertTrue(bScoop.isDestroyed()); assertTrue(cScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(aScoop, scoop); }
@Test public void createScoopFromABPathToBCPathToCCPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenB()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScooper.create(rootScoop, aScoop, fromPath, toPath); assertNotEquals(aScoop, bScoop); fromPath = Arrays.<Screen>asList(new ScreenB()); toPath = Arrays.<Screen>asList(new ScreenC()); Scoop cScoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertNotEquals(bScoop, cScoop); fromPath = Arrays.<Screen>asList(new ScreenC()); toPath = Arrays.<Screen>asList(new ScreenC()); Scoop scoop = screenScooper.create(rootScoop, cScoop, fromPath, toPath); assertNotEquals(bScoop, scoop); }
@Test public void createScoopFromABCPathToAPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA()); Scoop scoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(scoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(rootScoop, scoop.getParent()); }
@Test public void createScoopFromAPathToABCPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop cScoop = screenScooper.create(rootScoop, aScoop, fromPath, toPath); assertFalse(cScoop.getParent().isDestroyed()); assertFalse(cScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(aScoop, cScoop.getParent().getParent()); }
@Test public void createScoopFromAPathToABCPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); Scoop cScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(cScoop.getParent().getParent().isDestroyed()); assertFalse(cScoop.getParent().isDestroyed()); assertFalse(cScoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(rootScoop, cScoop.getParent().getParent().getParent()); }
@Test public void createScoopFromAPathToBPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenB()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScooper.create(rootScoop, aScoop, fromPath, toPath); assertTrue(aScoop.isDestroyed()); assertFalse(bScoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(rootScoop, bScoop.getParent()); }
@Test public void createScoopFromAPathToBPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenB()); Scoop bScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(bScoop.isDestroyed()); assertFalse(rootScoop.isDestroyed()); assertEquals(rootScoop, bScoop.getParent()); }
@Test public void createScoopFromABPathToACPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenC()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop cScoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertTrue(bScoop.isDestroyed()); assertFalse(cScoop.isDestroyed()); assertEquals(aScoop, cScoop.getParent()); }
@Test public void createScoopFromABPathToACPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenC()); Scoop cScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(cScoop.getParent().isDestroyed()); assertFalse(cScoop.isDestroyed()); assertEquals(rootScoop, cScoop.getParent().getParent()); }
@Test public void createScoopFromABPathToCDPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenC(), new ScreenD()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop dScoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertTrue(aScoop.isDestroyed()); assertTrue(bScoop.isDestroyed()); assertFalse(dScoop.getParent().isDestroyed()); assertFalse(dScoop.isDestroyed()); assertEquals(rootScoop, dScoop.getParent().getParent()); }
@Test public void createScoopFromABPathToCDPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenC(), new ScreenD()); Scoop dScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(dScoop.getParent().isDestroyed()); assertFalse(dScoop.isDestroyed()); assertEquals(rootScoop, dScoop.getParent().getParent()); }
@Test public void createScoopFromABPathToABCPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop cScoop = screenScooper.create(rootScoop, bScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertFalse(bScoop.isDestroyed()); assertFalse(cScoop.isDestroyed()); assertEquals(rootScoop, cScoop.getParent().getParent().getParent()); }
@Test public void createScoopFromABPathToABCPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); Scoop cScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(cScoop.getParent().getParent().isDestroyed()); assertFalse(cScoop.getParent().isDestroyed()); assertFalse(cScoop.isDestroyed()); assertEquals(rootScoop, cScoop.getParent().getParent().getParent()); }
@Test public void createScoopFromABCPathToABDPath() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenD()); Scoop aScoop = screenScoopFactory.createScreenScoop(new ScreenA(), rootScoop); Scoop bScoop = screenScoopFactory.createScreenScoop(new ScreenB(), aScoop); Scoop cScoop = screenScoopFactory.createScreenScoop(new ScreenC(), bScoop); Scoop dScoop = screenScooper.create(rootScoop, cScoop, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(aScoop.isDestroyed()); assertFalse(bScoop.isDestroyed()); assertFalse(dScoop.isDestroyed()); assertTrue(cScoop.isDestroyed()); assertEquals(rootScoop, dScoop.getParent().getParent().getParent()); }
@Test public void createScoopFromABCPathToABDPathNullCurrentScoop() { List<Screen> fromPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenC()); List<Screen> toPath = Arrays.<Screen>asList(new ScreenA(), new ScreenB(), new ScreenD()); Scoop dScoop = screenScooper.create(rootScoop, null, fromPath, toPath); assertFalse(rootScoop.isDestroyed()); assertFalse(dScoop.getParent().getParent().isDestroyed()); assertFalse(dScoop.getParent().isDestroyed()); assertFalse(dScoop.isDestroyed()); assertEquals(rootScoop, dScoop.getParent().getParent().getParent()); }