use of org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry in project mapstruct by mapstruct.
the class NestedTargetPropertiesTest method shouldMapNestedTarget.
@Test
public void shouldMapNestedTarget() {
ChartEntry chartEntry = new ChartEntry();
chartEntry.setArtistName("Prince");
chartEntry.setChartName("US Billboard Hot Rock Songs");
chartEntry.setCity("Minneapolis");
chartEntry.setPosition(1);
chartEntry.setRecordedAt("Live, First Avenue, Minneapolis");
chartEntry.setSongTitle("Purple Rain");
Chart result = ChartEntryToArtist.MAPPER.map(chartEntry);
assertThat(result.getName()).isEqualTo("US Billboard Hot Rock Songs");
assertThat(result.getSong()).isNotNull();
assertThat(result.getSong().getArtist()).isNotNull();
assertThat(result.getSong().getTitle()).isEqualTo("Purple Rain");
assertThat(result.getSong().getArtist().getName()).isEqualTo("Prince");
assertThat(result.getSong().getArtist().getLabel()).isNotNull();
assertThat(result.getSong().getArtist().getLabel().getStudio()).isNotNull();
assertThat(result.getSong().getArtist().getLabel().getStudio().getName()).isEqualTo("Live, First Avenue, Minneapolis");
assertThat(result.getSong().getArtist().getLabel().getStudio().getCity()).isEqualTo("Minneapolis");
assertThat(result.getSong().getPositions()).hasSize(1);
assertThat(result.getSong().getPositions().get(0)).isEqualTo(1);
}
use of org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry in project mapstruct by mapstruct.
the class NestedTargetPropertiesTest method shouldReverseNestedTarget.
@Test
public void shouldReverseNestedTarget() {
ChartEntry chartEntry = new ChartEntry();
chartEntry.setArtistName("Prince");
chartEntry.setChartName("US Billboard Hot Rock Songs");
chartEntry.setCity("Minneapolis");
chartEntry.setPosition(1);
chartEntry.setRecordedAt("Live, First Avenue, Minneapolis");
chartEntry.setSongTitle("Purple Rain");
Chart chart = ChartEntryToArtist.MAPPER.map(chartEntry);
ChartEntry result = ChartEntryToArtist.MAPPER.map(chart);
assertThat(result).isNotNull();
assertThat(result.getArtistName()).isEqualTo("Prince");
assertThat(result.getChartName()).isEqualTo("US Billboard Hot Rock Songs");
assertThat(result.getCity()).isEqualTo("Minneapolis");
assertThat(result.getPosition()).isEqualTo(1);
assertThat(result.getRecordedAt()).isEqualTo("Live, First Avenue, Minneapolis");
assertThat(result.getSongTitle()).isEqualTo("Purple Rain");
}
use of org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry in project mapstruct by mapstruct.
the class ArtistToChartEntryImpl method map.
@Override
public ChartEntry map(Chart chart, Song song, Integer position) {
if (chart == null && song == null && position == null) {
return null;
}
String chartName = null;
if (chart != null) {
chartName = chart.getName();
}
String songTitle = null;
String artistName = null;
String recordedAt = null;
String city = null;
if (song != null) {
songTitle = song.getTitle();
artistName = songArtistName(song);
recordedAt = songArtistLabelStudioName(song);
city = songArtistLabelStudioCity(song);
}
int position1 = 0;
if (position != null) {
position1 = position;
}
ChartEntry chartEntry = new ChartEntry(chartName, songTitle, artistName, recordedAt, city, position1);
return chartEntry;
}
use of org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry 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.test.constructor.nestedsource._target.ChartEntry 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