-
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
Abel
committed
Nov 21, 2024
1 parent
69019f5
commit b3c1489
Showing
4 changed files
with
102 additions
and
7 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
75 changes: 75 additions & 0 deletions
75
compiler-plugin/src/test/kotlin/tech/mappie/testing/objects/MethodReferenceTest.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,75 @@ | ||
package tech.mappie.testing.objects | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import tech.mappie.testing.compilation.compile | ||
import tech.mappie.testing.loadObjectMappieClass | ||
import java.io.File | ||
|
||
class MethodReferenceTest { | ||
|
||
data class Input(val x: Int) | ||
data class Output(val value: String) | ||
|
||
@TempDir | ||
lateinit var directory: File | ||
|
||
@Test | ||
fun `map property fromExpression should succeed with method reference`() { | ||
compile(directory) { | ||
file("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.objects.MethodReferenceTest.* | ||
class Mapper : ObjectMappie<Int, Output>() { | ||
override fun map(from: Int) = mapping { | ||
Output::value fromExpression Int::toString | ||
} | ||
} | ||
""" | ||
) | ||
} satisfies { | ||
isOk() | ||
hasNoMessages() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Int, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(101)).isEqualTo(Output("101")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map property fromProperty should succeed with method reference transform`() { | ||
compile(directory) { | ||
file("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.objects.MethodReferenceTest.* | ||
class Mapper : ObjectMappie<Input, Output>() { | ||
override fun map(from: Input) = mapping { | ||
Output::value fromProperty from::x transform Int::toString | ||
} | ||
} | ||
""" | ||
) | ||
} satisfies { | ||
isOk() | ||
hasNoMessages() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(Input(101))).isEqualTo(Output("101")) | ||
} | ||
} | ||
} |
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