poohbar
05/28/2018, 2:30 PMoleksiyp
06/04/2018, 9:30 PMthatadamedwards
06/08/2018, 9:36 PMval (_, _, result) = myUrlString.httpPost()
.header("Content-Type" to "application/json", "Authorization" to "Bearer $authToken")
.body(jacksonObjectMapper().writeValueAsString(message))
.responseString()
if (result is Result.Failure) {
val errorMessage = result.error.response.responseMessage
throw BadRequestException(errorMessage)
} else {
return true
}
dave08
06/10/2018, 5:37 PMresolve
extension from Kotlin stdlib on a File? I tried this, but it still seems to call the Kotlin code:
fun mockFile() = mockk<File>().apply {
every { resolve(any<File>()) } answers { mockk<File>(relaxed = true).apply {
every { path } returns "this.txt"
} }
}
// Gives
path must not be null
java.lang.IllegalStateException: path must not be null
at kotlin.io.FilesKt__FilePathComponentsKt.isRooted(FilePathComponents.kt:81)
at kotlin.io.FilesKt__UtilsKt.resolve(Utils.kt:400)
ghedeon
06/10/2018, 5:41 PMHtml.fromHtml()
?ghedeon
07/19/2018, 2:09 PMAssert
is quite popular on the assertion market). Thank you!poohbar
08/09/2018, 2:09 PMConcurrentModificationException
.. the tests looks kind of like this:
service.doSomething()
verify { mock1.aMethod() }
verify { mock2.aMethod() }
verify { mock3.aMethod() }
verify { mock4.aMethod() }
verify { mock5.aMethod() }
verify { mock6.aMethod() }
it throws the exception on the first verify
.. any clue what it could mean?quiqua
08/20/2018, 9:58 AMspyk
on a:
object GeometryValidation {
fun isPoint(coordinates: Position): ValidationResult = coordinates.validate()
fun isLineString(coordinates: List<Position>): ValidationResult {
coordinates.forEach { isPoint(it) }
....
}
private fun ...
}
and then verify that isPoint
has been called when calling isLineString
?oleksiyp
10/05/2018, 9:08 AMpoohbar
10/05/2018, 6:52 PMoleksiyp
10/10/2018, 10:26 AMoleksiyp
10/17/2018, 7:47 PMgildor
10/18/2018, 2:17 AMHexa
10/25/2018, 1:25 PM<http://mockk.io|mockk.io>
has an equivalent of this method any(Class<T> type)
which is from Mockito https://static.javadoc.io/org.mockito/mockito-core/2.11.0/org/mockito/ArgumentMatchers.html. I can't seem to find any equivalent so not sure what to use insteadHexa
10/26/2018, 2:46 PMHexa
10/28/2018, 10:45 AMany<T>()
is the same as any()
in this example?uhe
10/30/2018, 2:14 PMFailed to resolve: org.jetbrains.kotlin:kotlin-reflect:1.3.0-rc-80
when using io.mockk:mockk:1.8.9.kotlin13
?Gokul
10/31/2018, 5:11 AMmockkObject()
does not have a clearObjectMock()
method ? And how it is able to reset itself after every test?jobot0
10/31/2018, 1:58 PMcapture(slot)
should work here.
val obj = ExtendedObjBecauseImTestingOnAndroidUnderP(someStuff, someOtherStuff)
val objSpy = spyk(obj)
val slot = slot<ParamType>()
every {
obj.methodWhichSouldBePrivate(capture(slot), otherStuff))
} just Runs
Why am I getting this issue left matchers: [slotCapture<ParamType>()]
?Hexa
10/31/2018, 3:22 PMMockito.anyBoolean()
??poohbar
11/06/2018, 4:11 PMpoohbar
11/08/2018, 1:20 PMrobin
11/14/2018, 10:30 PMverify
? I'm currently switching from Mockito to MockK and am wondering what to do with my verifyNoMoreInteractions(mock)
calls.MrNiamh
11/15/2018, 11:23 AMAnthony f
11/28/2018, 4:24 PMMrNiamh
11/29/2018, 6:21 PMoleksiyp
11/29/2018, 7:13 PMmaxmello
12/03/2018, 4:01 PMrepository.save(entity)
method to just return whatever is passed into it. I thought that Slot
would be the correct way of doing this, but …
val slot = slot<Entity>()
every { repository.save(capture(slot)) } answers { slot.captured }
… does not work, because the slot.captured is lateinit and not initialized during initialization of the mocks. Am I missing something or is this not possible with mockK?jdiaz
12/04/2018, 12:39 AMevery { obj.method() } answers { mock["privateMethod"](); whatever; }
tKw
12/12/2018, 4:02 PMtKw
12/12/2018, 4:02 PMimport com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.jetbrains.exposed.dao.IntIdTable
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import kotlin.coroutines.CoroutineContext
class DatabaseConnection(config: HikariConfig) {
private val dispatcher: CoroutineContext = Dispatchers.Default
private val connection: Database = Database.connect(HikariDataSource(config))
suspend fun <T> query(transaction: Transaction.() -> T) =
withContext(dispatcher) {
transaction(db = connection, statement = transaction)
}
}
interface DatabaseConnectionProvider {
suspend fun <T> query(transaction: (Transaction.() -> T)): T
}
object DatabaseTest : DatabaseConnectionProvider {
val config = HikariConfig().apply {
driverClassName = "org.postgresql.Driver"
jdbcUrl = "jdbc:<postgresql://localhost:5432/exposed>"
username = "exposed"
password = "exposed"
maximumPoolSize = 3
isAutoCommit = false
transactionIsolation = "TRANSACTION_REPEATABLE_READ"
}
private val connection: DatabaseConnection = DatabaseConnection(config)
override suspend fun <T> query(transaction: (Transaction.() -> T)) = connection.query(transaction)
}
object Peeps : IntIdTable("peeps") {
data class Peep(val name: String, val role: String)
val name = text("name")
val role = text("role")
fun toPeep(row: ResultRow): Peep = Peep(
row[Peeps.name],
row[Peeps.role]
)
}
suspend fun main() {
DatabaseTest.query {
Peeps.selectAll().orderBy(Peeps.id).map { Peeps.toPeep(it) }.forEach { println("${it.name} - ${it.role}") }
}
}
import io.kotlintest.specs.DescribeSpec
import io.mockk.*
import kotlinx.coroutines.runBlocking
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.statements.InsertSelectStatement
class MainTests: DescribeSpec({
describe("test migrateDatabase") {
it("") {
coEvery {
DatabaseTest.query(any<Transaction.() -> Unit>())
} returns mockk()
runBlocking {
DatabaseTest.query {
Peeps.selectAll().map { Peeps.toPeep(it) }.forEach { println(it.name) }
}
}
coVerify {
DatabaseTest.query { any<InsertSelectStatement>() }
}
}
}
})