Search in sources :

Example 1 with Target

use of org.mapstruct.ap.test.bugs._1170._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.bugs._1170._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.bugs._1170._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.bugs._1170._target.Target in project mapstruct by mapstruct.

the class Issue1269Test method shouldMapNestedPropertiesCorrectly.

@ProcessorTest
public void shouldMapNestedPropertiesCorrectly() {
    VehicleTypeInfo sourceTypeInfo = new VehicleTypeInfo("Opel", "Corsa", 3);
    List<VehicleImage> sourceImages = Arrays.asList(new VehicleImage(100, "something"), new VehicleImage(150, "somethingElse"));
    Vehicle source = new Vehicle(sourceTypeInfo, sourceImages);
    VehicleDto target = VehicleMapper.INSTANCE.map(source);
    assertThat(target.getVehicleInfo()).isNotNull();
    assertThat(target.getVehicleInfo().getDoors()).isEqualTo(3);
    assertThat(target.getVehicleInfo().getType()).isEqualTo("Opel");
    assertThat(target.getVehicleInfo().getName()).isEqualTo("Corsa");
    assertThat(target.getVehicleInfo().getImages()).hasSize(2);
    assertThat(target.getVehicleInfo().getImages().get(0)).isEqualToComparingFieldByField(sourceImages.get(0));
    assertThat(target.getVehicleInfo().getImages().get(1)).isEqualToComparingFieldByField(sourceImages.get(1));
}
Also used : Vehicle(org.mapstruct.ap.test.bugs._1269.model.Vehicle) VehicleDto(org.mapstruct.ap.test.bugs._1269.dto.VehicleDto) VehicleImage(org.mapstruct.ap.test.bugs._1269.model.VehicleImage) VehicleTypeInfo(org.mapstruct.ap.test.bugs._1269.model.VehicleTypeInfo) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with Target

use of org.mapstruct.ap.test.bugs._1170._target.Target in project mapstruct by mapstruct.

the class Issue892Test method compiles.

@ProcessorTest
public void compiles() {
    Source src = new Source();
    src.setType(42);
    Target target = Mappers.getMapper(Issue892Mapper.class).toTarget(src);
    assertThat(target.getType()).isEqualTo(42);
}
Also used : Target(org.mapstruct.ap.test.bugs._892.Issue892Mapper.Target) Source(org.mapstruct.ap.test.bugs._892.Issue892Mapper.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)14 Target (org.mapstruct.ap.test.collection.adder._target.Target)6 SingleElementSource (org.mapstruct.ap.test.collection.adder.source.SingleElementSource)6 IssueKey (org.mapstruct.ap.testutil.IssueKey)6 Source (org.mapstruct.ap.test.collection.adder.source.Source)5 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)5 ListAssert (org.assertj.core.api.ListAssert)2 Target (org.mapstruct.ap.test.bugs._1170._target.Target)2 Source (org.mapstruct.ap.test.bugs._1170.source.Source)2 WithClasses (org.mapstruct.ap.testutil.WithClasses)2 Test (org.junit.Test)1 VehicleDto (org.mapstruct.ap.test.bugs._1269.dto.VehicleDto)1 Vehicle (org.mapstruct.ap.test.bugs._1269.model.Vehicle)1 VehicleImage (org.mapstruct.ap.test.bugs._1269.model.VehicleImage)1 VehicleTypeInfo (org.mapstruct.ap.test.bugs._1269.model.VehicleTypeInfo)1 ImmutableItem (org.mapstruct.ap.test.bugs._1596.domain.ImmutableItem)1 Item (org.mapstruct.ap.test.bugs._1596.domain.Item)1 ImmutableItemDTO (org.mapstruct.ap.test.bugs._1596.dto.ImmutableItemDTO)1 ItemDTO (org.mapstruct.ap.test.bugs._1596.dto.ItemDTO)1 ImmutableItem (org.mapstruct.ap.test.bugs._1801.domain.ImmutableItem)1