From 2e6c01efadb5c7cf4349d405d395b47abc126f23 Mon Sep 17 00:00:00 2001 From: Ali Sabzevari Date: Sat, 6 Oct 2018 15:54:21 +0200 Subject: [PATCH] #17 Modify project to migrate to kotlin 1.3 --- .idea/kotlin-http4k-realworld-example-app.iml | 9 ---- .idea/modules.xml | 8 --- .idea/modules/conduit_main.iml | 27 ---------- .idea/modules/conduit_test.iml | 27 ---------- .idea/vcs.xml | 1 + build.gradle | 13 ++++- src/main/kotlin/conduit/model/models.kt | 51 +++++++++++-------- src/test/kotlin/conduit/MockkFailingTest.kt | 26 ++++++++++ .../conduit/handler/LoginHandlerImplTest.kt | 3 +- 9 files changed, 69 insertions(+), 96 deletions(-) delete mode 100644 .idea/kotlin-http4k-realworld-example-app.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/modules/conduit_main.iml delete mode 100644 .idea/modules/conduit_test.iml create mode 100644 src/test/kotlin/conduit/MockkFailingTest.kt diff --git a/.idea/kotlin-http4k-realworld-example-app.iml b/.idea/kotlin-http4k-realworld-example-app.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/kotlin-http4k-realworld-example-app.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a31fd36..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/conduit_main.iml b/.idea/modules/conduit_main.iml deleted file mode 100644 index fef3e14..0000000 --- a/.idea/modules/conduit_main.iml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/conduit_test.iml b/.idea/modules/conduit_test.iml deleted file mode 100644 index a5b13d0..0000000 --- a/.idea/modules/conduit_test.iml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..8306744 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 19daa71..8c1e9df 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ buildscript { - ext.kotlin_version = "1.2.51" + ext.kotlin_version = "1.3.0-rc-146" ext.http4k_version = "3.33.1" ext.log4j_version = "2.10.0" ext.jackson_version = "2.9.6" repositories { + maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } mavenCentral() } @@ -19,6 +20,7 @@ repositories { mavenCentral() jcenter() maven { url "http://dl.bintray.com/kotlin/exposed" } + maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } } dependencies { @@ -34,15 +36,22 @@ dependencies { implementation "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version" implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jackson_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testImplementation "org.junit.jupiter:junit-jupiter-api:5.1.0" testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" - testImplementation "io.mockk:mockk:1.8.7" + testImplementation "io.mockk:mockk:1.8.9.kotlin13" } compileKotlin { kotlinOptions.jvmTarget = "1.8" + kotlinOptions { + freeCompilerArgs = ["-XXLanguage:+InlineClasses"] + } } compileTestKotlin { kotlinOptions.jvmTarget = "1.8" + kotlinOptions { + freeCompilerArgs = ["-XXLanguage:+InlineClasses"] + } } diff --git a/src/main/kotlin/conduit/model/models.kt b/src/main/kotlin/conduit/model/models.kt index 34e9b85..778ef06 100644 --- a/src/main/kotlin/conduit/model/models.kt +++ b/src/main/kotlin/conduit/model/models.kt @@ -5,29 +5,36 @@ import com.fasterxml.jackson.annotation.JsonValue import conduit.util.TokenAuth import com.fasterxml.jackson.annotation.JsonCreator.Mode.DELEGATING as m -data class Email @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} +inline class Email(val value: String) +inline class Password(val value: String) +inline class Token(val value: String) +inline class Username(val value: String) +inline class Bio(val value: String) +inline class Image(val value: String) -data class Password @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} - -data class Token @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} - -data class Username @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} - -data class Bio @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} - -data class Image @JsonCreator(mode = m) constructor(@JsonValue val value: String) { - override fun toString(): String = this.value -} +//data class Email @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} +// +//data class Password @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} +// +//data class Token @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} +// +//data class Username @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} +// +//data class Bio @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} +// +//data class Image @JsonCreator(mode = m) constructor(@JsonValue val value: String) { +// override fun toString(): String = this.value +//} data class User( val id: Int, diff --git a/src/test/kotlin/conduit/MockkFailingTest.kt b/src/test/kotlin/conduit/MockkFailingTest.kt new file mode 100644 index 0000000..25895cd --- /dev/null +++ b/src/test/kotlin/conduit/MockkFailingTest.kt @@ -0,0 +1,26 @@ +package conduit + +import io.mockk.every +import io.mockk.mockk +import org.junit.jupiter.api.Test + +class MockkFailingTest { + @Test // fails + fun `mockk test using any()`() { + val mocked = mockk(relaxed = true) + every { mocked.test(any()) } returns 1 + } + + @Test // passes + fun `mockk test using hardcoded value`() { + val mocked = mockk(relaxed = true) + every { mocked.test(MyInlineType("123")) } returns 1 + } + +} + +inline class MyInlineType(val value: String) + +interface TestMock { + fun test(value: MyInlineType): Int +} diff --git a/src/test/kotlin/conduit/handler/LoginHandlerImplTest.kt b/src/test/kotlin/conduit/handler/LoginHandlerImplTest.kt index c03de4a..5e29f16 100644 --- a/src/test/kotlin/conduit/handler/LoginHandlerImplTest.kt +++ b/src/test/kotlin/conduit/handler/LoginHandlerImplTest.kt @@ -71,5 +71,6 @@ class LoginHandlerImplTest { unit(loginInfo) } } -} + +} \ No newline at end of file