@Test public void shouldGetInventoryForSupervisedFacilities() throws Exception { long userId = 1L; long typeId = 1L; long programId = 1L; long equipmentTypeId = 1L; long facilityId = 1L; List<EquipmentInventory> expectedEquipments = new ArrayList<>(); expectedEquipments.add(new EquipmentInventory()); Facility facility = new Facility(facilityId); List<Facility> facilities = new ArrayList<>(); facilities.add(facility); long[] facilityIds = {facilityId}; Pagination page = new Pagination(1, 2); when(facilityService.getUserSupervisedFacilities(userId, programId, MANAGE_EQUIPMENT_INVENTORY)).thenReturn(facilities); when(repository.getInventory(programId, equipmentTypeId, facilityIds, page)).thenReturn(expectedEquipments); List<EquipmentInventory> equipments = service.getInventory(userId, typeId, programId, equipmentTypeId, page); verify(facilityService).getUserSupervisedFacilities(userId, programId, MANAGE_EQUIPMENT_INVENTORY); verify(repository).getInventory(programId, equipmentTypeId, facilityIds, page); assertEquals(equipments, expectedEquipments); }
public List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination) { long[] facilityIds = getFacilityIds(userId, typeId, programId); return repository.getInventory(programId, equipmentTypeId, facilityIds, pagination); }
EquipmentInventoryService { public List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination) { long[] facilityIds = getFacilityIds(userId, typeId, programId); return repository.getInventory(programId, equipmentTypeId, facilityIds, pagination); } }
EquipmentInventoryService { public List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination) { long[] facilityIds = getFacilityIds(userId, typeId, programId); return repository.getInventory(programId, equipmentTypeId, facilityIds, pagination); }  }
EquipmentInventoryService { public List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination) { long[] facilityIds = getFacilityIds(userId, typeId, programId); return repository.getInventory(programId, equipmentTypeId, facilityIds, pagination); }  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 List<EquipmentInventory> getInventory(Long userId, Long typeId, Long programId, Long equipmentTypeId, Pagination pagination) { long[] facilityIds = getFacilityIds(userId, typeId, programId); return repository.getInventory(programId, equipmentTypeId, facilityIds, pagination); }  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();  }