Search in sources :

Example 1 with Target

use of org.mapstruct.ap.test.collection.adder._target.Target 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 Target

use of org.mapstruct.ap.test.collection.adder._target.Target 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 3 with Target

use of org.mapstruct.ap.test.collection.adder._target.Target 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 4 with Target

use of org.mapstruct.ap.test.collection.adder._target.Target in project mapstruct by mapstruct.

the class AdderTest method testShouldPreferSetterStrategyButThereIsNone.

@ProcessorTest
public void testShouldPreferSetterStrategyButThereIsNone() throws DogException {
    AdderUsageObserver.setUsed(false);
    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));
    TargetWithoutSetter target = SourceTargetMapperStrategySetterPreferred.INSTANCE.toTargetDontUseAdder(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo(2L);
    assertTrue(AdderUsageObserver.isUsed());
}
Also used : TargetWithoutSetter(org.mapstruct.ap.test.collection.adder._target.TargetWithoutSetter) 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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with Target

use of org.mapstruct.ap.test.collection.adder._target.Target in project mapstruct by mapstruct.

the class AdderTest method testAddReverse.

@ProcessorTest
public void testAddReverse() {
    AdderUsageObserver.setUsed(false);
    Target source = new Target();
    source.setPets(Arrays.asList(3L));
    Source target = SourceTargetMapper.INSTANCE.toSource(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo("cat");
}
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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)14 SingleElementSource (org.mapstruct.ap.test.collection.adder.source.SingleElementSource)9 Source (org.mapstruct.ap.test.collection.adder.source.Source)8 IssueKey (org.mapstruct.ap.testutil.IssueKey)8 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)8 Target (org.mapstruct.ap.test.collection.adder._target.Target)6 SourceTeeth (org.mapstruct.ap.test.collection.adder.source.SourceTeeth)3 ListAssert (org.assertj.core.api.ListAssert)2 Test (org.junit.Test)2 Target (org.mapstruct.ap.test.bugs._1170._target.Target)2 Source (org.mapstruct.ap.test.bugs._1170.source.Source)2 TargetDali (org.mapstruct.ap.test.collection.adder._target.TargetDali)2 Target2 (org.mapstruct.ap.test.collection.adder._target.Target2)1 TargetHuman (org.mapstruct.ap.test.collection.adder._target.TargetHuman)1 TargetOnlyGetter (org.mapstruct.ap.test.collection.adder._target.TargetOnlyGetter)1 TargetViaTargetType (org.mapstruct.ap.test.collection.adder._target.TargetViaTargetType)1 TargetWithAnimals (org.mapstruct.ap.test.collection.adder._target.TargetWithAnimals)1 TargetWithoutSetter (org.mapstruct.ap.test.collection.adder._target.TargetWithoutSetter)1 Foo (org.mapstruct.ap.test.collection.adder.source.Foo)1 Source2 (org.mapstruct.ap.test.collection.adder.source.Source2)1