@Test public void shouldGetAllProgramsWithProductsByFacilityCode() { Facility facility = new Facility(123L); when(facilityService.getFacilityByCode("F1")).thenReturn(facility); List<Program> programsInFacility = new ArrayList(); Program program1 = makeProgram("PR1", "Program 1"); Program program2 = makeProgram("PR2", "Program 2"); programsInFacility.add(program1); programsInFacility.add(program2); when(programService.getByFacility(123L)).thenReturn(programsInFacility); Product product1 = makeProduct("PD1", "Product 1"); Product product2 = makeProduct("PD2", "Product 2"); Product product3 = makeProduct("PD3", "Product 3"); List<ProgramProduct> programProducts1 = new ArrayList(); programProducts1.add(makeProgramProduct(program1, product1)); programProducts1.add(makeProgramProduct(program1, product2)); List<ProgramProduct> programProducts2 = new ArrayList(); programProducts2.add(makeProgramProduct(program2, product3)); when(programProductService.getByProgram(program1)).thenReturn(programProducts1); when(programProductService.getByProgram(program2)).thenReturn(programProducts2); ProgramWithProducts programWithProducts1 = new ProgramWithProductsBuilder().withProgramCode("PR1").withProgramName("Program 1") .addProduct(product1).addProduct(product2).build(); ProgramWithProducts programWithProducts2 = new ProgramWithProductsBuilder().withProgramCode("PR2").withProgramName("Program 2") .addProduct(product3).build(); List<ProgramWithProducts> programsWithProducts = restProgramsService.getAllProgramsWithProductsByFacilityCode("F1"); assertEquals(2, programsWithProducts.size()); assertEquals(programWithProducts1, programsWithProducts.get(0)); assertEquals(programWithProducts2, programsWithProducts.get(1)); }
public List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); List<ProgramWithProducts> programsWithProducts = new ArrayList(); for (Program program : programService.getByFacility(facility.getId())) { ProgramWithProducts programWithProducts = new ProgramWithProducts(); programWithProducts.setProgramCode(program.getCode()); programWithProducts.setProgramName(program.getName()); List<Product> products = new ArrayList(); for (ProgramProduct programProduct : programProductService.getByProgram(program)) { products.add(programProduct.getProduct()); } programWithProducts.setProducts(products); programsWithProducts.add(programWithProducts); } return programsWithProducts; }
RestProgramsService { public List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); List<ProgramWithProducts> programsWithProducts = new ArrayList(); for (Program program : programService.getByFacility(facility.getId())) { ProgramWithProducts programWithProducts = new ProgramWithProducts(); programWithProducts.setProgramCode(program.getCode()); programWithProducts.setProgramName(program.getName()); List<Product> products = new ArrayList(); for (ProgramProduct programProduct : programProductService.getByProgram(program)) { products.add(programProduct.getProduct()); } programWithProducts.setProducts(products); programsWithProducts.add(programWithProducts); } return programsWithProducts; } }
RestProgramsService { public List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); List<ProgramWithProducts> programsWithProducts = new ArrayList(); for (Program program : programService.getByFacility(facility.getId())) { ProgramWithProducts programWithProducts = new ProgramWithProducts(); programWithProducts.setProgramCode(program.getCode()); programWithProducts.setProgramName(program.getName()); List<Product> products = new ArrayList(); for (ProgramProduct programProduct : programProductService.getByProgram(program)) { products.add(programProduct.getProduct()); } programWithProducts.setProducts(products); programsWithProducts.add(programWithProducts); } return programsWithProducts; }  }
RestProgramsService { public List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); List<ProgramWithProducts> programsWithProducts = new ArrayList(); for (Program program : programService.getByFacility(facility.getId())) { ProgramWithProducts programWithProducts = new ProgramWithProducts(); programWithProducts.setProgramCode(program.getCode()); programWithProducts.setProgramName(program.getName()); List<Product> products = new ArrayList(); for (ProgramProduct programProduct : programProductService.getByProgram(program)) { products.add(programProduct.getProduct()); } programWithProducts.setProducts(products); programsWithProducts.add(programWithProducts); } return programsWithProducts; }  List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode); }
RestProgramsService { public List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); List<ProgramWithProducts> programsWithProducts = new ArrayList(); for (Program program : programService.getByFacility(facility.getId())) { ProgramWithProducts programWithProducts = new ProgramWithProducts(); programWithProducts.setProgramCode(program.getCode()); programWithProducts.setProgramName(program.getName()); List<Product> products = new ArrayList(); for (ProgramProduct programProduct : programProductService.getByProgram(program)) { products.add(programProduct.getProduct()); } programWithProducts.setProducts(products); programsWithProducts.add(programWithProducts); } return programsWithProducts; }  List<ProgramWithProducts> getAllProgramsWithProductsByFacilityCode(String facilityCode);  }