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