@Test public void shouldSaveChangesInExistingEquipmentInventory() throws Exception { EquipmentType equipmentType = new EquipmentType(); equipmentType.setColdChain(false); equipmentType.setId(1L); Equipment equipment = new Equipment(); equipment.setEquipmentType(equipmentType); equipment.setEquipmentTypeId(equipmentType.getId()); equipment.setManufacturer("Manu"); equipment.setModel("123"); EquipmentInventory inventory = new EquipmentInventory(); inventory.setId(1L); inventory.setSerialNumber("123"); inventory.setEquipment(equipment); List<Equipment> equipments = new ArrayList<>(); equipments.add(equipment); when(equipmentService.getAllByType(1L)).thenReturn(equipments); service.save(inventory); verify(equipmentRepository, never()).insert(equipment); verify(equipmentRepository).update(equipment); verify(repository, never()).insert(inventory); verify(repository).update(inventory); }
public void save(EquipmentInventory inventory){ Equipment equipment = inventory.getEquipment(); if (!equipment.getEquipmentType().isColdChain()) { Boolean equipmentFound = false; Long equipmentTypeId = equipment.getEquipmentTypeId(); List<Equipment> equipments = equipmentService.getAllByType(equipmentTypeId); for (Equipment e : equipments) { if (e.equalsByMakeAndModel(equipment)) { equipmentFound = true; equipment = e; break; } } equipment.setModifiedBy(inventory.getModifiedBy()); if (!equipmentFound) { equipment.setCreatedBy(inventory.getCreatedBy()); equipmentRepository.insert(equipment); } else { equipmentRepository.update(equipment); } inventory.setEquipmentId(equipment.getId()); } if(inventory.getId() == null){ repository.insert(inventory); } else{ repository.update(inventory); } }
EquipmentInventoryService { public void save(EquipmentInventory inventory){ Equipment equipment = inventory.getEquipment(); if (!equipment.getEquipmentType().isColdChain()) { Boolean equipmentFound = false; Long equipmentTypeId = equipment.getEquipmentTypeId(); List<Equipment> equipments = equipmentService.getAllByType(equipmentTypeId); for (Equipment e : equipments) { if (e.equalsByMakeAndModel(equipment)) { equipmentFound = true; equipment = e; break; } } equipment.setModifiedBy(inventory.getModifiedBy()); if (!equipmentFound) { equipment.setCreatedBy(inventory.getCreatedBy()); equipmentRepository.insert(equipment); } else { equipmentRepository.update(equipment); } inventory.setEquipmentId(equipment.getId()); } if(inventory.getId() == null){ repository.insert(inventory); } else{ repository.update(inventory); } } }
EquipmentInventoryService { public void save(EquipmentInventory inventory){ Equipment equipment = inventory.getEquipment(); if (!equipment.getEquipmentType().isColdChain()) { Boolean equipmentFound = false; Long equipmentTypeId = equipment.getEquipmentTypeId(); List<Equipment> equipments = equipmentService.getAllByType(equipmentTypeId); for (Equipment e : equipments) { if (e.equalsByMakeAndModel(equipment)) { equipmentFound = true; equipment = e; break; } } equipment.setModifiedBy(inventory.getModifiedBy()); if (!equipmentFound) { equipment.setCreatedBy(inventory.getCreatedBy()); equipmentRepository.insert(equipment); } else { equipmentRepository.update(equipment); } inventory.setEquipmentId(equipment.getId()); } if(inventory.getId() == null){ repository.insert(inventory); } else{ repository.update(inventory); } }  }
EquipmentInventoryService { public void save(EquipmentInventory inventory){ Equipment equipment = inventory.getEquipment(); if (!equipment.getEquipmentType().isColdChain()) { Boolean equipmentFound = false; Long equipmentTypeId = equipment.getEquipmentTypeId(); List<Equipment> equipments = equipmentService.getAllByType(equipmentTypeId); for (Equipment e : equipments) { if (e.equalsByMakeAndModel(equipment)) { equipmentFound = true; equipment = e; break; } } equipment.setModifiedBy(inventory.getModifiedBy()); if (!equipmentFound) { equipment.setCreatedBy(inventory.getCreatedBy()); equipmentRepository.insert(equipment); } else { equipmentRepository.update(equipment); } inventory.setEquipmentId(equipment.getId()); } if(inventory.getId() == null){ repository.insert(inventory); } else{ repository.update(inventory); } }  List<EquipmentInventory> getInventoryForFacility(Long facilityId, Long programId); List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination); Integer getInventoryCount(Long userId, Long typeId, Long programId, Long equipmentTypeId); EquipmentInventory getInventoryById(Long id); void save(EquipmentInventory inventory); void updateStatus(EquipmentInventory inventory); void updateNonFunctionalEquipments(); }
EquipmentInventoryService { public void save(EquipmentInventory inventory){ Equipment equipment = inventory.getEquipment(); if (!equipment.getEquipmentType().isColdChain()) { Boolean equipmentFound = false; Long equipmentTypeId = equipment.getEquipmentTypeId(); List<Equipment> equipments = equipmentService.getAllByType(equipmentTypeId); for (Equipment e : equipments) { if (e.equalsByMakeAndModel(equipment)) { equipmentFound = true; equipment = e; break; } } equipment.setModifiedBy(inventory.getModifiedBy()); if (!equipmentFound) { equipment.setCreatedBy(inventory.getCreatedBy()); equipmentRepository.insert(equipment); } else { equipmentRepository.update(equipment); } inventory.setEquipmentId(equipment.getId()); } if(inventory.getId() == null){ repository.insert(inventory); } else{ repository.update(inventory); } }  List<EquipmentInventory> getInventoryForFacility(Long facilityId, Long programId); List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination); Integer getInventoryCount(Long userId, Long typeId, Long programId, Long equipmentTypeId); EquipmentInventory getInventoryById(Long id); void save(EquipmentInventory inventory); void updateStatus(EquipmentInventory inventory); void updateNonFunctionalEquipments();  }