Skip to content

Commit

Permalink
feedback PR - tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelPelser committed Nov 21, 2024
1 parent 385830d commit 8c73a2f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@ class FromExpressionTest {
assertThat(mapper.map(101)).isEqualTo(Output("101"))
}
}

@Test
fun `map property fromExpression should fail with method reference with wrong return type`() {
compile(directory) {
file("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.objects.FromExpressionTest.*
class Mapper : ObjectMappie<Int, Output>() {
override fun map(from: Int) = mapping {
Output::value fromExpression Int::toInt
}
}
"""
)
} satisfies {
isCompilationError()
hasErrorMessage(6, "Target Output::value of type String cannot be assigned from expression of type Int")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.junit.jupiter.api.io.TempDir
import tech.mappie.testing.compilation.compile
import tech.mappie.testing.loadObjectMappieClass
import java.io.File
import kotlin.random.Random

class ObjectWithDifferentValuesTest {

Expand Down Expand Up @@ -148,4 +149,27 @@ class ObjectWithDifferentValuesTest {
assertThat(mapper.map(Input("101", 9))).isEqualTo(Output("9", 101))
}
}

@Test
fun `map property fromProperty should fail with method reference with wrong signature`() {
compile(directory) {
file("Test.kt",
"""
import tech.mappie.api.ObjectMappie
import tech.mappie.testing.objects.ObjectWithDifferentValuesTest.*
class Mapper : ObjectMappie<Input, Output>() {
override fun map(from: Input) = mapping {
Output::age fromProperty from::firstname transform String::toString
Output::name fromProperty from::age transform Int::toInt
}
}
"""
)
} satisfies {
isCompilationError()
hasErrorMessage(6, "Inapplicable candidate(s): fun toString(): String")
hasErrorMessage(7, "Inapplicable candidate(s): fun toInt(): Int")
}
}
}

0 comments on commit 8c73a2f

Please sign in to comment.