Search in sources :

Example 66 with WithClasses

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

the class MultipleBuilderMapperTest method builderMappingMapperConfigDefined.

@WithClasses({ BuilderMapperConfig.class, BuilderConfigDefinedMapper.class })
@ProcessorTest
public void builderMappingMapperConfigDefined() {
    Process map = BuilderConfigDefinedMapper.INSTANCE.map(new Source("map"));
    Process wrongMap = BuilderConfigDefinedMapper.INSTANCE.wrongMap(new Source("wrongMap"));
    assertThat(map.getBuildMethod()).isEqualTo("create");
    assertThat(wrongMap.getBuildMethod()).isEqualTo("wrongCreate");
}
Also used : Process(org.mapstruct.ap.test.builder.multiple.build.Process) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 67 with WithClasses

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

the class Issue2318Test method shouldMap.

@ProcessorTest
@WithClasses(Issue2318Mapper.class)
public void shouldMap() {
    SourceChild source = new SourceChild();
    source.setValue("From child");
    source.setHolder(new Issue2318Mapper.SourceParent.Holder());
    source.getHolder().setParentValue1("From parent");
    source.getHolder().setParentValue2(12);
    TargetChild target = Issue2318Mapper.INSTANCE.mapChild(source);
    assertThat(target.getParentValue1()).isEqualTo("From parent");
    assertThat(target.getParentValue2()).isEqualTo(12);
    assertThat(target.getChildValue()).isEqualTo("From child");
}
Also used : TargetChild(org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.TargetChild) SourceChild(org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.SourceChild) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 68 with WithClasses

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

the class BuiltInTest method shouldApplyBuiltInOnStringToCalendar.

@ProcessorTest
@WithClasses(StringToCalendarMapper.class)
public void shouldApplyBuiltInOnStringToCalendar() throws ParseException {
    StringProperty source = new StringProperty();
    source.setProp("02.03.1999");
    source.publicProp = "02.03.2016";
    CalendarProperty target = StringToCalendarMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp()).isEqualTo(createCalendar("02.03.1999"));
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp).isEqualTo(createCalendar("02.03.2016"));
}
Also used : XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) CalendarProperty(org.mapstruct.ap.test.builtin.bean.CalendarProperty) StringProperty(org.mapstruct.ap.test.builtin.bean.StringProperty) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 69 with WithClasses

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

the class NestedSourcePropertiesConstructorTest method shouldGenerateImplementationForPropertyNamesOnly.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForPropertyNamesOnly() {
    generatedSource.addComparisonToFixtureFor(ArtistToChartEntry.class);
    Studio studio = new Studio("Abbey Road", "London");
    Label label = new Label("EMY", studio);
    Artist artist = new Artist("The Beatles", label);
    Song song = new Song(artist, "A Hard Day's Night", Collections.emptyList());
    ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map(song);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isNull();
    assertThat(chartEntry.getCity()).isEqualTo("London");
    assertThat(chartEntry.getPosition()).isEqualTo(0);
    assertThat(chartEntry.getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
}
Also used : Artist(org.mapstruct.ap.test.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Label(org.mapstruct.ap.test.constructor.nestedsource.source.Label) Studio(org.mapstruct.ap.test.constructor.nestedsource.source.Studio) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 70 with WithClasses

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

the class NestedSourcePropertiesConstructorTest method shouldPickPropertyNameOverParameterName.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldPickPropertyNameOverParameterName() {
    Chart chart = new Chart("record-sales", "Billboard", null);
    ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map(chart);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isNull();
    assertThat(chartEntry.getChartName()).isEqualTo("Billboard");
    assertThat(chartEntry.getCity()).isNull();
    assertThat(chartEntry.getPosition()).isEqualTo(0);
    assertThat(chartEntry.getRecordedAt()).isNull();
    assertThat(chartEntry.getSongTitle()).isNull();
}
Also used : ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) 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