Search in sources :

Example 76 with WithClasses

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"));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 77 with WithClasses

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");
}
Also used : BigInteger(java.math.BigInteger) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 78 with WithClasses

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);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 79 with WithClasses

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);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 80 with WithClasses

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();
}
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)

Aggregations

WithClasses (org.mapstruct.ap.testutil.WithClasses)119 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)118 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 IssueKey (org.mapstruct.ap.testutil.IssueKey)17 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)11 DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 CalendarProperty (org.mapstruct.ap.test.builtin.bean.CalendarProperty)8 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)8 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)7 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)6 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)6 Date (java.util.Date)5 LocalDateTime (org.joda.time.LocalDateTime)5 StringProperty (org.mapstruct.ap.test.builtin.bean.StringProperty)5 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)5 VehicleCollection (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection)5