Search in sources :

Example 31 with IssueKey

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

the class AdderTest method useIterationNameFromSource.

@IssueKey("1478")
@ProcessorTest
public void useIterationNameFromSource() {
    generatedSource.addComparisonToFixtureFor(SourceTargetMapperWithDifferentProperties.class);
    SourceWithPets source = new SourceWithPets();
    source.setPets(Arrays.asList("dog", "cat"));
    TargetWithAnimals target = SourceTargetMapperWithDifferentProperties.INSTANCE.map(source);
    assertThat(target.getAnimals()).containsExactly("dog", "cat");
}
Also used : SourceWithPets(org.mapstruct.ap.test.collection.adder.source.SourceWithPets) TargetWithAnimals(org.mapstruct.ap.test.collection.adder._target.TargetWithAnimals) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 32 with IssueKey

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

the class AdderTest method testMissingImport.

@IssueKey("310")
@ProcessorTest
public void testMissingImport() {
    generatedSource.addComparisonToFixtureFor(Source2Target2Mapper.class);
    Source2 source = new Source2();
    source.setAttributes(Arrays.asList(new Foo()));
    Target2 target = Source2Target2Mapper.INSTANCE.toTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getAttributes().size()).isEqualTo(1);
}
Also used : Source2(org.mapstruct.ap.test.collection.adder.source.Source2) Foo(org.mapstruct.ap.test.collection.adder.source.Foo) Target2(org.mapstruct.ap.test.collection.adder._target.Target2) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 33 with IssueKey

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

the class AdderTest method testAddWithExistingTarget.

@IssueKey("241")
@ProcessorTest
public void testAddWithExistingTarget() {
    AdderUsageObserver.setUsed(false);
    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));
    Target target = new Target();
    target.setPets(new ArrayList<>(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) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 34 with IssueKey

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

the class DefaultCollectionImplementationTest method shouldUseDefaultImplementationForListWithoutSetter.

@ProcessorTest
@IssueKey("92")
public void shouldUseDefaultImplementationForListWithoutSetter() {
    Source source = new Source();
    source.setFooList(createSourceFooList());
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFooListNoSetter()).containsExactly(new TargetFoo("Bob"), new TargetFoo("Alice"));
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 35 with IssueKey

use of org.mapstruct.ap.testutil.IssueKey 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));
}
Also used : LocalDate(org.joda.time.LocalDate) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

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