-
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.
Fixed bug with wrong map function to transform selection
- Loading branch information
1 parent
8e7573b
commit a3ee84b
Showing
2 changed files
with
58 additions
and
6 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
57 changes: 57 additions & 0 deletions
57
...iler-plugin/src/test/kotlin/tech/mappie/testing/MapperClassCanMultipleMapFunctionsTest.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,57 @@ | ||
package tech.mappie.testing | ||
|
||
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.KotlinCompilation | ||
import tech.mappie.testing.compilation.KotlinCompilation.ExitCode | ||
import tech.mappie.testing.compilation.SourceFile.Companion.kotlin | ||
import java.io.File | ||
|
||
class MapperClassCanMultipleMapFunctionsTest { | ||
|
||
data class Input(val text: String) | ||
data class Output(val text: String, val int: Int) | ||
|
||
@TempDir | ||
private lateinit var directory: File | ||
|
||
@Test | ||
fun `mapper with multiple map functions should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.MapperClassCanMultipleMapFunctionsTest.* | ||
class Mapper(private val int: Int) : ObjectMappie<Input, Output>() { | ||
fun map(value: String) = value | ||
override fun map(from: Input) = mapping { | ||
Output::int fromValue int | ||
} | ||
fun map(value: Int) = int | ||
} | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call(10) | ||
|
||
assertThat(mapper.map(Input("test"))) | ||
.isEqualTo(Output("test", 10)) | ||
} | ||
} | ||
|
||
} |