|
| 1 | +package tech.mappie.testing.objects5 |
| 2 | + |
| 3 | +import org.assertj.core.api.Assertions.assertThat |
| 4 | +import org.junit.jupiter.api.Test |
| 5 | +import tech.mappie.testing.MappieTestCase |
| 6 | + |
| 7 | +class Object5WithFromValueTest : MappieTestCase() { |
| 8 | + |
| 9 | + data class Input5(val float: Float) |
| 10 | + data class Output(val first: Long, val second: Long, val third: Long, val fourth: String, val float: Float) |
| 11 | + |
| 12 | + @Test |
| 13 | + fun `map five data classes into one should succeed`() { |
| 14 | + compile { |
| 15 | + file("Test.kt", |
| 16 | + """ |
| 17 | + import tech.mappie.api.ObjectMappie5 |
| 18 | + import tech.mappie.testing.objects5.Object5WithFromValueTest.* |
| 19 | +
|
| 20 | + class Mapper : ObjectMappie5<Long, Long, Long, String, Input5, Output>() |
| 21 | + """ |
| 22 | + ) |
| 23 | + } satisfies { |
| 24 | + isOk() |
| 25 | + hasNoWarningsOrErrors() |
| 26 | + |
| 27 | + val mapper = objectMappie5<Long, Long, Long, String, Input5, Output>() |
| 28 | + |
| 29 | + assertThat(mapper.map(1, 2, 3, "value", Input5(1.0f))) |
| 30 | + .isEqualTo(Output(1, 2, 3, "value", 1.0f)) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + fun `map five data classes into one with run should fail`() { |
| 36 | + compile { |
| 37 | + file("Test.kt", |
| 38 | + """ |
| 39 | + import tech.mappie.api.ObjectMappie5 |
| 40 | + import tech.mappie.testing.objects5.Object5WithFromValueTest.* |
| 41 | +
|
| 42 | + class Mapper : ObjectMappie5<Long, Long, Long, String, Input5, Output>() { |
| 43 | + override fun map(first: Long, second: Long, third: Long, fourth: String, fifth: Input5) = mapping { |
| 44 | + to::fourth fromValue run { uppercase("test") } |
| 45 | + to::float fromProperty fifth::float transform { it + 1 } |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + private fun uppercase(value: String) = value.uppercase() |
| 50 | + """ |
| 51 | + ) |
| 52 | + } satisfies { |
| 53 | + isCompilationError() |
| 54 | + hasErrorMessage(6, |
| 55 | + "The function 'run' was called as an extension method on the mapping dsl which does not exist after compilation") |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments