Search in sources :

Example 91 with ProcessorTest

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

the class LocalDateTimeToXMLGregorianCalendarConversionTest method shouldMapXmlGregorianCalendarToLocalDateTimeCorrectly.

@ProcessorTest
public void shouldMapXmlGregorianCalendarToLocalDateTimeCorrectly() throws DatatypeConfigurationException {
    XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1994, Calendar.MARCH, 5, 11, 30, 50, 500, DatatypeConstants.FIELD_UNDEFINED);
    Source source = new Source();
    source.setXmlGregorianCalendar(xmlGregorianCalendar);
    Target target = SourceTargetMapper.INSTANCE.toTarget(source);
    LocalDateTime expectedLocalDateTime = LocalDateTime.of(1994, Calendar.MARCH, 5, 11, 30, 50, 500000000);
    assertThat(target).isNotNull();
    assertThat(target.getLocalDateTime()).isEqualTo(expectedLocalDateTime);
}
Also used : LocalDateTime(java.time.LocalDateTime) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Target(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Target) Source(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 92 with ProcessorTest

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

the class LocalDateTimeToXMLGregorianCalendarConversionTest method shouldNullCheckOnConversionToTarget.

@ProcessorTest
public void shouldNullCheckOnConversionToTarget() {
    Target target = SourceTargetMapper.INSTANCE.toTarget(new Source());
    assertThat(target).isNotNull();
    assertThat(target.getLocalDateTime()).isNull();
}
Also used : Target(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Target) Source(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 93 with ProcessorTest

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

the class LocalDateTimeToXMLGregorianCalendarConversionTest method shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithNanoseconds.

@ProcessorTest
public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithNanoseconds() throws DatatypeConfigurationException {
    LocalDateTime localDateTime = LocalDateTime.of(1994, Calendar.MARCH, 5, 11, 30, 50, 9000000);
    Target target = new Target();
    target.setLocalDateTime(localDateTime);
    Source source = SourceTargetMapper.INSTANCE.toSource(target);
    XMLGregorianCalendar expectedCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1994, Calendar.MARCH, 5, 11, 30, 50, 9, DatatypeConstants.FIELD_UNDEFINED);
    assertThat(source).isNotNull();
    assertThat(source.getXmlGregorianCalendar()).isEqualTo(expectedCalendar);
}
Also used : LocalDateTime(java.time.LocalDateTime) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Target(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Target) Source(org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 94 with ProcessorTest

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

the class NestedSourcePropertiesConstructorTest method shouldGenerateImplementationForMultipleParam.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForMultipleParam() {
    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());
    Chart chart = new Chart("record-sales", "Billboard", null);
    ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map(chart, song, 1);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isEqualTo("Billboard");
    assertThat(chartEntry.getCity()).isEqualTo("London");
    assertThat(chartEntry.getPosition()).isEqualTo(1);
    assertThat(chartEntry.getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
    chartEntry = ArtistToChartEntry.MAPPER.map(null, song, 10);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isNull();
    assertThat(chartEntry.getCity()).isEqualTo("London");
    assertThat(chartEntry.getPosition()).isEqualTo(10);
    assertThat(chartEntry.getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
    chartEntry = ArtistToChartEntry.MAPPER.map(chart, null, 5);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isNull();
    assertThat(chartEntry.getChartName()).isEqualTo("Billboard");
    assertThat(chartEntry.getCity()).isNull();
    assertThat(chartEntry.getPosition()).isEqualTo(5);
    assertThat(chartEntry.getRecordedAt()).isNull();
    assertThat(chartEntry.getSongTitle()).isNull();
    chartEntry = ArtistToChartEntry.MAPPER.map(chart, song, null);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isEqualTo("Billboard");
    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) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 95 with ProcessorTest

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

the class ReversingNestedSourcePropertiesConstructorTest method shouldIgnoreEverytingBelowArtist.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithIgnoresReverse.class })
public void shouldIgnoreEverytingBelowArtist() {
    Song song1 = prepareSong();
    ChartEntry chartEntry = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapForward(song1);
    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");
    // and now in reverse
    Song song2 = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNull();
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) BaseChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry) ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

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