Search in sources :

Example 1 with IssueKey

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());
}
Also used : Target(org.mapstruct.ap.test.collection.adder._target.Target) GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) Source(org.mapstruct.ap.test.collection.adder.source.Source) SingleElementSource(org.mapstruct.ap.test.collection.adder.source.SingleElementSource) Test(org.junit.Test) IssueKey(org.mapstruct.ap.testutil.IssueKey)

Example 2 with IssueKey

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();
}
Also used : Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 3 with IssueKey

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");
}
Also used : Calendar(java.util.Calendar) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with IssueKey

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);
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with IssueKey

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);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

IssueKey (org.mapstruct.ap.testutil.IssueKey)38 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)36 WithClasses (org.mapstruct.ap.testutil.WithClasses)14 Date (java.util.Date)6 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)6 BigInteger (java.math.BigInteger)4 Target (org.mapstruct.ap.test.collection.adder._target.Target)4 SingleElementSource (org.mapstruct.ap.test.collection.adder.source.SingleElementSource)4 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 Source (org.mapstruct.ap.test.collection.adder.source.Source)3 OriginalRelease (org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease)3 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 SimpleDateFormat (java.text.SimpleDateFormat)2 GregorianCalendar (java.util.GregorianCalendar)2 List (java.util.List)2 ListAssert (org.assertj.core.api.ListAssert)2 Test (org.junit.Test)2 Target (org.mapstruct.ap.test.bugs._1170._target.Target)2