Search in sources :

Example 6 with Song

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

the class ChartEntryToArtistImpl method chartSongTitle.

private String chartSongTitle(Chart chart) {
    if (chart == null) {
        return null;
    }
    Song song = chart.getSong();
    if (song == null) {
        return null;
    }
    String title = song.getTitle();
    if (title == null) {
        return null;
    }
    return title;
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song)

Example 7 with Song

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

the class NestedSourcePropertiesConstructorTest method shouldGenerateImplementationForPropertyNamesOnly.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForPropertyNamesOnly() {
    generatedSource.addComparisonToFixtureFor(ArtistToChartEntry.class);
    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());
    ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map(song);
    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");
}
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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 8 with Song

use of org.mapstruct.ap.test.constructor.nestedsource.source.Song 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");
}
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 9 with Song

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

the class ReversingNestedSourcePropertiesConstructorTest method shouldGenerateNestedWithMappingReverse.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithMappingReverse.class, ChartEntryWithMapping.class })
public void shouldGenerateNestedWithMappingReverse() {
    Song song1 = prepareSong();
    ChartEntryWithMapping chartEntry = ArtistToChartEntryWithMappingReverse.MAPPER.mapForward(song1);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistId()).isEqualTo(1);
    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 = ArtistToChartEntryWithMappingReverse.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");
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) ChartEntryWithMapping(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithMapping) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 10 with Song

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

the class ReversingNestedSourcePropertiesConstructorTest method shouldGenerateNestedWithConfigReverse.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithConfigReverse.class, ArtistToChartEntryConfig.class, BaseChartEntry.class, ChartEntryWithBase.class })
public void shouldGenerateNestedWithConfigReverse() {
    Song song1 = prepareSong();
    ChartEntryWithBase chartEntry = ArtistToChartEntryWithConfigReverse.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 = ArtistToChartEntryWithConfigReverse.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");
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) ChartEntryWithBase(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithBase) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

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