-
Notifications
You must be signed in to change notification settings - Fork 2
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
1a0bc65
commit 0f66c20
Showing
16 changed files
with
126 additions
and
4 deletions.
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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/kotlin-2.0.20-Beta1/build.gradle.kts → test/kotlin-2.0.20-RC/build.gradle.kts
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
0
test/kotlin-2.0.20-Beta1/gradlew → test/kotlin-2.0.20-RC/gradlew
100755 → 100644
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/kotlin-2.0.20-Beta1/settings.gradle.kts → test/kotlin-2.0.20-RC/settings.gradle.kts
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
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,11 @@ | ||
import tech.mappie.api.EnumMappie | ||
|
||
enum class InputEnum { | ||
A, B, C, D; | ||
} | ||
|
||
enum class OutputEnum { | ||
A, B, C, D, E; | ||
} | ||
|
||
object EnumMapper : EnumMappie<InputEnum, OutputEnum>() |
15 changes: 15 additions & 0 deletions
15
test/kotlin-2.0.20-RC/src/main/kotlin/GeneratedEnumMapper.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 @@ | ||
import tech.mappie.api.ObjectMappie | ||
|
||
data class NestedGeneratedInputObject(val enum: InputEnumTwo) | ||
|
||
enum class InputEnumTwo { | ||
A, B, C, D; | ||
} | ||
|
||
data class NestedGeneratedOutputObject(val enum: OutputEnumTwo) | ||
|
||
enum class OutputEnumTwo { | ||
A, B, C, D, E; | ||
} | ||
|
||
object NestedGeneratedInputToOutputMapper : ObjectMappie<NestedGeneratedInputObject, NestedGeneratedOutputObject>() |
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,36 @@ | ||
import tech.mappie.api.ObjectMappie | ||
|
||
data class InputObject( | ||
val name: String, | ||
val age: Int, | ||
val nested: NestedInput, | ||
) | ||
|
||
data class NestedInput(val boolean: BooleanEnum) { | ||
enum class BooleanEnum { TRUE, FALSE } | ||
} | ||
|
||
data class OutputObject( | ||
val name: String, | ||
val age: Int, | ||
val boolean: Boolean, | ||
) | ||
|
||
object ObjectMapperWithoutVia : ObjectMappie<InputObject, OutputObject>() { | ||
override fun map(from: InputObject) = mapping { | ||
to::boolean fromProperty from.nested::boolean | ||
} | ||
} | ||
|
||
object ObjectMapper : ObjectMappie<InputObject, OutputObject>() { | ||
override fun map(from: InputObject) = mapping { | ||
to::boolean fromProperty from.nested::boolean via BooleanEnumToBooleanMapper | ||
} | ||
} | ||
|
||
object BooleanEnumToBooleanMapper : ObjectMappie<NestedInput.BooleanEnum, Boolean>() { | ||
override fun map(from: NestedInput.BooleanEnum) = when (from) { | ||
NestedInput.BooleanEnum.TRUE -> !false | ||
NestedInput.BooleanEnum.FALSE -> !true | ||
} | ||
} |
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,21 @@ | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class EnumMapperTest { | ||
|
||
private val mappings = listOf( | ||
InputEnum.A to OutputEnum.A, | ||
InputEnum.B to OutputEnum.B, | ||
InputEnum.C to OutputEnum.C, | ||
InputEnum.D to OutputEnum.D, | ||
) | ||
|
||
@Test | ||
fun `map InputEnum to OutputEnum`() { | ||
mappings.forEach { (input, expected) -> | ||
assertEquals( | ||
EnumMapper.map(input), expected | ||
) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/kotlin-2.0.20-RC/src/test/kotlin/NestedGeneratedEnumMapperTest.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,22 @@ | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class NestedGeneratedEnumMapperTest { | ||
|
||
private val mappings = listOf( | ||
InputEnumTwo.A to OutputEnumTwo.A, | ||
InputEnumTwo.B to OutputEnumTwo.B, | ||
InputEnumTwo.C to OutputEnumTwo.C, | ||
InputEnumTwo.D to OutputEnumTwo.D, | ||
) | ||
|
||
@Test | ||
fun `map NestedGeneratedInputObject to NestedGeneratedOutputObject`() { | ||
mappings.forEach { (input, expected) -> | ||
assertEquals( | ||
NestedGeneratedInputToOutputMapper.map(NestedGeneratedInputObject(input)), | ||
NestedGeneratedOutputObject(expected) | ||
) | ||
} | ||
} | ||
} |
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,13 @@ | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ObjectMapperTest { | ||
|
||
@Test | ||
fun `map using ObjectMapper`() { | ||
assertEquals( | ||
OutputObject("name", 22, true), | ||
ObjectMapper.map(InputObject("name", 22, NestedInput(NestedInput.BooleanEnum.TRUE))) | ||
) | ||
} | ||
} |