Skip to content

Commit 03eb690

Browse files
committed
Add test for Kotlin example
1 parent 769e80c commit 03eb690

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

mapstruct-kotlin/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
<artifactId>kotlin-stdlib</artifactId>
3232
<version>${kotlin.version}</version>
3333
</dependency>
34+
<dependency>
35+
<groupId>org.jetbrains.kotlin</groupId>
36+
<artifactId>kotlin-test-junit</artifactId>
37+
<version>${kotlin.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>junit</groupId>
42+
<artifactId>junit</artifactId>
43+
<version>4.12</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.assertj</groupId>
48+
<artifactId>assertj-core</artifactId>
49+
<version>3.8.0</version>
50+
<scope>test</scope>
51+
</dependency>
3452
</dependencies>
3553

3654
<build>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.mapstruct.example.kotlin.converter
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.junit.Test
5+
import org.mapstruct.example.kotlin.dto.PersonDto
6+
import org.mapstruct.example.kotlin.model.Person
7+
import org.mapstruct.factory.Mappers
8+
import java.time.LocalDate
9+
10+
class PersonConverterTest {
11+
12+
@Test
13+
fun testConvertToDto() {
14+
val converter = Mappers.getMapper(PersonConverter::class.java)
15+
16+
val person = Person("Samuel", "Jackson", "0123 334466", LocalDate.of(1948, 12, 21))
17+
18+
val personDto = converter.convertToDto(person)
19+
assertThat(personDto).isNotNull()
20+
assertThat(personDto.firstName).isEqualTo("Samuel")
21+
assertThat(personDto.lastName).isEqualTo("Jackson")
22+
assertThat(personDto.phone).isEqualTo("0123 334466")
23+
assertThat(personDto.birthdate).isEqualTo(LocalDate.of(1948, 12, 21))
24+
}
25+
26+
@Test
27+
fun testConvertToModel() {
28+
val converter = Mappers.getMapper(PersonConverter::class.java)
29+
30+
val personDto = PersonDto("Samuel", "Jackson", "0123 334466", LocalDate.of(1948, 12, 21))
31+
32+
val person = converter.convertToModel(personDto)
33+
assertThat(person).isNotNull()
34+
assertThat(person.firstName).isEqualTo("Samuel")
35+
assertThat(person.lastName).isEqualTo("Jackson")
36+
assertThat(person.phoneNumber).isEqualTo("0123 334466")
37+
assertThat(person.birthdate).isEqualTo(LocalDate.of(1948, 12, 21))
38+
}
39+
40+
}

0 commit comments

Comments
 (0)