@Test public void shouldSaveUpdate() throws Exception { ServiceContract contract = new ServiceContract(); contract.setEquipments(new ArrayList<ContractDetail>()); contract.setFacilities(new ArrayList<ContractDetail>()); contract.setServiceTypes(new ArrayList<ContractDetail>()); doNothing().when(mapper).deleteEquipments(any(Long.class)); doNothing().when(mapper).insertEquipment(any(Long.class), any(Long.class)); doNothing().when(mapper).insertFacilities(any(Long.class), any(Long.class)); doNothing().when(mapper).insertServiceTypes(any(Long.class), any(Long.class)); contract.setId(5L); service.save(contract); verify(repository, never()).insert(any(ServiceContract.class)); verify(repository).update(contract); }
public void save(ServiceContract contract){ if(contract.getId() == null){ repository.insert(contract); }else{ repository.update(contract); mapper.deleteFacilities(contract.getId()); for(ContractDetail detail: contract.getFacilities()){ if(detail.getIsActive()){ mapper.insertFacilities(contract.getId(), detail.getId()); } } mapper.deleteEquipments(contract.getId()); for(ContractDetail detail: contract.getEquipments()){ if(detail.getIsActive()){ mapper.insertEquipment(contract.getId(), detail.getId()); } } mapper.deleteServiceTypes(contract.getId()); for(ContractDetail detail: contract.getServiceTypes()){ if(detail.getIsActive()){ mapper.insertServiceTypes(contract.getId(), detail.getId()); } } } }
ServiceContractService { public void save(ServiceContract contract){ if(contract.getId() == null){ repository.insert(contract); }else{ repository.update(contract); mapper.deleteFacilities(contract.getId()); for(ContractDetail detail: contract.getFacilities()){ if(detail.getIsActive()){ mapper.insertFacilities(contract.getId(), detail.getId()); } } mapper.deleteEquipments(contract.getId()); for(ContractDetail detail: contract.getEquipments()){ if(detail.getIsActive()){ mapper.insertEquipment(contract.getId(), detail.getId()); } } mapper.deleteServiceTypes(contract.getId()); for(ContractDetail detail: contract.getServiceTypes()){ if(detail.getIsActive()){ mapper.insertServiceTypes(contract.getId(), detail.getId()); } } } } }
ServiceContractService { public void save(ServiceContract contract){ if(contract.getId() == null){ repository.insert(contract); }else{ repository.update(contract); mapper.deleteFacilities(contract.getId()); for(ContractDetail detail: contract.getFacilities()){ if(detail.getIsActive()){ mapper.insertFacilities(contract.getId(), detail.getId()); } } mapper.deleteEquipments(contract.getId()); for(ContractDetail detail: contract.getEquipments()){ if(detail.getIsActive()){ mapper.insertEquipment(contract.getId(), detail.getId()); } } mapper.deleteServiceTypes(contract.getId()); for(ContractDetail detail: contract.getServiceTypes()){ if(detail.getIsActive()){ mapper.insertServiceTypes(contract.getId(), detail.getId()); } } } }  }
ServiceContractService { public void save(ServiceContract contract){ if(contract.getId() == null){ repository.insert(contract); }else{ repository.update(contract); mapper.deleteFacilities(contract.getId()); for(ContractDetail detail: contract.getFacilities()){ if(detail.getIsActive()){ mapper.insertFacilities(contract.getId(), detail.getId()); } } mapper.deleteEquipments(contract.getId()); for(ContractDetail detail: contract.getEquipments()){ if(detail.getIsActive()){ mapper.insertEquipment(contract.getId(), detail.getId()); } } mapper.deleteServiceTypes(contract.getId()); for(ContractDetail detail: contract.getServiceTypes()){ if(detail.getIsActive()){ mapper.insertServiceTypes(contract.getId(), detail.getId()); } } } }  List<ServiceContract> getAll(); List<ServiceContract> getAllForFacility(Long facilityId); List<ServiceContract> getAllForVendor(Long vendorId); List<ServiceContract> getAllForEquipment(Long equipmentId); ServiceContract getById(Long id); void save(ServiceContract contract); }
ServiceContractService { public void save(ServiceContract contract){ if(contract.getId() == null){ repository.insert(contract); }else{ repository.update(contract); mapper.deleteFacilities(contract.getId()); for(ContractDetail detail: contract.getFacilities()){ if(detail.getIsActive()){ mapper.insertFacilities(contract.getId(), detail.getId()); } } mapper.deleteEquipments(contract.getId()); for(ContractDetail detail: contract.getEquipments()){ if(detail.getIsActive()){ mapper.insertEquipment(contract.getId(), detail.getId()); } } mapper.deleteServiceTypes(contract.getId()); for(ContractDetail detail: contract.getServiceTypes()){ if(detail.getIsActive()){ mapper.insertServiceTypes(contract.getId(), detail.getId()); } } } }  List<ServiceContract> getAll(); List<ServiceContract> getAllForFacility(Long facilityId); List<ServiceContract> getAllForVendor(Long vendorId); List<ServiceContract> getAllForEquipment(Long equipmentId); ServiceContract getById(Long id); void save(ServiceContract contract);  }