Search in sources :

Example 6 with ScientistDto

use of org.mapstruct.ap.test.array._target.ScientistDto in project mapstruct by mapstruct.

the class ArrayMappingTest method shouldMapArrayToArrayExistingLargerSizedTarget.

@ProcessorTest
public void shouldMapArrayToArrayExistingLargerSizedTarget() {
    ScientistDto[] existingTarget = new ScientistDto[] { new ScientistDto("Jim"), new ScientistDto("Bart"), new ScientistDto("John") };
    ScientistDto[] target = ScienceMapper.INSTANCE.scientistsToDtos(new Scientist[] { new Scientist("Bob"), new Scientist("Larry") }, existingTarget);
    assertThat(target).isNotNull();
    assertThat(target).isEqualTo(existingTarget);
    assertThat(target).extracting("name").containsOnly("Bob", "Larry", "John");
}
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 7 with ScientistDto

use of org.mapstruct.ap.test.array._target.ScientistDto in project mapstruct by mapstruct.

the class ArrayMappingTest method shouldMapArrayToArray.

@ProcessorTest
public void shouldMapArrayToArray() {
    ScientistDto[] dtos = ScienceMapper.INSTANCE.scientistsToDtos(new Scientist[] { new Scientist("Bob"), new Scientist("Larry") });
    assertThat(dtos).isNotNull();
    assertThat(dtos).extracting("name").containsOnly("Bob", "Larry");
}
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 8 with ScientistDto

use of org.mapstruct.ap.test.array._target.ScientistDto in project mapstruct by mapstruct.

the class ScienceMapperImpl method scientistsToDtos.

@Override
public ScientistDto[] scientistsToDtos(Scientist[] scientists) {
    if (scientists == null) {
        return null;
    }
    ScientistDto[] scientistDtoTmp = new ScientistDto[scientists.length];
    int i = 0;
    for (Scientist scientist : scientists) {
        scientistDtoTmp[i] = scientistToDto(scientist);
        i++;
    }
    return scientistDtoTmp;
}
Also used : ScientistDto(org.mapstruct.ap.test.array._target.ScientistDto) Scientist(org.mapstruct.ap.test.array.source.Scientist)

Example 9 with ScientistDto

use of org.mapstruct.ap.test.array._target.ScientistDto in project mapstruct by mapstruct.

the class ScienceMapperImpl method scientistsToDtos.

@Override
public ScientistDto[] scientistsToDtos(List<Scientist> scientists) {
    if (scientists == null) {
        return null;
    }
    ScientistDto[] scientistDtoTmp = new ScientistDto[scientists.size()];
    int i = 0;
    for (Scientist scientist : scientists) {
        scientistDtoTmp[i] = scientistToDto(scientist);
        i++;
    }
    return scientistDtoTmp;
}
Also used : ScientistDto(org.mapstruct.ap.test.array._target.ScientistDto) Scientist(org.mapstruct.ap.test.array.source.Scientist)

Example 10 with ScientistDto

use of org.mapstruct.ap.test.array._target.ScientistDto in project mapstruct by mapstruct.

the class ScienceMapperImpl method scientistToDto.

@Override
public ScientistDto scientistToDto(Scientist scientist) {
    if (scientist == null) {
        return null;
    }
    ScientistDto scientistDto = new ScientistDto();
    scientistDto.setName(scientist.getName());
    String[] publications = scientist.getPublications();
    if (publications != null) {
        scientistDto.setPublications(Arrays.copyOf(publications, publications.length));
    }
    scientistDto.setPublicationYears(stringArrayTointArray(scientist.getPublicationYears()));
    String[] publicPublications = scientist.publicPublications;
    if (publicPublications != null) {
        scientistDto.publicPublications = Arrays.copyOf(publicPublications, publicPublications.length);
    }
    scientistDto.publicPublicationYears = stringArrayTointArray(scientist.publicPublicationYears);
    return scientistDto;
}
Also used : ScientistDto(org.mapstruct.ap.test.array._target.ScientistDto)

Aggregations

ScientistDto (org.mapstruct.ap.test.array._target.ScientistDto)10 Scientist (org.mapstruct.ap.test.array.source.Scientist)9 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)7