Upgrades { public final int applyUpgradesSince( int lastId, Context resources ) { int lastUpgradeId = lastId; for (UpgradeOperation op : operations) { if (op.getId() <= lastId) continue; LOGGER.debug("Upgrade {0}: starting", op); op.apply(resources); LOGGER.debug("Upgrade {0}: complete", op); lastUpgradeId = op.getId(); } return lastUpgradeId; } protected  Upgrades( UpgradeOperation... operations ); final int applyUpgradesSince( int lastId,
                                         Context resources ); final boolean isUpgradeRequired( int lastId ); final int getLatestAvailableUpgradeId(); static final Upgrades STANDARD_UPGRADES; }
@Test public void shouldApplyOnlyLatestUpgrades() throws Exception { testUpgrades.applyUpgradesSince(0, null); operation1.assertCalled(); operation2.assertCalled(); operation3.assertCalled(); testUpgrades.applyUpgradesSince(1, null); operation1.assertCalled(); operation2.assertCalled(); operation3.assertCalled(); testUpgrades.applyUpgradesSince(2, null); operation1.assertNotCalled(); operation2.assertCalled(); operation3.assertCalled(); testUpgrades.applyUpgradesSince(3, null); operation1.assertNotCalled(); operation2.assertNotCalled(); operation3.assertCalled(); testUpgrades.applyUpgradesSince(4, null); operation1.assertNotCalled(); operation2.assertNotCalled(); operation3.assertNotCalled(); testUpgrades.applyUpgradesSince(5, null); operation1.assertNotCalled(); operation2.assertNotCalled(); operation3.assertNotCalled(); }