Search in sources :

Example 1 with Chart

use of org.mapstruct.ap.test.constructor.nestedsource.source.Chart 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 Chart

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

the class NestedProductPropertiesConstructorTest method shouldMapNestedTarget.

@ProcessorTest
public void shouldMapNestedTarget() {
    ChartEntry chartEntry = new ChartEntry("US Billboard Hot Rock Songs", "Purple Rain", "Prince", "Live, First Avenue, Minneapolis", "Minneapolis", 1);
    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);
}
Also used : ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 3 with Chart

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

the class NestedProductPropertiesConstructorTest method shouldReverseNestedTarget.

@ProcessorTest
public void shouldReverseNestedTarget() {
    ChartEntry chartEntry = new ChartEntry("US Billboard Hot Rock Songs", "Purple Rain", "Prince", "Live, First Avenue, Minneapolis", "Minneapolis", 1);
    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");
}
Also used : ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 4 with Chart

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

Example 5 with Chart

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

the class ChartEntryToArtistImpl method map.

@Override
public Chart map(ChartEntry chartEntry) {
    if (chartEntry == null) {
        return null;
    }
    Song song = null;
    String name = null;
    song = chartEntryToSong(chartEntry);
    name = chartEntry.getChartName();
    String type = null;
    Chart chart = new Chart(type, name, song);
    return chart;
}
Also used : Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart)

Aggregations

Chart (org.mapstruct.ap.test.constructor.nestedsource.source.Chart)5 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)4 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)4 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)2 WithClasses (org.mapstruct.ap.testutil.WithClasses)2 Artist (org.mapstruct.ap.test.constructor.nestedsource.source.Artist)1 Label (org.mapstruct.ap.test.constructor.nestedsource.source.Label)1 Studio (org.mapstruct.ap.test.constructor.nestedsource.source.Studio)1