Search in sources :

Example 61 with ProcessorTest

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

the class JavaDefaultExpressionTest method testJavaDefaultExpressionWithNoValues.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public void testJavaDefaultExpressionWithNoValues() {
    Source source = new Source();
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getSourceId()).isEqualTo("test");
    assertThat(target.getSourceDate()).isEqualTo(new Date(30L));
}
Also used : Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 62 with ProcessorTest

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

the class JavaExpressionTest method testJavaExpressionInsertionWithExistingTarget.

@ProcessorTest
@WithClasses({ Source.class, Target.class, TimeAndFormat.class, SourceTargetMapper.class })
public void testJavaExpressionInsertionWithExistingTarget() throws ParseException {
    Source source = new Source();
    String format = "dd-MM-yyyy,hh:mm:ss";
    Date time = getTime(format, "09-01-2014,01:35:03");
    source.setFormat(format);
    source.setTime(time);
    Target target = new Target();
    Target target2 = SourceTargetMapper.INSTANCE.sourceToTargetWithMappingTarget(source, target);
    assertThat(target).isNotNull();
    assertThat(target.getTimeAndFormat().getTime()).isEqualTo(time);
    assertThat(target.getTimeAndFormat().getFormat()).isEqualTo(format);
    assertThat(target.getAnotherProp()).isNull();
    assertThat(target).isEqualTo(target2);
}
Also used : Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 63 with ProcessorTest

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

the class SeveralReferencedMappersWithSameSimpleNameTest method severalMappersWithSameSimpleNameCanBeReferenced.

@ProcessorTest
public void severalMappersWithSameSimpleNameCanBeReferenced() {
    Source source = new Source();
    source.setFoo(123);
    source.setBar(456L);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFoo()).isEqualTo("246");
    assertThat(target.getBar()).isEqualTo("912");
}
Also used : Target(org.mapstruct.ap.test.references.samename.model.Target) Source(org.mapstruct.ap.test.references.samename.model.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 64 with ProcessorTest

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

the class SeveralReferencedMappersWithSameSimpleNameTest method mapperInSamePackageAndAnotherMapperWithSameNameInAnotherPackageCanBeReferenced.

@ProcessorTest
public void mapperInSamePackageAndAnotherMapperWithSameNameInAnotherPackageCanBeReferenced() {
    Source source = new Source();
    source.setFoo(123);
    source.setBar(456L);
    Target target = AnotherSourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFoo()).isEqualTo("246");
    assertThat(target.getBar()).isEqualTo("912");
}
Also used : Target(org.mapstruct.ap.test.references.samename.model.Target) Source(org.mapstruct.ap.test.references.samename.model.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 65 with ProcessorTest

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

the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessNullArg.

@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessNullArg() {
    // given
    Car car = new Car("Morris", 2);
    // when
    CarDto carDto1 = CarMapper.INSTANCE.carToCarDto(car);
    // then
    assertThat(carDto1).isNotNull();
    assertThat(carDto1.getMake()).isEqualTo(car.getMake());
    assertThat(carDto1.getSeatCount()).isEqualTo(car.getNumberOfSeats());
    assertThat(carDto1.getModel()).isEqualTo("ModelT");
    assertThat(carDto1.getCatalogId()).isNotEmpty();
    // when
    CarDto carDto2 = CarMapper.INSTANCE.carToCarDto(null);
    // then
    assertThat(carDto2).isNotNull();
    assertThat(carDto2.getMake()).isNull();
    assertThat(carDto2.getSeatCount()).isEqualTo(0);
    assertThat(carDto2.getModel()).isEqualTo("ModelT");
    assertThat(carDto2.getCatalogId()).isNotEmpty();
}
Also used : Car(org.mapstruct.ap.test.nullvaluemapping.source.Car) DriverAndCarDto(org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto) CarDto(org.mapstruct.ap.test.nullvaluemapping._target.CarDto) 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