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