Search in sources :

Example 76 with ProcessorTest

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

the class InnerClassesImportsTest method mapperRequiresInnerInnerClassImports.

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

Example 77 with ProcessorTest

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

the class InnerClassesImportsTest method mapperRequiresInnerEnumImports.

@ProcessorTest
@IssueKey("209")
public void mapperRequiresInnerEnumImports() {
    BeanWithInnerEnum source = new BeanWithInnerEnum();
    source.setTest("whatever");
    source.setInnerEnum(InnerEnum.A);
    BeanFacade target = BeanWithInnerEnumMapper.INSTANCE.toFacade(source);
    assertThat(target).isNotNull();
    assertThat(target.getInnerEnum()).isEqualTo("A");
    BeanWithInnerEnum sourceAgain = BeanWithInnerEnumMapper.INSTANCE.fromFacade(target);
    assertThat(sourceAgain).isNotNull();
    assertThat(sourceAgain.getInnerEnum()).isEqualTo(InnerEnum.A);
    generatedSource.addComparisonToFixtureFor(BeanWithInnerEnumMapper.class);
}
Also used : BeanWithInnerEnum(org.mapstruct.ap.test.imports.innerclasses.BeanWithInnerEnum) BeanFacade(org.mapstruct.ap.test.imports.innerclasses.BeanFacade) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 78 with ProcessorTest

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

the class InheritedMappingMethodTest method shouldMapUsingUnboundedInheretedMappingMethod.

@ProcessorTest
public void shouldMapUsingUnboundedInheretedMappingMethod() {
    // given
    CarDto bikeDto = new CarDto();
    bikeDto.setHorsepower(130);
    // when
    UnboundMappable<CarDto, Car> instance = CarMapper.INSTANCE;
    Car bike = instance.from(bikeDto);
    // then
    assertThat(bike).isNotNull();
    assertThat(bike.getHorsepower()).isEqualTo(130);
}
Also used : Car(org.mapstruct.ap.test.inheritedmappingmethod.source.Car) FastCar(org.mapstruct.ap.test.inheritedmappingmethod.source.FastCar) CarDto(org.mapstruct.ap.test.inheritedmappingmethod._target.CarDto) FastCarDto(org.mapstruct.ap.test.inheritedmappingmethod._target.FastCarDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 79 with ProcessorTest

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

the class SourceTypeContainsCollectionWithExtendsBoundTest method generatesImportsForCollectionWithExtendsBoundInSourceType.

@ProcessorTest
@IssueKey("768")
public void generatesImportsForCollectionWithExtendsBoundInSourceType() {
    Astronaut astronaut = new Astronaut();
    astronaut.setName("Bob");
    Spaceship spaceship = new Spaceship();
    spaceship.setAstronauts(Collections.singleton(astronaut));
    SpaceshipDto spaceshipDto = SpaceshipMapper.INSTANCE.spaceshipToDto(spaceship);
    assertThat(spaceshipDto).isNotNull();
    assertThat(spaceshipDto.getAstronauts()).extracting("name").containsOnly("Bob");
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(Astronaut.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(Spaceship.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(AstronautDto.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(SpaceshipDto.class);
}
Also used : Astronaut(org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Astronaut) SpaceshipDto(org.mapstruct.ap.test.imports.sourcewithextendsbound.dto.SpaceshipDto) Spaceship(org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Spaceship) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 80 with ProcessorTest

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

the class Issue1799Test method fluentJavaBeanStyleSettersShouldWork.

@ProcessorTest
public void fluentJavaBeanStyleSettersShouldWork() {
    Target target = Issue1799Mapper.INSTANCE.map(new Source(new Date(150), "Switzerland"));
    assertThat(target.getSettlementDate()).isEqualTo(new Date(150));
    assertThat(target.getGetawayLocation()).isEqualTo("Switzerland");
}
Also used : Date(java.util.Date) 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