Search in sources :

Example 36 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses 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 37 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses 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 38 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class BigNumbersConversionTest method shouldApplyReverseBigIntegerConversions.

@ProcessorTest
@IssueKey("21")
@WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class })
public void shouldApplyReverseBigIntegerConversions() {
    BigIntegerTarget target = new BigIntegerTarget();
    target.setB((byte) 1);
    target.setBb((byte) 2);
    target.setS((short) 3);
    target.setSs((short) 4);
    target.setI(5);
    target.setIi(6);
    target.setL(7);
    target.setLl(8L);
    target.setF(9.0f);
    target.setFf(10.0f);
    target.setD(11.0d);
    target.setDd(12.0d);
    target.setString("13");
    BigIntegerSource source = BigIntegerMapper.INSTANCE.targetToSource(target);
    assertThat(source).isNotNull();
    assertThat(source.getB()).isEqualTo(new BigInteger("1"));
    assertThat(source.getBb()).isEqualTo(new BigInteger("2"));
    assertThat(source.getS()).isEqualTo(new BigInteger("3"));
    assertThat(source.getSs()).isEqualTo(new BigInteger("4"));
    assertThat(source.getI()).isEqualTo(new BigInteger("5"));
    assertThat(source.getIi()).isEqualTo(new BigInteger("6"));
    assertThat(source.getL()).isEqualTo(new BigInteger("7"));
    assertThat(source.getLl()).isEqualTo(new BigInteger("8"));
    assertThat(source.getF()).isEqualTo(new BigInteger("9"));
    assertThat(source.getFf()).isEqualTo(new BigInteger("10"));
    assertThat(source.getD()).isEqualTo(new BigInteger("11"));
    assertThat(source.getDd()).isEqualTo(new BigInteger("12"));
    assertThat(source.getString()).isEqualTo(new BigInteger("13"));
}
Also used : BigInteger(java.math.BigInteger) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 39 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class BigNumbersConversionTest method shouldApplyBigDecimalConversions.

@ProcessorTest
@IssueKey("21")
@WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class })
public void shouldApplyBigDecimalConversions() {
    BigDecimalSource source = new BigDecimalSource();
    source.setB(new BigDecimal("1.45"));
    source.setBb(new BigDecimal("2.45"));
    source.setS(new BigDecimal("3.45"));
    source.setSs(new BigDecimal("4.45"));
    source.setI(new BigDecimal("5.45"));
    source.setIi(new BigDecimal("6.45"));
    source.setL(new BigDecimal("7.45"));
    source.setLl(new BigDecimal("8.45"));
    source.setF(new BigDecimal("9.45"));
    source.setFf(new BigDecimal("10.45"));
    source.setD(new BigDecimal("11.45"));
    source.setDd(new BigDecimal("12.45"));
    source.setString(new BigDecimal("13.45"));
    source.setBigInteger(new BigDecimal("14.45"));
    BigDecimalTarget target = BigDecimalMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getB()).isEqualTo((byte) 1);
    assertThat(target.getBb()).isEqualTo((byte) 2);
    assertThat(target.getS()).isEqualTo((short) 3);
    assertThat(target.getSs()).isEqualTo((short) 4);
    assertThat(target.getI()).isEqualTo(5);
    assertThat(target.getIi()).isEqualTo(6);
    assertThat(target.getL()).isEqualTo(7);
    assertThat(target.getLl()).isEqualTo(8);
    assertThat(target.getF()).isEqualTo(9.45f);
    assertThat(target.getFf()).isEqualTo(10.45f);
    assertThat(target.getD()).isEqualTo(11.45d);
    assertThat(target.getDd()).isEqualTo(12.45d);
    assertThat(target.getString()).isEqualTo("13.45");
    assertThat(target.getBigInteger()).isEqualTo(new BigInteger("14"));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 40 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class ConstructorVisibilityTest method shouldUsePublicParameterConstructorIfPresent.

@ProcessorTest
@WithClasses({ SimpleWithPublicParameterlessConstructorMapper.class })
public void shouldUsePublicParameterConstructorIfPresent() {
    PersonDto source = new PersonDto();
    source.setName("Bob");
    source.setAge(30);
    SimpleWithPublicParameterlessConstructorMapper.Person target = SimpleWithPublicParameterlessConstructorMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getName()).isEqualTo("From Constructor");
    assertThat(target.getAge()).isEqualTo(-1);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

WithClasses (org.mapstruct.ap.testutil.WithClasses)119 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)118 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 IssueKey (org.mapstruct.ap.testutil.IssueKey)17 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)11 DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 CalendarProperty (org.mapstruct.ap.test.builtin.bean.CalendarProperty)8 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)8 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)7 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)6 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)6 Date (java.util.Date)5 LocalDateTime (org.joda.time.LocalDateTime)5 StringProperty (org.mapstruct.ap.test.builtin.bean.StringProperty)5 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)5 VehicleCollection (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection)5