@Test public void shouldNotGetParentFacilityIfChildIsAnOrphan() throws Exception { String facilityCode = "F19"; Long facilityId = 1L; Facility facility = new Facility(); facility.setId(facilityId); FacilityFeedDTO expectedFacilityFeedDTO = new FacilityFeedDTO(); when(facilityService.getFacilityByCode(facilityCode)).thenReturn(facility); Facility parentFacility = null; whenNew(FacilityFeedDTO.class).withArguments(facility, parentFacility).thenReturn(expectedFacilityFeedDTO); FacilityFeedDTO facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); verify(facilityService).getFacilityByCode(facilityCode); 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);  }