use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesTest 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();
}
use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedReverseWithFactory.
@ProcessorTest
@WithClasses({ ArtistToChartEntryWithFactoryReverse.class, SourceDtoFactory.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");
assertThat(SourceDtoFactory.isCreateSongCalled()).isTrue();
assertThat(SourceDtoFactory.isCreateStudioCalled()).isTrue();
assertThat(SourceDtoFactory.isCreateLabelCalled()).isTrue();
assertThat(SourceDtoFactory.isCreateArtistCalled()).isTrue();
}
use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesTest method prepareSong.
private Song prepareSong() {
Studio studio = new Studio();
studio.setName("Abbey Road");
studio.setCity("London");
Label label = new Label();
label.setStudio(studio);
label.setName("EMY");
Artist artist = new Artist();
artist.setName("The Beatles");
artist.setLabel(label);
Song song = new Song();
song.setArtist(artist);
song.setTitle("A Hard Day's Night");
return song;
}
use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.
the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedComposedReverse.
@ProcessorTest
@WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class })
public void shouldGenerateNestedComposedReverse() {
Song song1 = prepareSong();
ChartEntryComposed chartEntry = ArtistToChartEntryComposedReverse.MAPPER.mapForward(song1);
assertThat(chartEntry).isNotNull();
assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
assertThat(chartEntry.getChartName()).isNull();
assertThat(chartEntry.getLabel().getName()).isEqualTo("EMY");
assertThat(chartEntry.getLabel().getCity()).isEqualTo("London");
assertThat(chartEntry.getLabel().getRecordedAt()).isEqualTo("Abbey Road");
assertThat(chartEntry.getPosition()).isEqualTo(0);
assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
// and now in reverse
Song song2 = ArtistToChartEntryComposedReverse.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()).isEqualTo("EMY");
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.source.Song 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();
}
Aggregations