-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
a5bccdc
commit 0e2e789
Showing
15 changed files
with
613 additions
and
11 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
90 changes: 90 additions & 0 deletions
90
compiler-plugin/src/test/kotlin/tech/mappie/testing/builtin/DoubleMappersTest.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,90 @@ | ||
package tech.mappie.testing.builtin | ||
|
||
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 tech.mappie.testing.loadObjectMappieClass | ||
import java.io.File | ||
import java.math.BigDecimal | ||
|
||
class DoubleMappersTest { | ||
|
||
@TempDir | ||
lateinit var directory: File | ||
|
||
data class DoubleInput(val value: Double) | ||
|
||
data class BigDecimalOutput(val value: BigDecimal) | ||
|
||
@Test | ||
fun `map Double to BigDecimal implicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.builtin.DoubleMappersTest.* | ||
class Mapper : ObjectMappie<DoubleInput, BigDecimalOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 2.0 | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<DoubleInput, BigDecimalOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(DoubleInput(input))) | ||
.isEqualTo(BigDecimalOutput(input.toBigDecimal())) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map Double to BigDecimal explicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.api.builtin.* | ||
import tech.mappie.testing.builtin.DoubleMappersTest.* | ||
class Mapper : ObjectMappie<DoubleInput, BigDecimalOutput>() { | ||
override fun map(from: DoubleInput) = mapping { | ||
to::value fromProperty from::value via DoubleToBigDecimalMapper() | ||
} | ||
} | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 5.0 | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<DoubleInput, BigDecimalOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(DoubleInput(input))) | ||
.isEqualTo(BigDecimalOutput(input.toBigDecimal())) | ||
} | ||
} | ||
} |
162 changes: 162 additions & 0 deletions
162
compiler-plugin/src/test/kotlin/tech/mappie/testing/builtin/FloatMappersTest.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,162 @@ | ||
package tech.mappie.testing.builtin | ||
|
||
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 tech.mappie.testing.loadObjectMappieClass | ||
import java.io.File | ||
import java.math.BigDecimal | ||
import java.math.BigInteger | ||
|
||
class FloatMappersTest { | ||
|
||
@TempDir | ||
lateinit var directory: File | ||
|
||
data class FloatInput(val value: Float) | ||
|
||
data class DoubleOutput(val value: Double) | ||
|
||
data class BigDecimalOutput(val value: BigDecimal) | ||
|
||
@Test | ||
fun `map Float to Double implicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.builtin.FloatMappersTest.* | ||
class Mapper : ObjectMappie<FloatInput, DoubleOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 2.0f | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<FloatInput, DoubleOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(FloatInput(input))) | ||
.isEqualTo(DoubleOutput(input.toDouble())) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map Float to Double explicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.api.builtin.* | ||
import tech.mappie.testing.builtin.FloatMappersTest.* | ||
class Mapper : ObjectMappie<FloatInput, DoubleOutput>() { | ||
override fun map(from: FloatInput) = mapping { | ||
to::value fromProperty from::value via FloatToDoubleMapper() | ||
} | ||
} | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 5.0f | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<FloatInput, DoubleOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(FloatInput(input))) | ||
.isEqualTo(DoubleOutput(input.toDouble())) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map Float to BigDecimal implicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.builtin.FloatMappersTest.* | ||
class Mapper : ObjectMappie<FloatInput, BigDecimalOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 2.0f | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<FloatInput, BigDecimalOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(FloatInput(input))) | ||
.isEqualTo(BigDecimalOutput(input.toBigDecimal())) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map Float to BigDecimal explicit should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.api.builtin.* | ||
import tech.mappie.testing.builtin.FloatMappersTest.* | ||
class Mapper : ObjectMappie<FloatInput, BigDecimalOutput>() { | ||
override fun map(from: FloatInput) = mapping { | ||
to::value fromProperty from::value via FloatToBigDecimalMapper() | ||
} | ||
} | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val input = 5.0f | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<FloatInput, BigDecimalOutput>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(FloatInput(input))) | ||
.isEqualTo(BigDecimalOutput(input.toBigDecimal())) | ||
} | ||
} | ||
} |
Oops, something went wrong.