Search in sources :

Example 1 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song 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");
}
Also used : Artist(org.mapstruct.ap.test.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Label(org.mapstruct.ap.test.constructor.nestedsource.source.Label) Studio(org.mapstruct.ap.test.constructor.nestedsource.source.Studio) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song in project mapstruct by mapstruct.

the class ReversingNestedSourcePropertiesConstructorTest method prepareSong.

private Song prepareSong() {
    Studio studio = new Studio("Abbey Road", "London");
    Label label = new Label("EMY", studio);
    Artist artist = new Artist("The Beatles", label);
    return new Song(artist, "A Hard Day's Night", Collections.emptyList());
}
Also used : Artist(org.mapstruct.ap.test.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) Label(org.mapstruct.ap.test.constructor.nestedsource.source.Label) ChartEntryLabel(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryLabel) Studio(org.mapstruct.ap.test.constructor.nestedsource.source.Studio)

Example 3 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song 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();
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) BaseChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry) ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song in project mapstruct by mapstruct.

the class ChartEntryToArtistImpl method chartEntryToSong.

protected Song chartEntryToSong(ChartEntry chartEntry) {
    if (chartEntry == null) {
        return null;
    }
    Artist artist = null;
    String title = null;
    List<Integer> positions = null;
    artist = chartEntryToArtist(chartEntry);
    title = chartEntry.getSongTitle();
    positions = mapPosition(chartEntry.getPosition());
    Song song = new Song(artist, title, positions);
    return song;
}
Also used : Artist(org.mapstruct.ap.test.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song)

Example 5 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song in project mapstruct by mapstruct.

the class ChartEntryToArtistImpl method chartSongArtistName.

private String chartSongArtistName(Chart chart) {
    if (chart == null) {
        return null;
    }
    Song song = chart.getSong();
    if (song == null) {
        return null;
    }
    Artist artist = song.getArtist();
    if (artist == null) {
        return null;
    }
    String name = artist.getName();
    if (name == null) {
        return null;
    }
    return name;
}
Also used : Artist(org.mapstruct.ap.test.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song)

Aggregations

Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)16 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)8 WithClasses (org.mapstruct.ap.testutil.WithClasses)8 Artist (org.mapstruct.ap.test.constructor.nestedsource.source.Artist)7 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)5 Label (org.mapstruct.ap.test.constructor.nestedsource.source.Label)5 Studio (org.mapstruct.ap.test.constructor.nestedsource.source.Studio)5 BaseChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry)3 Chart (org.mapstruct.ap.test.constructor.nestedsource.source.Chart)2 ChartEntryComposed (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryComposed)1 ChartEntryLabel (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryLabel)1 ChartEntryWithBase (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithBase)1 ChartEntryWithMapping (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithMapping)1