Search in sources :

Example 6 with PersonDto

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

the class SimpleDefaultAnnotatedConstructorTest 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"));
    PersonWithDefaultAnnotatedConstructor target = SimpleDefaultAnnotatedConstructorMapper.INSTANCE.mapWithExpression(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(20);
}
Also used : PersonDto(org.mapstruct.ap.test.constructor.PersonDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 7 with PersonDto

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

the class SimpleConstructorPropertiesTest 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"));
    PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.INSTANCE.mapWithConstants(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(25);
    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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 8 with PersonDto

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

the class SimpleConstructorPropertiesTest method mapDefault.

@ProcessorTest
public void mapDefault() {
    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"));
    PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.INSTANCE.map(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(30);
    assertThat(target.getJob()).isEqualTo("Software Engineer");
    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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 9 with PersonDto

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

the class ConstructorMixedWithSettersTest method mapDefault.

@ProcessorTest
public void mapDefault() {
    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"));
    PersonMixed target = ConstructorMixedWithSettersMapper.INSTANCE.map(source);
    assertThat(target.getName()).isEqualTo("Bob");
    assertThat(target.getAge()).isEqualTo(30);
    assertThat(target.getJob()).isEqualTo("Software Engineer");
    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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 10 with PersonDto

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

the class ConstructorVisibilityTest method shouldUseSinglePublicConstructorAlways.

@ProcessorTest
@WithClasses({ SimpleWithPublicConstructorMapper.class })
public void shouldUseSinglePublicConstructorAlways() {
    PersonDto source = new PersonDto();
    source.setName("Bob");
    source.setAge(30);
    SimpleWithPublicConstructorMapper.Person target = SimpleWithPublicConstructorMapper.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)

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