Skip to content

Commit

Permalink
Remove mockito from dependencies and replace usages with mockk (#3539)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsinukov authored Apr 18, 2023
1 parent cd2be8e commit 977cf8b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion THIRDPARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ library-specific functionality (via plugins) that Ktor provides.


* [MockK](https://mockk.io/). Apache 2.0 License.
* [Mockito](https://site.mockito.org/). MIT License.
* [Moowork](https://github.com/srs/gradle-node-plugin). Apache 2.0 License.
* [Apache HTTP Components](https://hc.apache.org/). Apache 2.0 License.
* [Kotlin](https://kotlinlang.org). Apache 2.0 License.
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jansi-version = "2.4.0"
typesafe-version = "1.4.2"

mockk-version = "1.13.5"
mokito-kotlin-version = "1.6.0"

java-jwt-version = "4.4.0"

Expand Down Expand Up @@ -138,7 +137,6 @@ typesafe-config = { module = "com.typesafe:config", version.ref = "typesafe-vers
java-jwt = { module = "com.auth0:java-jwt", version.ref = "java-jwt-version" }
jwks-rsa = { module = "com.auth0:jwks-rsa", version.ref = "jwks-rsa-version" }

mockito-kotlin = { module = "com.nhaarman:mockito-kotlin", version.ref = "mokito-kotlin-version" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk-version" }

slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-version" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin.sourceSets {
}
jvmTest {
dependencies {
api(libs.mockito.kotlin)
api(libs.mockk)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package io.ktor.server.auth.jwt
import com.auth0.jwk.*
import com.auth0.jwt.*
import com.auth0.jwt.algorithms.*
import com.nhaarman.mockito_kotlin.*
import io.ktor.http.*
import io.ktor.http.auth.*
import io.ktor.server.application.*
Expand All @@ -16,6 +15,7 @@ import io.ktor.server.auth.Principal
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import io.mockk.*
import java.security.*
import java.security.interfaces.*
import java.util.concurrent.*
Expand Down Expand Up @@ -593,22 +593,23 @@ class JWTAuthTest {
private val kid = "NkJCQzIyQzRBMEU4NjhGNUU4MzU4RkY0M0ZDQzkwOUQ0Q0VGNUMwQg"

private fun getJwkProviderNullAlgorithmMock(): JwkProvider {
val jwk = mock<Jwk> {
on { publicKey } doReturn keyPair.public
val jwk = mockk<Jwk> {
every { algorithm } returns null
every { publicKey } returns keyPair.public
}
return mock {
on { get(kid) } doReturn jwk
return mockk {
every { this@mockk.get(kid) } returns jwk
}
}

private fun getJwkProviderMock(): JwkProvider {
val jwk = mock<Jwk> {
on { algorithm } doReturn jwkAlgorithm.name
on { publicKey } doReturn keyPair.public
val jwk = mockk<Jwk> {
every { algorithm } returns jwkAlgorithm.name
every { publicKey } returns keyPair.public
}
return mock {
on { get(kid) } doReturn jwk
on { get("wrong") } doThrow (SigningKeyNotFoundException("Key not found", null))
return mockk {
every { this@mockk.get(kid) } returns jwk
every { this@mockk.get("wrong") } throws SigningKeyNotFoundException("Key not found", null)
}
}

Expand Down

0 comments on commit 977cf8b

Please sign in to comment.