@Test public void shouldGetParentFacilityOnlyIfChildNotAnOrphan() throws Exception { String facilityCode = "F19"; Long facilityId = 1L; Long parentFacilityId = 2L; Facility facility = new Facility(); facility.setId(facilityId); facility.setParentFacilityId(parentFacilityId); Facility parentFacility = new Facility(); parentFacility.setId(parentFacilityId); FacilityFeedDTO expectedFacilityFeedDTO = new FacilityFeedDTO(); when(facilityService.getFacilityByCode(facilityCode)).thenReturn(facility); when(facilityService.getById(parentFacilityId)).thenReturn(parentFacility); whenNew(FacilityFeedDTO.class).withArguments(facility, parentFacility).thenReturn(expectedFacilityFeedDTO); FacilityFeedDTO facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); verify(facilityService).getFacilityByCode(facilityCode); verify(facilityService).getById(parentFacilityId); assertThat(facilityFeedDTO, is(expectedFacilityFeedDTO)); verifyNew(FacilityFeedDTO.class).withArguments(facility,parentFacility); }
public FacilityFeedDTO getFacilityByCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getParentFacilityId() != null) { parentFacility = facilityService.getById(facility.getParentFacilityId()); } return new FacilityFeedDTO(facility, parentFacility); }
RestFacilityService { public FacilityFeedDTO getFacilityByCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getParentFacilityId() != null) { parentFacility = facilityService.getById(facility.getParentFacilityId()); } return new FacilityFeedDTO(facility, parentFacility); } }
RestFacilityService { public FacilityFeedDTO getFacilityByCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getParentFacilityId() != null) { parentFacility = facilityService.getById(facility.getParentFacilityId()); } return new FacilityFeedDTO(facility, parentFacility); }  }
RestFacilityService { public FacilityFeedDTO getFacilityByCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getParentFacilityId() != null) { parentFacility = facilityService.getById(facility.getParentFacilityId()); } return new FacilityFeedDTO(facility, parentFacility); }  FacilityFeedDTO getFacilityByCode(String facilityCode); }
RestFacilityService { public FacilityFeedDTO getFacilityByCode(String facilityCode) { Facility facility = facilityService.getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getParentFacilityId() != null) { parentFacility = facilityService.getById(facility.getParentFacilityId()); } return new FacilityFeedDTO(facility, parentFacility); }  FacilityFeedDTO getFacilityByCode(String facilityCode);  }