use of org.mapstruct.ap.test.nestedsourceproperties.source.Chart 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.nestedsourceproperties.source.Chart 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.nestedsourceproperties.source.Chart in project mapstruct by mapstruct.
the class ChartEntryToArtistImpl method map.
@Override
public Chart map(ChartEntry chartEntry1, ChartEntry chartEntry2) {
if (chartEntry1 == null && chartEntry2 == null) {
return null;
}
Chart chart = new Chart();
if (chartEntry1 != null) {
if (chart.getSong() == null) {
chart.setSong(new Song());
}
chartEntryToSong1(chartEntry1, chart.getSong());
}
if (chartEntry2 != null) {
if (chart.getSong() == null) {
chart.setSong(new Song());
}
chartEntryToSong2(chartEntry2, chart.getSong());
chart.setName(chartEntry2.getChartName());
}
return chart;
}
use of org.mapstruct.ap.test.nestedsourceproperties.source.Chart in project mapstruct by mapstruct.
the class NestedSourcePropertiesTest method shouldUseAddAsTargetAccessor.
@ProcessorTest
@WithClasses({ ArtistToChartEntryAdder.class, ChartPositions.class, AdderUsageObserver.class })
public void shouldUseAddAsTargetAccessor() {
AdderUsageObserver.setUsed(false);
Song song = new Song();
song.setPositions(Arrays.asList(3, 5));
Chart chart = new Chart();
chart.setSong(song);
ChartPositions positions = ArtistToChartEntryAdder.MAPPER.map(chart);
assertThat(positions).isNotNull();
assertThat(positions.getPositions()).containsExactly(3L, 5L);
assertThat(AdderUsageObserver.isUsed()).isTrue();
}
use of org.mapstruct.ap.test.nestedsourceproperties.source.Chart in project mapstruct by mapstruct.
the class NestedProductPropertiesTest method shouldMapNestedTarget.
@ProcessorTest
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);
}
Aggregations