Search in sources :

Example 1 with EmployeeEntity

use of org.mapstruct.ap.test.updatemethods.EmployeeEntity in project mapstruct by mapstruct.

the class DepartmentMapperImpl method toEmployeeEntity.

@Override
public EmployeeEntity toEmployeeEntity(EmployeeDto dto) {
    if (dto == null) {
        return null;
    }
    EmployeeEntity employeeEntity = new EmployeeEntity();
    employeeEntity.setName(dto.getName());
    return employeeEntity;
}
Also used : EmployeeEntity(org.mapstruct.ap.test.updatemethods.EmployeeEntity)

Example 2 with EmployeeEntity

use of org.mapstruct.ap.test.updatemethods.EmployeeEntity in project mapstruct by mapstruct.

the class ExternalSelectionTest method shouldSelectGeneratedExternalMapperForIterablesAndMaps.

@ProcessorTest
@IssueKey("487")
public void shouldSelectGeneratedExternalMapperForIterablesAndMaps() {
    DepartmentDto departmentDto = new DepartmentDto();
    EmployeeDto employeeDto = new EmployeeDto();
    employeeDto.setName("Sarah");
    SecretaryDto secretaryDto = new SecretaryDto();
    secretaryDto.setName("Jim");
    departmentDto.setEmployees(Arrays.asList(employeeDto));
    Map<SecretaryDto, EmployeeDto> secretaryToEmployee = new HashMap<>();
    secretaryToEmployee.put(secretaryDto, employeeDto);
    departmentDto.setSecretaryToEmployee(secretaryToEmployee);
    DepartmentEntity departmentEntity = new DepartmentEntity(5);
    DepartmentMapper.INSTANCE.toDepartmentEntity(departmentDto, departmentEntity);
    assertThat(departmentEntity).isNotNull();
    assertThat(departmentEntity.getEmployees()).isNotEmpty();
    assertThat(departmentEntity.getEmployees().get(0).getName()).isEqualTo("Sarah");
    assertThat(departmentEntity.getSecretaryToEmployee()).isNotEmpty();
    Map.Entry<SecretaryEntity, EmployeeEntity> firstEntry = departmentEntity.getSecretaryToEmployee().entrySet().iterator().next();
    assertThat(firstEntry.getKey().getName()).isEqualTo("Jim");
    assertThat(firstEntry.getValue().getName()).isEqualTo("Sarah");
}
Also used : DepartmentDto(org.mapstruct.ap.test.updatemethods.DepartmentDto) DepartmentEntity(org.mapstruct.ap.test.updatemethods.DepartmentEntity) ConstructableDepartmentEntity(org.mapstruct.ap.test.updatemethods.ConstructableDepartmentEntity) EmployeeDto(org.mapstruct.ap.test.updatemethods.EmployeeDto) HashMap(java.util.HashMap) EmployeeEntity(org.mapstruct.ap.test.updatemethods.EmployeeEntity) SecretaryDto(org.mapstruct.ap.test.updatemethods.SecretaryDto) HashMap(java.util.HashMap) Map(java.util.Map) SecretaryEntity(org.mapstruct.ap.test.updatemethods.SecretaryEntity) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

EmployeeEntity (org.mapstruct.ap.test.updatemethods.EmployeeEntity)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConstructableDepartmentEntity (org.mapstruct.ap.test.updatemethods.ConstructableDepartmentEntity)1 DepartmentDto (org.mapstruct.ap.test.updatemethods.DepartmentDto)1 DepartmentEntity (org.mapstruct.ap.test.updatemethods.DepartmentEntity)1 EmployeeDto (org.mapstruct.ap.test.updatemethods.EmployeeDto)1 SecretaryDto (org.mapstruct.ap.test.updatemethods.SecretaryDto)1 SecretaryEntity (org.mapstruct.ap.test.updatemethods.SecretaryEntity)1 IssueKey (org.mapstruct.ap.testutil.IssueKey)1 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)1