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");
}
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();
}
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"));
}
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"));
}
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);
}
Aggregations