Search in sources :

Example 41 with WithClasses

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

the class WildCardTest method shouldGenerateSuperBoundTargetForgedIterableMethod.

@ProcessorTest
@WithClasses({ SourceSuperBoundTargetMapper.class, Source.class, SuperBoundTarget.class, Plan.class, Idea.class })
public void shouldGenerateSuperBoundTargetForgedIterableMethod() {
    Source source = new Source();
    SuperBoundTarget target = SourceSuperBoundTargetMapper.STM.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getElements()).isNull();
    generatedSource.forMapper(SourceSuperBoundTargetMapper.class).content().as("Should not contain FQN after super").doesNotContain("? super org.mapstruct.ap.test.collection.wildcard.Idea");
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 42 with WithClasses

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

the class ConditionalQualifierTest method conditionalMethodWithSourceParameter.

@ProcessorTest
@WithClasses({ ConditionalMethodWithSourceParameterMapper.class })
public void conditionalMethodWithSourceParameter() {
    ConditionalMethodWithSourceParameterMapper mapper = ConditionalMethodWithSourceParameterMapper.INSTANCE;
    EmployeeDto dto = new EmployeeDto();
    dto.setName("Tester");
    dto.setUniqueIdNumber("SSID-001");
    dto.setCountry(null);
    Employee employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("UK");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isEqualTo("SSID-001");
    assertThat(employee.getSsid()).isNull();
    dto.setCountry("US");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isEqualTo("SSID-001");
    dto.setCountry("CH");
    employee = mapper.map(dto);
    assertThat(employee.getNin()).isNull();
    assertThat(employee.getSsid()).isNull();
}
Also used : Employee(org.mapstruct.ap.test.conditional.Employee) EmployeeDto(org.mapstruct.ap.test.conditional.EmployeeDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 43 with WithClasses

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

the class ReversingNestedSourcePropertiesTest 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.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) BaseChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 44 with WithClasses

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

the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedReverseWithFactory.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithFactoryReverse.class, SourceDtoFactory.class })
public void shouldGenerateNestedReverseWithFactory() {
    Song song1 = prepareSong();
    ChartEntry chartEntry = ArtistToChartEntryWithFactoryReverse.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 = ArtistToChartEntryWithFactoryReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNotNull();
    assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
    assertThat(song2.getArtist().getLabel()).isNotNull();
    assertThat(song2.getArtist().getLabel().getName()).isNull();
    assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
    assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
    assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
    assertThat(SourceDtoFactory.isCreateSongCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateStudioCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateLabelCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateArtistCalled()).isTrue();
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) BaseChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 45 with WithClasses

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

the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedComposedReverse.

@ProcessorTest
@WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class })
public void shouldGenerateNestedComposedReverse() {
    Song song1 = prepareSong();
    ChartEntryComposed chartEntry = ArtistToChartEntryComposedReverse.MAPPER.mapForward(song1);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isNull();
    assertThat(chartEntry.getLabel().getName()).isEqualTo("EMY");
    assertThat(chartEntry.getLabel().getCity()).isEqualTo("London");
    assertThat(chartEntry.getLabel().getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getPosition()).isEqualTo(0);
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
    // and now in reverse
    Song song2 = ArtistToChartEntryComposedReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNotNull();
    assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
    assertThat(song2.getArtist().getLabel()).isNotNull();
    assertThat(song2.getArtist().getLabel().getName()).isEqualTo("EMY");
    assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
    assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
    assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntryComposed(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryComposed) 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