AdminProfileDtoToAdministratorMapper { public Staff map(AdminProfileDto adminProfileDto) { Staff administrator = null; if (adminProfileDto.getUsername() == null) { if (adminProfileDto.getId() != null) { administrator = providerAdminRepository.findOne(adminProfileDto .getId()); } else { administrator = new Staff(); } } else { administrator = providerAdminRepository .findByUsername(adminProfileDto.getUsername()); } administrator.setFirstName(adminProfileDto.getFirstName()); administrator.setLastName(adminProfileDto.getLastName()); administrator.setEmail(adminProfileDto.getEmail()); administrator.setEmployeeID(adminProfileDto.getEmployeeId()); if (StringUtils.hasText(adminProfileDto.getAdministrativeGenderCode())) { AdministrativeGenderCode administrativeGenderCode = administrativeGenderCodeRepository .findByCode(adminProfileDto.getAdministrativeGenderCode()); administrator.setAdministrativeGenderCode(administrativeGenderCode); } else { administrator.setAdministrativeGenderCode(null); } return administrator; } AdminProfileDtoToAdministratorMapper(
			StaffRepository providerAdminRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository); Staff map(AdminProfileDto adminProfileDto);  }
@Test public void testMap_Given_Null_Username_And_Null_Admin_Id() { AdminProfileDto adminProfileDto = mock(AdminProfileDto.class); when(adminProfileDto.getUsername()).thenReturn(null); when(adminProfileDto.getId()).thenReturn(null); final String firstName = "Firstname"; when(adminProfileDto.getFirstName()).thenReturn(firstName); Staff administrator = sut.map(adminProfileDto); assertEquals(firstName, administrator.getFirstName()); }
@Test public void testMap_Given_Username() { final String username = "username"; AdminProfileDto adminProfileDto = mock(AdminProfileDto.class); when(adminProfileDto.getUsername()).thenReturn(username); Staff administrator = mock(Staff.class); when(providerAdminRepository.findByUsername(username)).thenReturn( administrator); final String firstName = "Firstname"; when(adminProfileDto.getFirstName()).thenReturn(firstName); Staff result = sut.map(adminProfileDto); assertEquals(administrator, result); }
@Test public void test_General_Case() { final String username = "username"; AdminProfileDto adminProfileDto = mock(AdminProfileDto.class); when(adminProfileDto.getUsername()).thenReturn(username); when(adminProfileDto.getEmail()).thenReturn("consent2share@gmail.com"); Staff administrator = mock(Staff.class); when(providerAdminRepository.findByUsername(username)).thenReturn( administrator); final String firstName = "Firstname"; when(adminProfileDto.getFirstName()).thenReturn(firstName); when(adminProfileDto.getAdministrativeGenderCode()).thenReturn("M"); Staff result = sut.map(adminProfileDto); assertEquals(administrator, result); }