-
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 automatic resolving of via nullable mappers
- Loading branch information
1 parent
e67bb96
commit ba26595
Showing
5 changed files
with
172 additions
and
1 deletion.
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
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
51 changes: 51 additions & 0 deletions
51
compiler-plugin/src/test/kotlin/tech/mappie/testing/ObjectWithNestedNonNullToNullTest.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,51 @@ | ||
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 ObjectWithNestedNonNullToNullTest { | ||
data class Input(val text: InnerInput, val int: Int) | ||
data class InnerInput(val value: String) | ||
data class Output(val text: InnerOutput?, val int: Int) | ||
data class InnerOutput(val value: String) | ||
|
||
@TempDir | ||
private lateinit var directory: File | ||
|
||
@Test | ||
fun `map data classes with nested null to non-null using object InnerMapper without declaring mapping should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.ObjectWithNestedNonNullToNullTest.* | ||
class Mapper : ObjectMappie<Input, Output>() | ||
object InnerMapper : ObjectMappie<InnerInput, InnerOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(Input(InnerInput("value"), 20))) | ||
.isEqualTo(Output(InnerOutput("value"), 20)) | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
compiler-plugin/src/test/kotlin/tech/mappie/testing/ObjectWithNestedNullTest.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,115 @@ | ||
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 ObjectWithNestedNullTest { | ||
data class Input(val text: InnerInput?, val int: Int) | ||
data class InnerInput(val value: String) | ||
data class Output(val text: InnerOutput?, val int: Int) | ||
data class InnerOutput(val value: String) | ||
|
||
@TempDir | ||
private lateinit var directory: File | ||
|
||
@Test | ||
fun `map data classes with nested non-null to non-null using object InnerMapper without declaring mapping should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.ObjectWithNestedNullTest.* | ||
class Mapper : ObjectMappie<Input, Output>() | ||
object InnerMapper : ObjectMappie<InnerInput, InnerOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(Input(InnerInput("value"), 20))) | ||
.isEqualTo(Output(InnerOutput("value"), 20)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map data classes with nested null to null using object InnerMapper without declaring mapping should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.ObjectWithNestedNullTest.* | ||
class Mapper : ObjectMappie<Input, Output>() | ||
object InnerMapper : ObjectMappie<InnerInput, InnerOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(Input(null, 20))) | ||
.isEqualTo(Output(null, 20)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `map data classes with nested null to non-null using object InnerMapper without declaring mapping should succeed`() { | ||
KotlinCompilation(directory).apply { | ||
sources = buildList { | ||
add( | ||
kotlin("Test.kt", | ||
""" | ||
import tech.mappie.api.ObjectMappie | ||
import tech.mappie.testing.ObjectWithNestedNullTest.* | ||
class Mapper : ObjectMappie<Input, Output>() | ||
object InnerMapper : ObjectMappie<InnerInput, InnerOutput>() | ||
""" | ||
) | ||
) | ||
} | ||
}.compile { | ||
assertThat(exitCode).isEqualTo(ExitCode.OK) | ||
assertThat(messages).isEmpty() | ||
|
||
val mapper = classLoader | ||
.loadObjectMappieClass<Input, Output>("Mapper") | ||
.constructors | ||
.first() | ||
.call() | ||
|
||
assertThat(mapper.map(Input(null, 20))) | ||
.isEqualTo(Output(null, 20)) | ||
} | ||
} | ||
} |