-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
204be3b
commit ad745a3
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
testing/src/main/kotlin/testing/ListToNullableListMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package testing | ||
|
||
import tech.mappie.api.ObjectMappie | ||
|
||
data class SourceList(val value: List<String>) | ||
|
||
data class TargetList(val value: List<String>?) | ||
|
||
object NullableListFromListMapper : ObjectMappie<SourceList, TargetList>() { | ||
override fun map(from: SourceList): TargetList = mapping { | ||
TargetList::value fromProperty SourceList::value via StringIdentityMapper.forList | ||
} | ||
} | ||
|
||
object StringIdentityMapper : ObjectMappie<String, String>() { | ||
override fun map(from: String): String = from | ||
} |
15 changes: 15 additions & 0 deletions
15
testing/src/test/kotlin/testing/ListToNullableListMapperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package testing | ||
|
||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ListToNullableListMapperTest { | ||
|
||
@Test | ||
fun `map List to nullable List via NullableListFromList`() { | ||
assertEquals( | ||
TargetList(listOf("A", "B")), | ||
NullableListFromListMapper.map(SourceList(listOf("A", "B"))), | ||
) | ||
} | ||
} |