I am trying to implement the same given below using MockK instead of Mockito. I am not able to mock the lambda function inside the JDBC template update() method class Repository(private val jdbcTemplate: JdbcTemplate) { createRule(emp: Employee): Int? { val insertRuleQuery: String = getAddEmployeeSqlString() val holder: KeyHolder = GeneratedKeyHolder() val row: Int = jdbcTemplate.update({ connection: Connection -> val ps = connection.prepareStatement(insertRuleQuery, arrayOf("EMP_ID")) ps.setLong(1, emp.batchId) ps.setString(2, emp.permanent) ps.setString(3, emp.groupId) ps }, holder) return row } class RepositoryTest { private val mockJT = Mockito.mock(JdbcTemplate::class.java) fun `jdbc test emp insert`() {
great presentation, explaining core features of mockk. Great work!!
Excellent presentation. Thank you
Useful to this day, thank you sir
Thanks!
How to spy final methods using mockk ? Every time i have to wrap it with an open method to spy a final method
Good one!
I am trying to implement the same given below using MockK instead of Mockito. I am not able to mock the lambda function inside the JDBC template update() method
class Repository(private val jdbcTemplate: JdbcTemplate) {
createRule(emp: Employee): Int? {
val insertRuleQuery: String = getAddEmployeeSqlString()
val holder: KeyHolder = GeneratedKeyHolder()
val row: Int = jdbcTemplate.update({ connection: Connection ->
val ps = connection.prepareStatement(insertRuleQuery, arrayOf("EMP_ID"))
ps.setLong(1, emp.batchId)
ps.setString(2, emp.permanent)
ps.setString(3, emp.groupId)
ps
}, holder)
return row
}
class RepositoryTest {
private val mockJT = Mockito.mock(JdbcTemplate::class.java)
fun `jdbc test emp insert`() {
Mockito.`when`(
mockJT.update(
Mockito.any(PreparedStatementCreator::class.java), Mockito.any(
KeyHolder::class.java
)
)
).thenReturn(1)
assertEquals(count, 1)
}