Search in sources :

Example 26 with ProcessorTest

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

the class ArrayMappingTest method shouldCopyArraysInBean.

@ProcessorTest
public void shouldCopyArraysInBean() {
    Scientist source = new Scientist("Bob");
    source.setPublications(new String[] { "the Lancet", "Nature" });
    source.publicPublications = new String[] { "public the Lancet", "public Nature" };
    ScientistDto dto = ScienceMapper.INSTANCE.scientistToDto(source);
    assertThat(dto).isNotNull();
    assertThat(dto).isNotEqualTo(source);
    assertThat(dto.getPublications()).containsOnly("the Lancet", "Nature");
    assertThat(dto.publicPublications).containsOnly("public the Lancet", "public Nature");
}
Also used : ScientistDto(org.mapstruct.ap.test.array._target.ScientistDto) Scientist(org.mapstruct.ap.test.array.source.Scientist) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 27 with ProcessorTest

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

the class AdderTest method testWildcardAdderTargetToSource.

@IssueKey("1170")
@ProcessorTest
public void testWildcardAdderTargetToSource() {
    Target target = new Target();
    target.addWithoutWildcard(2L);
    target.addWildcardInTarget(2L);
    target.getWildcardInSources().add(2L);
    target.addWildcardInBoth(2L);
    target.setWildcardAdderToSetters(Arrays.asList(2L));
    Source source = AdderSourceTargetMapper.INSTANCE.toSource(target);
    assertThat(source).isNotNull();
    assertThat(source.getWithoutWildcards()).containsExactly("mouse");
    ((ListAssert<String>) assertThat(source.getWildcardInSources())).containsExactly("mouse");
    assertThat(source.getWildcardInTargets()).containsExactly("mouse");
    ((ListAssert<String>) assertThat(source.getWildcardInBoths())).containsExactly("mouse");
    ((ListAssert<String>) assertThat(source.getWildcardAdderToSetters())).containsExactly("mouse");
}
Also used : Target(org.mapstruct.ap.test.bugs._1170._target.Target) ListAssert(org.assertj.core.api.ListAssert) Source(org.mapstruct.ap.test.bugs._1170.source.Source) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 28 with ProcessorTest

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

the class AdderTest method testWildcardAdder.

@IssueKey("1170")
@ProcessorTest
public void testWildcardAdder() {
    Source source = new Source();
    source.addWithoutWildcard("mouse");
    source.addWildcardInTarget("mouse");
    source.addWildcardInSource("mouse");
    source.addWildcardInBoth("mouse");
    source.addWildcardAdderToSetter("mouse");
    Target target = AdderSourceTargetMapper.INSTANCE.toTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getWithoutWildcards()).containsExactly(2L);
    assertThat(target.getWildcardInSources()).containsExactly(2L);
    ((ListAssert<Long>) assertThat(target.getWildcardInTargets())).containsExactly(2L);
    ((ListAssert<Long>) assertThat(target.getWildcardInBoths())).containsExactly(2L);
    assertThat(target.getWildcardAdderToSetters()).containsExactly(2L);
}
Also used : Target(org.mapstruct.ap.test.bugs._1170._target.Target) ListAssert(org.assertj.core.api.ListAssert) Source(org.mapstruct.ap.test.bugs._1170.source.Source) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 29 with ProcessorTest

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

the class Issue1482Test method testReverse.

@ProcessorTest
@WithClasses(TargetSourceMapper.class)
public void testReverse() {
    Target target = new Target();
    target.setBigDecimal(new BigDecimal(5));
    target.setTest("VAL1");
    Source2 source2 = TargetSourceMapper.INSTANCE.map(target);
    assertThat(source2).isNotNull();
    assertThat(source2.getTest()).isEqualTo(SourceEnum.VAL1);
    assertThat(source2.getWrapper().getValue()).isEqualTo(new BigDecimal(5));
}
Also used : BigDecimal(java.math.BigDecimal) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 30 with ProcessorTest

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

the class Issue1561Test method shouldCorrectlyUseAdder.

@ProcessorTest
public void shouldCorrectlyUseAdder() {
    Source source = new Source();
    source.addProperty("first");
    source.addProperty("second");
    Target target = Issue1561Mapper.INSTANCE.map(source);
    assertThat(target.getNestedTarget().getProperties()).containsExactly("first", "second");
    Source mapped = Issue1561Mapper.INSTANCE.map(target);
    assertThat(mapped.getProperties()).containsExactly("first", "second");
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10