use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class JodaConversionTest method testSourceToTargetMappingForStrings.
@ProcessorTest
@EnabledOnJre(JRE.JAVA_8)
public // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+
void testSourceToTargetMappingForStrings() {
Source src = new Source();
src.setLocalTime(new LocalTime(0, 0));
src.setLocalDate(new LocalDate(2014, 1, 1));
src.setLocalDateTime(new LocalDateTime(2014, 1, 1, 0, 0));
src.setDateTime(new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.UTC));
// with given format
Target target = SourceTargetMapper.INSTANCE.sourceToTarget(src);
assertThat(target).isNotNull();
assertThat(target.getDateTime()).isEqualTo("01.01.2014 00:00 UTC");
assertThat(target.getLocalDateTime()).isEqualTo("01.01.2014 00:00");
assertThat(target.getLocalDate()).isEqualTo("01.01.2014");
assertThat(target.getLocalTime()).isEqualTo("00:00");
// and now with default mappings
target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping(src);
assertThat(target).isNotNull();
assertThat(target.getDateTime()).isEqualTo("1. Januar 2014 00:00:00 UTC");
assertThat(target.getLocalDateTime()).isEqualTo("1. Januar 2014 00:00:00");
assertThat(target.getLocalDate()).isEqualTo("1. Januar 2014");
assertThat(target.getLocalTime()).isEqualTo("00:00:00");
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class JodaConversionTest method testStringToLocalDate.
@ProcessorTest
public void testStringToLocalDate() {
String dateTimeAsString = "01.01.2014";
Target target = new Target();
target.setLocalDate(dateTimeAsString);
LocalDate sourceDate = new LocalDate(2014, 1, 1);
Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateMapped(target);
assertThat(src).isNotNull();
assertThat(src.getLocalDate()).isEqualTo(sourceDate);
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class IgnorePropertyTest method shouldInheritIgnoreByDefaultFromBase.
@ProcessorTest
@IssueKey("1933")
public void shouldInheritIgnoreByDefaultFromBase() {
WorkBenchDto workBenchDto = new WorkBenchDto();
workBenchDto.setArticleName("MyBench");
workBenchDto.setArticleDescription("Beautiful");
workBenchDto.setCreationDate(new Date());
workBenchDto.setModificationDate(new Date());
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBench(workBenchDto);
assertThat(benchTarget).isNotNull();
assertThat(benchTarget.getArticleName()).isNull();
assertThat(benchTarget.getDescription()).isEqualTo("Beautiful");
assertThat(benchTarget.getKey()).isNull();
assertThat(benchTarget.getModificationDate()).isNull();
assertThat(benchTarget.getCreationDate()).isNull();
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class DecoratorTest method shouldApplyCustomMappers.
@IssueKey("173")
@ProcessorTest
@WithClasses({ Person2Mapper.class, Person2MapperDecorator.class, Person2.class, PersonDto2.class, Employer.class, EmployerDto.class, EmployerMapper.class, SportsClub.class, SportsClubDto.class })
public void shouldApplyCustomMappers() {
// given
Calendar birthday = Calendar.getInstance();
birthday.set(1928, Calendar.MAY, 23);
Person2 person = new Person2("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
person.setEmployer(new Employer("ACME"));
person.setSportsClub(new SportsClub("SC Duckburg"));
// when
PersonDto2 personDto = Person2Mapper.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");
assertThat(personDto.getEmployer()).isNotNull();
assertThat(personDto.getEmployer().getName()).isNotNull();
assertThat(personDto.getEmployer().getName()).isEqualTo("ACME");
assertThat(personDto.getSportsClub()).isNotNull();
assertThat(personDto.getSportsClub().getName()).isNotNull();
assertThat(personDto.getSportsClub().getName()).isEqualTo("SC Duckburg");
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class DecoratorTest method shouldInvokeDecoratorMethods.
@ProcessorTest
@WithClasses({ PersonMapper.class, PersonMapperDecorator.class })
public void shouldInvokeDecoratorMethods() {
// 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 = PersonMapper.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");
}
Aggregations