Search in sources :

Example 96 with WithClasses

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

the class ConditionalExpressionTest method conditionalExpressionInStaticClassMethod.

@ProcessorTest
@WithClasses({ ConditionalMethodsInUtilClassMapper.class })
public void conditionalExpressionInStaticClassMethod() {
    ConditionalMethodsInUtilClassMapper mapper = ConditionalMethodsInUtilClassMapper.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) BasicEmployee(org.mapstruct.ap.test.conditional.basic.BasicEmployee) EmployeeDto(org.mapstruct.ap.test.conditional.EmployeeDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 97 with WithClasses

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

the class JodaConversionTest method testStringToLocalDateUsingDefaultFormat.

@ProcessorTest
@WithClasses({ StringToLocalDateMapper.class, SourceWithStringDate.class, TargetWithLocalDate.class })
@IssueKey("456")
public void testStringToLocalDateUsingDefaultFormat() {
    SourceWithStringDate source = new SourceWithStringDate();
    source.setDate("19. November 2014");
    TargetWithLocalDate target = StringToLocalDateMapper.INSTANCE.sourceToTarget(source);
    assertThat(target.getDate()).isEqualTo(new LocalDate(2014, 11, 19));
}
Also used : LocalDate(org.joda.time.LocalDate) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 98 with WithClasses

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

the class DecoratorTest method shouldApplyDelegateToClassBasedMapper.

@ProcessorTest
@WithClasses({ YetAnotherPersonMapper.class, YetAnotherPersonMapperDecorator.class })
public void shouldApplyDelegateToClassBasedMapper() {
    // given
    Calendar birthday = Calendar.getInstance();
    birthday.set(1928, Calendar.MAY, 23);
    Person person = new Person2("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
    // when
    PersonDto personDto = YetAnotherPersonMapper.INSTANCE.personToPersonDto(person);
    // then
    assertThat(personDto).isNotNull();
    assertThat(personDto.getName()).isEqualTo("Gary Crant");
    assertThat(personDto.getAddress()).isNotNull();
    assertThat(personDto.getAddress().getAddressLine()).isEqualTo("42 Ocean View Drive");
}
Also used : Calendar(java.util.Calendar) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 99 with WithClasses

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

the class DecoratorTest method shouldApplyDecoratorWithDefaultConstructor.

@ProcessorTest
@WithClasses({ AnotherPersonMapper.class, AnotherPersonMapperDecorator.class })
public void shouldApplyDecoratorWithDefaultConstructor() {
    // given
    Calendar birthday = Calendar.getInstance();
    birthday.set(1928, Calendar.MAY, 23);
    Person person = new Person("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
    // when
    PersonDto personDto = AnotherPersonMapper.INSTANCE.personToPersonDto(person);
    // then
    assertThat(personDto).isNotNull();
    assertThat(personDto.getName()).isEqualTo("Gary Crant");
    assertThat(personDto.getAddress()).isNotNull();
    assertThat(personDto.getAddress().getAddressLine()).isEqualTo("42 Ocean View Drive");
}
Also used : Calendar(java.util.Calendar) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 100 with WithClasses

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

the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedWithMappingReverse.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithMappingReverse.class, ChartEntryWithMapping.class })
public void shouldGenerateNestedWithMappingReverse() {
    Song song1 = prepareSong();
    ChartEntryWithMapping chartEntry = ArtistToChartEntryWithMappingReverse.MAPPER.mapForward(song1);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistId()).isEqualTo(1);
    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 = ArtistToChartEntryWithMappingReverse.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");
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntryWithMapping(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryWithMapping) 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