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);
}
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();
}
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);
}
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");
}
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();
}
Aggregations