use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry 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();
}
use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesConstructorTest method shouldGenerateNestedReverse.
@ProcessorTest
@WithClasses({ ArtistToChartEntryReverse.class })
public void shouldGenerateNestedReverse() {
Song song1 = prepareSong();
ChartEntry chartEntry = ArtistToChartEntryReverse.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 = ArtistToChartEntryReverse.MAPPER.mapReverse(chartEntry);
assertThat(song2).isNotNull();
assertThat(song2.getArtist()).isNotNull();
assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
assertThat(song2.getArtist().getLabel()).isNotNull();
assertThat(song2.getArtist().getLabel().getName()).isNull();
assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
}
use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesConstructorTest method shouldGenerateNestedReverseWithFactory.
@ProcessorTest
@WithClasses({ ArtistToChartEntryWithFactoryReverse.class })
public void shouldGenerateNestedReverseWithFactory() {
Song song1 = prepareSong();
ChartEntry chartEntry = ArtistToChartEntryWithFactoryReverse.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 = ArtistToChartEntryWithFactoryReverse.MAPPER.mapReverse(chartEntry);
assertThat(song2).isNotNull();
assertThat(song2.getArtist()).isNotNull();
assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
assertThat(song2.getArtist().getLabel()).isNotNull();
assertThat(song2.getArtist().getLabel().getName()).isNull();
assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
}
use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.
the class ArtistToChartEntryImpl method map.
@Override
public ChartEntry map(Chart name) {
if (name == null) {
return null;
}
ChartEntry chartEntry = new ChartEntry();
chartEntry.setChartName(name.getName());
return chartEntry;
}
use of org.mapstruct.ap.test.nestedsourceproperties._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;
}
ChartEntry chartEntry = new ChartEntry();
if (chart != null) {
chartEntry.setChartName(chart.getName());
}
if (song != null) {
chartEntry.setSongTitle(song.getTitle());
chartEntry.setArtistName(songArtistName(song));
chartEntry.setRecordedAt(songArtistLabelStudioName(song));
chartEntry.setCity(songArtistLabelStudioCity(song));
}
if (position != null) {
chartEntry.setPosition(position);
}
return chartEntry;
}
Aggregations