Search in sources :

Example 11 with PersonDto

use of org.mapstruct.ap.test.constructor.PersonDto in project mapstruct by mapstruct.

the class ConstructorVisibilityTest method shouldUseDefaultAnnotatedConstructorAlways.

@ProcessorTest
@WithClasses({ SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.class })
public void shouldUseDefaultAnnotatedConstructorAlways() {
    PersonDto source = new PersonDto();
    source.setName("Bob");
    source.setAge(30);
    SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.Person target = SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(30);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 12 with PersonDto

use of org.mapstruct.ap.test.constructor.PersonDto in project mapstruct by mapstruct.

the class SimpleDefaultAnnotatedConstructorTest method mapWithConstants.

@ProcessorTest
public void mapWithConstants() {
    PersonDto source = new PersonDto();
    source.setName("Bob");
    source.setAge(30);
    source.setJob("Software Engineer");
    source.setCity("Zurich");
    source.setAddress("Plaza 1");
    source.setChildren(Arrays.asList("Alice", "Tom"));
    PersonWithDefaultAnnotatedConstructor target = SimpleDefaultAnnotatedConstructorMapper.INSTANCE.mapWithConstants(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(25);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 13 with PersonDto

use of org.mapstruct.ap.test.constructor.PersonDto in project mapstruct by mapstruct.

the class SimpleConstructorTest method mapWithExpressions.

@ProcessorTest
public void mapWithExpressions() {
    PersonDto source = new PersonDto();
    source.setName("Bob");
    source.setAge(30);
    source.setJob("Software Engineer");
    source.setCity("Zurich");
    source.setAddress("Plaza 1");
    source.setChildren(Arrays.asList("Alice", "Tom"));
    Person target = SimpleConstructorMapper.INSTANCE.mapWithExpression(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(20);
    assertThat(target.getJob()).isEqualTo("software developer");
    assertThat(target.getCity()).isEqualTo("Zurich");
    assertThat(target.getAddress()).isEqualTo("Plaza 1");
    assertThat(target.getChildren()).containsExactly("Alice", "Tom");
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) Person(org.mapstruct.ap.test.constructor.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)13 Person (org.mapstruct.ap.test.constructor.Person)3 WithClasses (org.mapstruct.ap.testutil.WithClasses)3