use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class BigNumbersConversionTest method shouldApplyReverseBigDecimalConversions.
@ProcessorTest
@IssueKey("21")
@WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class })
public void shouldApplyReverseBigDecimalConversions() {
BigDecimalTarget target = new BigDecimalTarget();
target.setB((byte) 1);
target.setBb((byte) 2);
target.setS((short) 3);
target.setSs((short) 4);
target.setI(5);
target.setIi(6);
target.setL(7);
target.setLl(8L);
target.setF(9.0f);
target.setFf(10.0f);
target.setD(11.0d);
target.setDd(12.0d);
target.setString("13.45");
target.setBigInteger(new BigInteger("14"));
BigDecimalSource source = BigDecimalMapper.INSTANCE.targetToSource(target);
assertThat(source).isNotNull();
assertThat(source.getB()).isEqualTo(new BigDecimal("1"));
assertThat(source.getBb()).isEqualTo(new BigDecimal("2"));
assertThat(source.getS()).isEqualTo(new BigDecimal("3"));
assertThat(source.getSs()).isEqualTo(new BigDecimal("4"));
assertThat(source.getI()).isEqualTo(new BigDecimal("5"));
assertThat(source.getIi()).isEqualTo(new BigDecimal("6"));
assertThat(source.getL()).isEqualTo(new BigDecimal("7"));
assertThat(source.getLl()).isEqualTo(new BigDecimal("8"));
assertThat(source.getF()).isEqualTo(new BigDecimal("9.0"));
assertThat(source.getFf()).isEqualTo(new BigDecimal("10.0"));
assertThat(source.getD()).isEqualTo(new BigDecimal("11.0"));
assertThat(source.getDd()).isEqualTo(new BigDecimal("12.0"));
assertThat(source.getString()).isEqualTo(new BigDecimal("13.45"));
assertThat(source.getBigInteger()).isEqualTo(new BigDecimal("14"));
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class BigNumbersConversionTest method shouldApplyBigIntegerConversions.
@ProcessorTest
@IssueKey("21")
@WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class })
public void shouldApplyBigIntegerConversions() {
BigIntegerSource source = new BigIntegerSource();
source.setB(new BigInteger("1"));
source.setBb(new BigInteger("2"));
source.setS(new BigInteger("3"));
source.setSs(new BigInteger("4"));
source.setI(new BigInteger("5"));
source.setIi(new BigInteger("6"));
source.setL(new BigInteger("7"));
source.setLl(new BigInteger("8"));
source.setF(new BigInteger("9"));
source.setFf(new BigInteger("10"));
source.setD(new BigInteger("11"));
source.setDd(new BigInteger("12"));
source.setString(new BigInteger("13"));
BigIntegerTarget target = BigIntegerMapper.INSTANCE.sourceToTarget(source);
assertThat(target).isNotNull();
assertThat(target.getB()).isEqualTo((byte) 1);
assertThat(target.getBb()).isEqualTo((byte) 2);
assertThat(target.getS()).isEqualTo((short) 3);
assertThat(target.getSs()).isEqualTo((short) 4);
assertThat(target.getI()).isEqualTo(5);
assertThat(target.getIi()).isEqualTo(6);
assertThat(target.getL()).isEqualTo(7);
assertThat(target.getLl()).isEqualTo(8);
assertThat(target.getF()).isEqualTo(9.0f);
assertThat(target.getFf()).isEqualTo(10.0f);
assertThat(target.getD()).isEqualTo(11.0d);
assertThat(target.getDd()).isEqualTo(12.0d);
assertThat(target.getString()).isEqualTo("13");
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class ConstructorVisibilityTest method shouldUseSinglePublicConstructorAlways.
@ProcessorTest
@WithClasses({ SimpleWithPublicConstructorMapper.class })
public void shouldUseSinglePublicConstructorAlways() {
PersonDto source = new PersonDto();
source.setName("Bob");
source.setAge(30);
SimpleWithPublicConstructorMapper.Person target = SimpleWithPublicConstructorMapper.INSTANCE.map(source);
assertThat(target).isNotNull();
assertThat(target.getName()).isEqualTo("Bob");
assertThat(target.getAge()).isEqualTo(30);
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class ConstructorVisibilityTest method shouldUseDefaultAnnotatedConstructorAlways.
@ProcessorTest
@WithClasses({ SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.class })
public void shouldUseDefaultAnnotatedConstructorAlways() {
PersonDto source = new PersonDto();
source.setName("Bob");
source.setAge(30);
SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.Person target = SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.INSTANCE.map(source);
assertThat(target).isNotNull();
assertThat(target.getName()).isEqualTo("Bob");
assertThat(target.getAge()).isEqualTo(30);
}
use of org.mapstruct.ap.testutil.WithClasses 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();
}
Aggregations