Polishing

This commit is contained in:
Sebastien Deleuze
2017-06-09 01:49:56 +03:00
parent 736bf1c502
commit 86580b2358
16 changed files with 668 additions and 674 deletions

View File

@@ -35,123 +35,123 @@ import java.sql.*
@RunWith(MockitoJUnitRunner::class)
class JdbcOperationsExtensionsTests {
@Mock(answer = Answers.RETURNS_MOCKS)
lateinit var template: JdbcTemplate
@Mock(answer = Answers.RETURNS_MOCKS)
lateinit var template: JdbcTemplate
@Test
fun `queryForObject with KClass`() {
val sql = "select age from customer where id = 3"
val requiredType = Int::class
val sql = "select age from customer where id = 3"
val requiredType = Int::class
template.queryForObject(sql, requiredType)
verify(template, times(1)).queryForObject(sql, requiredType)
verify(template, times(1)).queryForObject(sql, requiredType)
}
@Test
fun `queryForObject with reified type parameters`() {
val sql = "select age from customer where id = 3"
val sql = "select age from customer where id = 3"
template.queryForObject<Int>(sql)
verify(template, times(1)).queryForObject(sql, Integer::class.java)
verify(template, times(1)).queryForObject(sql, Integer::class.java)
}
@Test
fun `queryForObject with RowMapper-like function`() {
val sql = "select age from customer where id = ?"
template.queryForObject(sql, 3) { rs: ResultSet, _: Int -> rs.getInt(1) }
verify(template, times(1)).queryForObject(eq(sql), any<RowMapper<Int>>(), eq(3))
template.queryForObject(sql, 3) { rs: ResultSet, _: Int -> rs.getInt(1) }
verify(template, times(1)).queryForObject(eq(sql), any<RowMapper<Int>>(), eq(3))
}
@Test
fun `queryForObject with argTypes`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
val requiredType = Int::class
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
val requiredType = Int::class
template.queryForObject(sql, args, argTypes, requiredType)
verify(template, times(1)).queryForObject(sql, args, argTypes, requiredType)
verify(template, times(1)).queryForObject(sql, args, argTypes, requiredType)
}
@Test
fun `queryForObject with reified type parameters and argTypes`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
template.queryForObject<Int>(sql, args, argTypes)
verify(template, times(1)).queryForObject(sql, args, argTypes, Integer::class.java)
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
template.queryForObject<Int>(sql, args, argTypes)
verify(template, times(1)).queryForObject(sql, args, argTypes, Integer::class.java)
}
@Test
fun `queryForObject with args`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
template.queryForObject(sql, args, Int::class)
verify(template, times(1)).queryForObject(sql, args, Int::class.java)
verify(template, times(1)).queryForObject(sql, args, Int::class.java)
}
@Test
fun `queryForObject with reified type parameters and args`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
template.queryForObject<Int>(sql, args)
verify(template, times(1)).queryForObject(sql, args, Integer::class.java)
verify(template, times(1)).queryForObject(sql, args, Integer::class.java)
}
@Test
fun `queryForObject with varargs`() {
val sql = "select age from customer where id = ?"
val sql = "select age from customer where id = ?"
template.queryForObject(sql, Int::class, 3)
verify(template, times(1)).queryForObject(sql, Int::class.java, 3)
verify(template, times(1)).queryForObject(sql, Int::class.java, 3)
}
@Test
fun `queryForList with reified type parameters`() {
val sql = "select age from customer where id = 3"
val sql = "select age from customer where id = 3"
template.queryForList<Int>(sql)
verify(template, times(1)).queryForList(sql, Integer::class.java)
verify(template, times(1)).queryForList(sql, Integer::class.java)
}
@Test
fun `queryForList with reified type parameters and argTypes`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
template.queryForList<Int>(sql, args, argTypes)
verify(template, times(1)).queryForList(sql, args, argTypes, Integer::class.java)
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
template.queryForList<Int>(sql, args, argTypes)
verify(template, times(1)).queryForList(sql, args, argTypes, Integer::class.java)
}
@Test
fun `queryForList with reified type parameters and args`() {
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
val sql = "select age from customer where id = ?"
val args = arrayOf(3)
template.queryForList<Int>(sql, args)
verify(template, times(1)).queryForList(sql, args, Integer::class.java)
verify(template, times(1)).queryForList(sql, args, Integer::class.java)
}
@Test
fun `query with ResultSetExtractor-like function`() {
val sql = "select age from customer where id = ?"
val sql = "select age from customer where id = ?"
template.query<Int>(sql, 3) { rs ->
rs.next()
rs.getInt(1)
}
verify(template, times(1)).query(eq(sql), any<ResultSetExtractor<Int>>(), eq(3))
verify(template, times(1)).query(eq(sql), any<ResultSetExtractor<Int>>(), eq(3))
}
@Test
fun `query with RowCallbackHandler-like function`() {
val sql = "select age from customer where id = ?"
val sql = "select age from customer where id = ?"
template.query(sql, 3) { rs ->
assertEquals(22, rs.getInt(1))
}
verify(template, times(1)).query(eq(sql), any<RowCallbackHandler>(), eq(3))
verify(template, times(1)).query(eq(sql), any<RowCallbackHandler>(), eq(3))
}
@Test
fun `query with RowMapper-like function`() {
val sql = "select age from customer where id = ?"
val sql = "select age from customer where id = ?"
template.query(sql, 3) { rs, _ ->
rs.getInt(1)
}
verify(template, times(1)).query(eq(sql), any<RowMapper<Int>>(), eq(3))
verify(template, times(1)).query(eq(sql), any<RowMapper<Int>>(), eq(3))
}
}