use of org.mapstruct.ap.testutil.IssueKey in project mapstruct by mapstruct.
the class AdderTest method testAddwithExistingTarget.
@IssueKey("241")
@Test
public void testAddwithExistingTarget() throws DogException {
AdderUsageObserver.setUsed(false);
Source source = new Source();
source.setPets(Arrays.asList("mouse"));
Target target = new Target();
target.setPets(new ArrayList<Long>(Arrays.asList(1L)));
SourceTargetMapper.INSTANCE.toExistingTarget(source, target);
assertThat(target).isNotNull();
assertThat(target.getPets().size()).isEqualTo(2);
assertThat(target.getPets().get(0)).isEqualTo(1L);
assertThat(target.getPets().get(1)).isEqualTo(2L);
assertTrue(AdderUsageObserver.isUsed());
}
use of org.mapstruct.ap.testutil.IssueKey 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.IssueKey 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.IssueKey in project mapstruct by mapstruct.
the class StringConversionTest method stringShouldBeMappedToObjectByReference.
@ProcessorTest
@IssueKey("328")
public void stringShouldBeMappedToObjectByReference() {
Target target = new Target();
target.setObject(STRING_CONSTANT);
Source source = SourceTargetMapper.INSTANCE.targetToSource(target);
// no conversion, no built-in method
assertThat(source.getObject()).isSameAs(STRING_CONSTANT);
}
use of org.mapstruct.ap.testutil.IssueKey in project mapstruct by mapstruct.
the class SourceToManyTargetPropertiesTest method shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper.
@ProcessorTest
@IssueKey("94")
public void shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper() throws ParseException {
Source source = new Source();
String sourceFormat = "dd-MM-yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(sourceFormat);
Date sourceTime = dateFormat.parse("09-01-2014");
TimeAndFormat sourceTimeAndFormat = new TimeAndFormat();
sourceTimeAndFormat.setTfFormat(sourceFormat);
sourceTimeAndFormat.setTfTime(sourceTime);
source.setTimeAndFormat(sourceTimeAndFormat);
Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
assertThat(target).isNotNull();
assertThat(target.getFormat()).isEqualTo(sourceFormat);
assertThat(target.getTime()).isEqualTo(sourceTime);
}
Aggregations