Search in sources :

Example 71 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class WildCardTest method testWildCard.

@ProcessorTest
@WithClasses(SourceWildCardExtendsMapper.class)
public void testWildCard() {
    // prepare source
    SourceWildCardExtendsMapper.Wrapper<BigInteger> wrapper = new SourceWildCardExtendsMapper.Wrapper<>(new BigInteger("5"));
    SourceWildCardExtendsMapper.Source source = new SourceWildCardExtendsMapper.Source(wrapper);
    // action
    SourceWildCardExtendsMapper.Target target = SourceWildCardExtendsMapper.INSTANCE.map(source);
    // verify target
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isEqualTo("5");
}
Also used : BigInteger(java.math.BigInteger) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 72 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class SpringCompileOptionConstructorMapperTest method shouldConvertToTarget.

@ProcessorTest
public void shouldConvertToTarget() throws Exception {
    // given
    CustomerEntity customerEntity = new CustomerEntity();
    customerEntity.setName("Samuel");
    customerEntity.setGender(Gender.MALE);
    CustomerRecordEntity customerRecordEntity = new CustomerRecordEntity();
    customerRecordEntity.setCustomer(customerEntity);
    customerRecordEntity.setRegistrationDate(createDate("31-08-1982 10:20:56"));
    // when
    CustomerRecordDto customerRecordDto = customerRecordMapper.asTarget(customerRecordEntity);
    // then
    assertThat(customerRecordDto).isNotNull();
    assertThat(customerRecordDto.getCustomer()).isNotNull();
    assertThat(customerRecordDto.getCustomer().getName()).isEqualTo("Samuel");
    assertThat(customerRecordDto.getCustomer().getGender()).isEqualTo(GenderDto.M);
    assertThat(customerRecordDto.getRegistrationDate()).isNotNull();
    assertThat(customerRecordDto.getRegistrationDate().toString()).isEqualTo("1982-08-31T10:20:56.000+02:00");
}
Also used : CustomerEntity(org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity) CustomerRecordDto(org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto) CustomerRecordEntity(org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 73 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class Jsr330ConstructorMapperTest method shouldConvertToTarget.

@ProcessorTest
public void shouldConvertToTarget() {
    // given
    CustomerEntity customerEntity = new CustomerEntity();
    customerEntity.setName("Samuel");
    customerEntity.setGender(Gender.MALE);
    // when
    CustomerDto customerDto = customerMapper.asTarget(customerEntity);
    // then
    assertThat(customerDto).isNotNull();
    assertThat(customerDto.getName()).isEqualTo("Samuel");
    assertThat(customerDto.getGender()).isEqualTo(GenderDto.M);
}
Also used : CustomerEntity(org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity) CustomerDto(org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 74 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class Jsr330DefaultCompileOptionFieldMapperTest method shouldConvertToTarget.

@ProcessorTest
public void shouldConvertToTarget() {
    // given
    CustomerEntity customerEntity = new CustomerEntity();
    customerEntity.setName("Samuel");
    customerEntity.setGender(Gender.MALE);
    // when
    CustomerDto customerDto = customerMapper.asTarget(customerEntity);
    // then
    assertThat(customerDto).isNotNull();
    assertThat(customerDto.getName()).isEqualTo("Samuel");
    assertThat(customerDto.getGender()).isEqualTo(GenderDto.M);
}
Also used : CustomerEntity(org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity) CustomerDto(org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 75 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class InnerClassesImportsTest method mapperRequiresInnerClassImports.

@ProcessorTest
@IssueKey("412")
public void mapperRequiresInnerClassImports() {
    SourceWithInnerClass source = new SourceWithInnerClass();
    source.setInnerClassMember(new SourceInnerClass(412));
    TargetWithInnerClass target = InnerClassMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getInnerClassMember().getValue()).isEqualTo(412);
    generatedSource.addComparisonToFixtureFor(InnerClassMapper.class);
}
Also used : SourceWithInnerClass(org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass) SourceInnerClass(org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass.SourceInnerClass) TargetWithInnerClass(org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10