Skip to content

Commit

Permalink
2.0.20-RC support
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jul 31, 2024
1 parent 1a0bc65 commit 0f66c20
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compatibility-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
compatibility:
strategy:
matrix:
version: ['kotlin-1.9.24', 'kotlin-2.0.0', 'kotlin-2.0.20-Beta1', 'java']
version: ['kotlin-1.9.24', 'kotlin-2.0.0', 'kotlin-2.0.20-RC', 'java']
name: Compatibility
permissions:
pull-requests: read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class MappieGradlePlugin : KotlinCompilerPluginSupportPlugin {

private companion object {
private const val KOTLIN_GRADLE_PLUGIN_NAME = "kotlin-gradle-plugin"
private val SUPPORTED_KOTLIN_VERSIONS = listOf("1.9.24", "2.0.0", "2.0.20-Beta1")
private val SUPPORTED_KOTLIN_VERSIONS = listOf(
"1.9.24",
"2.0.0",
"2.0.20-RC",
)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "2.0.20-Beta1"
id("org.jetbrains.kotlin.jvm") version "2.0.20-RC"
id("tech.mappie.plugin") version "+"
}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = "mappie-test-kotlin-2.0.20-Beta1"
rootProject.name = "mappie-test-kotlin-2.0.20-RC"

pluginManagement {
repositories {
Expand Down
11 changes: 11 additions & 0 deletions test/kotlin-2.0.20-RC/src/main/kotlin/EnumMapping.kt
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 test/kotlin-2.0.20-RC/src/main/kotlin/GeneratedEnumMapper.kt
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>()
36 changes: 36 additions & 0 deletions test/kotlin-2.0.20-RC/src/main/kotlin/ObjectMapper.kt
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
}
}
21 changes: 21 additions & 0 deletions test/kotlin-2.0.20-RC/src/test/kotlin/EnumMapperTest.kt
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
)
}
}
}
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)
)
}
}
}
13 changes: 13 additions & 0 deletions test/kotlin-2.0.20-RC/src/test/kotlin/ObjectMapperTest.kt
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)))
)
}
}

0 comments on commit 0f66c20

Please sign in to comment.