Search in sources :

Example 1 with PersonDto

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

the class ConstructorVisibilityTest method shouldUsePublicParameterConstructorIfPresent.

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

Example 2 with PersonDto

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

the class SimpleConstructorTest 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"));
    Person target = SimpleConstructorMapper.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) Person(org.mapstruct.ap.test.constructor.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 3 with PersonDto

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

the class SimpleConstructorTest 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"));
    Person target = SimpleConstructorMapper.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) Person(org.mapstruct.ap.test.constructor.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 4 with PersonDto

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

the class SimpleConstructorPropertiesTest 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"));
    PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.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) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with PersonDto

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

the class SimpleDefaultAnnotatedConstructorTest 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"));
    PersonWithDefaultAnnotatedConstructor target = SimpleDefaultAnnotatedConstructorMapper.INSTANCE.map(source);
    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)

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