Search in sources :

Example 46 with WithClasses

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

the class NestedSourcePropertiesTest method shouldUseAddAsTargetAccessor.

@ProcessorTest
@WithClasses({ ArtistToChartEntryAdder.class, ChartPositions.class, AdderUsageObserver.class })
public void shouldUseAddAsTargetAccessor() {
    AdderUsageObserver.setUsed(false);
    Song song = new Song();
    song.setPositions(Arrays.asList(3, 5));
    Chart chart = new Chart();
    chart.setSong(song);
    ChartPositions positions = ArtistToChartEntryAdder.MAPPER.map(chart);
    assertThat(positions).isNotNull();
    assertThat(positions.getPositions()).containsExactly(3L, 5L);
    assertThat(AdderUsageObserver.isUsed()).isTrue();
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartPositions(org.mapstruct.ap.test.nestedsourceproperties._target.ChartPositions) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 47 with WithClasses

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

the class NestedSourcePropertiesTest method shouldGenerateImplementationForPropertyNamesOnly.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForPropertyNamesOnly() {
    generatedSource.addComparisonToFixtureFor(ArtistToChartEntry.class);
    Studio studio = new Studio();
    studio.setName("Abbey Road");
    studio.setCity("London");
    Label label = new Label();
    label.setStudio(studio);
    label.setName("EMY");
    Artist artist = new Artist();
    artist.setName("The Beatles");
    artist.setLabel(label);
    Song song = new Song();
    song.setArtist(artist);
    song.setTitle("A Hard Day's Night");
    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.nestedsourceproperties.source.Artist) Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Label(org.mapstruct.ap.test.nestedsourceproperties.source.Label) Studio(org.mapstruct.ap.test.nestedsourceproperties.source.Studio) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 48 with WithClasses

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

the class SimpleNestedPropertiesTest method testViaNull.

@ProcessorTest
@WithClasses({ SimpleMapper.class })
public void testViaNull() {
    SourceRoot sourceRoot = new SourceRoot();
    // sourceRoot.getProps() is null
    TargetObject targetObject = SimpleMapper.MAPPER.toTargetObject(sourceRoot);
    assertEquals(0L, targetObject.getPublicLongValue());
    assertEquals(0L, targetObject.getLongValue());
    assertEquals(0, targetObject.getIntValue());
    assertEquals(0.0, targetObject.getDoubleValue(), 0.01);
    assertEquals(0.0f, targetObject.getFloatValue(), 0.01f);
    assertEquals(0, targetObject.getShortValue());
    assertEquals(0, targetObject.getCharValue());
    assertEquals(0, targetObject.getByteValue());
    assertFalse(targetObject.isBooleanValue());
    assertNull(targetObject.getByteArray());
    assertNull(targetObject.getStringValue());
}
Also used : SourceRoot(org.mapstruct.ap.test.nestedproperties.simple.source.SourceRoot) TargetObject(org.mapstruct.ap.test.nestedproperties.simple._target.TargetObject) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 49 with WithClasses

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

the class ForgedStreamMappingTest method shouldForgeNewIterableMappingMethodReturnNullOnNullSource.

@ProcessorTest
@WithClasses({ StreamMapper.class, Source.class, Target.class })
public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() {
    Source source = new Source();
    source.setFooStream(null);
    source.setFooStream3(null);
    Target target = StreamMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFooStream()).isNull();
    Source source2 = StreamMapper.INSTANCE.targetToSource(target);
    assertThat(source2).isNotNull();
    assertThat(source2.getFooStream()).isNull();
    assertThat(source2.getFooStream3()).isNull();
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 50 with WithClasses

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

the class ForgedStreamMappingTest method shouldForgeNewIterableMappingMethod.

@ProcessorTest
@WithClasses({ StreamMapper.class, Source.class, Target.class })
public void shouldForgeNewIterableMappingMethod() {
    Source source = new Source();
    source.setFooStream(Collections.asSet("1", "2").stream());
    Target target = StreamMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFooStream()).contains(1L, 2L);
    Source source2 = StreamMapper.INSTANCE.targetToSource(target);
    assertThat(source2).isNotNull();
    assertThat(source2.getFooStream()).contains("1", "2");
    generatedSource.forMapper(StreamMapper.class).content().as("Mapper should not uas addAll").doesNotContain("addAll( ").as("Mapper should not use Stream.empty()").doesNotContain("Stream.empty()");
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) 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