@Test public void shouldGetAllProgramProductsByProgramCodeAndFacilityTypeCode() { List<ProgramProduct> expectedProgramProducts = new ArrayList<>(); when(programRepository.getIdByCode("P1")).thenReturn(10L); FacilityType warehouse = new FacilityType("warehouse"); when(facilityTypeRepository.getByCodeOrThrowException(warehouse.getCode())).thenReturn(warehouse); when(programProductRepository.getProgramProductsBy(10L, "warehouse")).thenReturn(expectedProgramProducts); List<ProgramProduct> programProducts = service.getProgramProductsBy(" P1", " warehouse"); assertThat(programProducts, is(expectedProgramProducts)); verify(facilityTypeRepository).getByCodeOrThrowException(warehouse.getCode()); verify(programRepository).getIdByCode("P1"); verify(programProductRepository).getProgramProductsBy(10L, "warehouse"); }
public List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode) { FacilityType facilityType = new FacilityType(); if ((facilityTypeCode = trimToNull(facilityTypeCode)) != null) { facilityType = facilityTypeRepository.getByCodeOrThrowException(facilityTypeCode); } return programProductRepository.getProgramProductsBy(programRepository.getIdByCode(trimToEmpty(programCode)), facilityType.getCode()); }
ProgramProductService { public List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode) { FacilityType facilityType = new FacilityType(); if ((facilityTypeCode = trimToNull(facilityTypeCode)) != null) { facilityType = facilityTypeRepository.getByCodeOrThrowException(facilityTypeCode); } return programProductRepository.getProgramProductsBy(programRepository.getIdByCode(trimToEmpty(programCode)), facilityType.getCode()); } }
ProgramProductService { public List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode) { FacilityType facilityType = new FacilityType(); if ((facilityTypeCode = trimToNull(facilityTypeCode)) != null) { facilityType = facilityTypeRepository.getByCodeOrThrowException(facilityTypeCode); } return programProductRepository.getProgramProductsBy(programRepository.getIdByCode(trimToEmpty(programCode)), facilityType.getCode()); }  }
ProgramProductService { public List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode) { FacilityType facilityType = new FacilityType(); if ((facilityTypeCode = trimToNull(facilityTypeCode)) != null) { facilityType = facilityTypeRepository.getByCodeOrThrowException(facilityTypeCode); } return programProductRepository.getProgramProductsBy(programRepository.getIdByCode(trimToEmpty(programCode)), facilityType.getCode()); }  Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateProgramProductPrice(ProgramProductPrice programProductPrice); void save(ProgramProduct programProduct); void saveAndLogPriceChange(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); List<ProgramProduct> getByProductCode(String productCode); List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> getActiveByProgram(Long programId); ProgramProduct getByProgramAndProductId(Long programId, Long productId); List<ProgramProduct> search(String searchParam, Pagination pagination, String column); List<ProgramProduct> getUnapprovedProgramProducts(Long facilityTypeId, Long programId); Integer getTotalSearchResultCount(String searchParam, String column); @Transactional void saveAll(List<ProgramProduct> programProducts, Product product); void insertISA(ProgramProductISA isa); void updateISA(ProgramProductISA isa); }
ProgramProductService { public List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode) { FacilityType facilityType = new FacilityType(); if ((facilityTypeCode = trimToNull(facilityTypeCode)) != null) { facilityType = facilityTypeRepository.getByCodeOrThrowException(facilityTypeCode); } return programProductRepository.getProgramProductsBy(programRepository.getIdByCode(trimToEmpty(programCode)), facilityType.getCode()); }  Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateProgramProductPrice(ProgramProductPrice programProductPrice); void save(ProgramProduct programProduct); void saveAndLogPriceChange(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); List<ProgramProduct> getByProductCode(String productCode); List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> getActiveByProgram(Long programId); ProgramProduct getByProgramAndProductId(Long programId, Long productId); List<ProgramProduct> search(String searchParam, Pagination pagination, String column); List<ProgramProduct> getUnapprovedProgramProducts(Long facilityTypeId, Long programId); Integer getTotalSearchResultCount(String searchParam, String column); @Transactional void saveAll(List<ProgramProduct> programProducts, Product product); void insertISA(ProgramProductISA isa); void updateISA(ProgramProductISA isa);  }