### Question:
UpdateActionFactory { public List<UpdateAction> getActions(DeployableService currentService, DeployableServiceSpec newServiceSpec) { DeployableServiceSpec currentServiceSpec = currentService.getSpec(); List<UpdateAction> actions = new ArrayList<UpdateAction>(); logger.info("Calculating changes on service spec \nOld = " + currentServiceSpec + "\nNew = " + newServiceSpec); if (currentServiceSpec.getNumberOfInstances() < newServiceSpec.getNumberOfInstances()) { UpdateAction action = new IncreaseNumberOfReplicas(currentService, newServiceSpec); actions.add(action); } else if (currentServiceSpec.getNumberOfInstances() > newServiceSpec.getNumberOfInstances()) { UpdateAction action = new DecreaseNumberOfReplicas(currentService, newServiceSpec); actions.add(action); } if (!(currentServiceSpec.getResourceImpact() == null || currentServiceSpec.getResourceImpact().getMemory() == null)) { if (!(currentServiceSpec.getResourceImpact().getMemory().ordinal() == newServiceSpec.getResourceImpact() .getMemory().ordinal())) { UpdateAction action = new Migrate(currentService, newServiceSpec); actions.add(action); } } logger.info("Detected changes: " + actions); return actions; }  List<UpdateAction> getActions(DeployableService currentService, DeployableServiceSpec newServiceSpec);  }### Answer:
@Test public void shouldReturnIncreaseReplicas() { DeployableService airlineService = models1.getAirlineService(); DeployableServiceSpec newAirlineSpec = models2.getAirlineSpec(); newAirlineSpec.setNumberOfInstances(3); UpdateActionFactory fac = new UpdateActionFactory(); List<UpdateAction> actions = fac.getActions(airlineService, newAirlineSpec); assertEquals(1, actions.size()); UpdateAction action = actions.get(0); assertEquals(IncreaseNumberOfReplicas.class, action.getClass()); }
@Test public void shouldReturnDecreaseReplicas() { DeployableService airlineService = models1.getAirlineService(); DeployableServiceSpec newAirlineSpec = models2.getAirlineSpec(); newAirlineSpec.setNumberOfInstances(1); UpdateActionFactory fac = new UpdateActionFactory(); List<UpdateAction> actions = fac.getActions(airlineService, newAirlineSpec); assertEquals(1, actions.size()); UpdateAction action = actions.get(0); assertEquals(DecreaseNumberOfReplicas.class, action.getClass()); }
@Test public void shouldReturnMigrate() { DeployableService airlineService = models1.getAirlineService(); DeployableServiceSpec currentAirlineSpec = models1.getAirlineSpec(); ResourceImpact currentImpact = new ResourceImpact(); currentImpact.setMemory(MemoryType.SMALL); currentAirlineSpec.setResourceImpact(currentImpact); DeployableServiceSpec newAirlineSpec = models2.getAirlineSpec(); ResourceImpact newImpact = new ResourceImpact(); newImpact.setMemory(MemoryType.LARGE); newAirlineSpec.setResourceImpact(newImpact); UpdateActionFactory fac = new UpdateActionFactory(); List<UpdateAction> actions = fac.getActions(airlineService, newAirlineSpec); assertEquals(1, actions.size()); UpdateAction action = actions.get(0); assertEquals(Migrate.class, action.getClass()); }