Search in sources :

Example 1 with EmployeeDto

use of org.mapstruct.ap.test.conditional.EmployeeDto in project mapstruct by mapstruct.

the class ConditionalQualifierTest method conditionalMethodWithSourceParameter.

@ProcessorTest
@WithClasses({ ConditionalMethodWithSourceParameterMapper.class })
public void conditionalMethodWithSourceParameter() {
    ConditionalMethodWithSourceParameterMapper mapper = ConditionalMethodWithSourceParameterMapper.INSTANCE;
    EmployeeDto dto = new EmployeeDto();
    dto.setName("Tester");
    dto.setUniqueIdNumber("SSID-001");
    dto.setCountry(null);
    Employee employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("UK");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isEqualTo("SSID-001");
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("US");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isEqualTo("SSID-001");
    dto.setCountry("CH");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
}
Also used : Employee(org.mapstruct.ap.test.conditional.Employee) EmployeeDto(org.mapstruct.ap.test.conditional.EmployeeDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with EmployeeDto

use of org.mapstruct.ap.test.conditional.EmployeeDto in project mapstruct by mapstruct.

the class ConditionalQualifierTest method conditionalClassQualifiers.

@ProcessorTest
@WithClasses({ ConditionalMethodWithClassQualifiersMapper.class })
public void conditionalClassQualifiers() {
    ConditionalMethodWithClassQualifiersMapper mapper = ConditionalMethodWithClassQualifiersMapper.INSTANCE;
    EmployeeDto dto = new EmployeeDto();
    dto.setName("Tester");
    dto.setUniqueIdNumber("SSID-001");
    dto.setCountry(null);
    Employee employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("UK");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isEqualTo("SSID-001");
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("US");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isEqualTo("SSID-001");
    dto.setCountry("CH");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
}
Also used : Employee(org.mapstruct.ap.test.conditional.Employee) EmployeeDto(org.mapstruct.ap.test.conditional.EmployeeDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 3 with EmployeeDto

use of org.mapstruct.ap.test.conditional.EmployeeDto in project mapstruct by mapstruct.

the class ConditionalExpressionTest method conditionalExpressionInStaticClassMethod.

@ProcessorTest
@WithClasses({ ConditionalMethodsInUtilClassMapper.class })
public void conditionalExpressionInStaticClassMethod() {
    ConditionalMethodsInUtilClassMapper mapper = ConditionalMethodsInUtilClassMapper.INSTANCE;
    EmployeeDto dto = new EmployeeDto();
    dto.setName("Tester");
    dto.setUniqueIdNumber("SSID-001");
    dto.setCountry(null);
    Employee employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("UK");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isEqualTo("SSID-001");
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("US");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isEqualTo("SSID-001");
    dto.setCountry("CH");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
}
Also used : Employee(org.mapstruct.ap.test.conditional.Employee) BasicEmployee(org.mapstruct.ap.test.conditional.basic.BasicEmployee) EmployeeDto(org.mapstruct.ap.test.conditional.EmployeeDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

Employee (org.mapstruct.ap.test.conditional.Employee)3 EmployeeDto (org.mapstruct.ap.test.conditional.EmployeeDto)3 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)3 WithClasses (org.mapstruct.ap.testutil.WithClasses)3 BasicEmployee (org.mapstruct.ap.test.conditional.basic.BasicEmployee)1