Polishing
This commit is contained in:
parent
736bf1c502
commit
86580b2358
|
@ -4,8 +4,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
|
@ -16,43 +15,43 @@ import org.mockito.junit.MockitoJUnitRunner
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class BeanFactoryExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bf: BeanFactory
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bf: BeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBean with KClass`() {
|
||||
bf.getBean(Foo::class)
|
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBean with KClass`() {
|
||||
bf.getBean(Foo::class)
|
||||
verify(bf, times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters`() {
|
||||
bf.getBean<Foo>()
|
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBean with reified type parameters`() {
|
||||
bf.getBean<Foo>()
|
||||
verify(bf, times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with String and reified type parameters`() {
|
||||
val name = "foo"
|
||||
bf.getBean<Foo>(name)
|
||||
verify(bf, Mockito.times(1)).getBean(name, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBean with String and reified type parameters`() {
|
||||
val name = "foo"
|
||||
bf.getBean<Foo>(name)
|
||||
verify(bf, times(1)).getBean(name, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with KClass and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean(Foo::class, arg1, arg2)
|
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
@Test
|
||||
fun `getBean with KClass and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean(Foo::class, arg1, arg2)
|
||||
verify(bf, times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean<Foo>(arg1, arg2)
|
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
@Test
|
||||
fun `getBean with reified type parameters and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean<Foo>(arg1, arg2)
|
||||
verify(bf, times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
|
@ -13,122 +13,122 @@ import org.mockito.junit.MockitoJUnitRunner
|
|||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ListenableBeanFactoryExtensionsTests {
|
||||
class ListableBeanFactoryExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var lbf: ListableBeanFactory
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var lbf: ListableBeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass`() {
|
||||
lbf.getBeanNamesForType(Foo::class)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass`() {
|
||||
lbf.getBeanNamesForType(Foo::class)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters`() {
|
||||
lbf.getBeanNamesForType<Foo>()
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters`() {
|
||||
lbf.getBeanNamesForType<Foo>()
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass`() {
|
||||
lbf.getBeansOfType(Foo::class)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with KClass`() {
|
||||
lbf.getBeansOfType(Foo::class)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with KClass and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters`() {
|
||||
lbf.getBeansOfType<Foo>()
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters`() {
|
||||
lbf.getBeansOfType<Foo>()
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false, false)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with KClass`() {
|
||||
lbf.getBeanNamesForAnnotation(Bar::class)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with KClass`() {
|
||||
lbf.getBeanNamesForAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with reified type parameters`() {
|
||||
lbf.getBeanNamesForAnnotation<Bar>()
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with reified type parameters`() {
|
||||
lbf.getBeanNamesForAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with KClass`() {
|
||||
lbf.getBeansWithAnnotation(Bar::class)
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with KClass`() {
|
||||
lbf.getBeansWithAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with reified type parameters`() {
|
||||
lbf.getBeansWithAnnotation<Bar>()
|
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with reified type parameters`() {
|
||||
lbf.getBeansWithAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and KClass`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean(name, Bar::class)
|
||||
Mockito.verify(lbf, Mockito.times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and KClass`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean(name, Bar::class)
|
||||
verify(lbf, times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and reified type parameters`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean<Bar>(name)
|
||||
Mockito.verify(lbf, Mockito.times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and reified type parameters`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean<Bar>(name)
|
||||
verify(lbf, times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
|
||||
annotation class Bar
|
||||
annotation class Bar
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class KotlinAutowiredTests {
|
|||
bpp.setBeanFactory(bf)
|
||||
bf.addBeanPostProcessor(bpp)
|
||||
var bd = RootBeanDefinition(KotlinBean::class.java)
|
||||
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE)
|
||||
bd.scope = RootBeanDefinition.SCOPE_PROTOTYPE
|
||||
bf.registerBeanDefinition("annotatedBean", bd)
|
||||
var tb = TestBean()
|
||||
bf.registerSingleton("testBean", tb)
|
||||
|
@ -56,7 +56,7 @@ class KotlinAutowiredTests {
|
|||
bpp.setBeanFactory(bf)
|
||||
bf.addBeanPostProcessor(bpp)
|
||||
var bd = RootBeanDefinition(KotlinBean::class.java)
|
||||
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE)
|
||||
bd.scope = RootBeanDefinition.SCOPE_PROTOTYPE
|
||||
bf.registerBeanDefinition("annotatedBean", bd)
|
||||
|
||||
var kb = bf.getBean("annotatedBean", KotlinBean::class.java)
|
||||
|
|
|
@ -12,15 +12,15 @@ import org.springframework.context.support.registerBean
|
|||
*/
|
||||
class AnnotationConfigApplicationContextExtensionsTests {
|
||||
|
||||
@Test
|
||||
fun `Instantiate AnnotationConfigApplicationContext`() {
|
||||
val applicationContext = AnnotationConfigApplicationContext {
|
||||
registerBean<Foo>()
|
||||
}
|
||||
applicationContext.refresh()
|
||||
assertNotNull(applicationContext)
|
||||
assertNotNull(applicationContext.getBean<Foo>())
|
||||
}
|
||||
@Test
|
||||
fun `Instantiate AnnotationConfigApplicationContext`() {
|
||||
val applicationContext = AnnotationConfigApplicationContext {
|
||||
registerBean<Foo>()
|
||||
}
|
||||
applicationContext.refresh()
|
||||
assertNotNull(applicationContext)
|
||||
assertNotNull(applicationContext.getBean<Foo>())
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.http.HttpEntity
|
||||
import org.springframework.http.HttpMethod
|
||||
|
@ -21,134 +20,133 @@ import java.net.URI
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class RestOperationsExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var template: RestOperations
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var template: RestOperations
|
||||
|
||||
@Test
|
||||
fun `getForObject with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForObject<Foo>(url, var1, var2)
|
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java, var1, var2)
|
||||
}
|
||||
@Test
|
||||
fun `getForObject with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForObject<Foo>(url, var1, var2)
|
||||
verify(template, times(1)).getForObject(url, Foo::class.java, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForObject with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.getForObject<Foo>(url, vars)
|
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java, vars)
|
||||
}
|
||||
@Test
|
||||
fun `getForObject with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.getForObject<Foo>(url, vars)
|
||||
verify(template, times(1)).getForObject(url, Foo::class.java, vars)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForObject with reified type parameters and URI`() {
|
||||
val url = URI("https://spring.io")
|
||||
template.getForObject<Foo>(url)
|
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `getForObject with reified type parameters and URI`() {
|
||||
val url = URI("https://spring.io")
|
||||
template.getForObject<Foo>(url)
|
||||
verify(template, times(1)).getForObject(url, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForEntity with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForEntity<Foo>(url, var1, var2)
|
||||
verify(template, Mockito.times(1)).getForEntity(url, Foo::class.java, var1, var2)
|
||||
}
|
||||
@Test
|
||||
fun `getForEntity with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForEntity<Foo>(url, var1, var2)
|
||||
verify(template, times(1)).getForEntity(url, Foo::class.java, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForObject with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForObject<Foo>(url, body, var1, var2)
|
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java, var1, var2)
|
||||
}
|
||||
@Test
|
||||
fun `postForObject with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForObject<Foo>(url, body, var1, var2)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForObject with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForObject<Foo>(url, body, vars)
|
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java, vars)
|
||||
}
|
||||
@Test
|
||||
fun `postForObject with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForObject<Foo>(url, body, vars)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java, vars)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForObject with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForObject<Foo>(url, body)
|
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `postForObject with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForObject<Foo>(url, body)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForEntity<Foo>(url, body, var1, var2)
|
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java, var1, var2)
|
||||
}
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters, String and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForEntity<Foo>(url, body, var1, var2)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForEntity<Foo>(url, body, vars)
|
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java, vars)
|
||||
}
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters, String and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForEntity<Foo>(url, body, vars)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java, vars)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForEntity<Foo>(url, body)
|
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForEntity<Foo>(url, body)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.exchange<Foo>(url, method, entity, var1, var2)
|
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java, var1, var2)
|
||||
}
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and varargs`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.exchange<Foo>(url, method, entity, var1, var2)
|
||||
verify(template, times(1)).exchange(url, method, entity, Foo::class.java, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.exchange<Foo>(url, method, entity, vars)
|
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java, vars)
|
||||
}
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and Map`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.exchange<Foo>(url, method, entity, vars)
|
||||
verify(template, times(1)).exchange(url, method, entity, Foo::class.java, vars)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
template.exchange<Foo>(url, method, entity)
|
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
template.exchange<Foo>(url, method, entity)
|
||||
verify(template, times(1)).exchange(url, method, entity, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpEntity`() {
|
||||
val url = "https://spring.io"
|
||||
val entity = mock<RequestEntity<Foo>>()
|
||||
template.exchange<Foo>(entity)
|
||||
verify(template, Mockito.times(1)).exchange(entity, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpEntity`() {
|
||||
val entity = mock<RequestEntity<Foo>>()
|
||||
template.exchange<Foo>(entity)
|
||||
verify(template, times(1)).exchange(entity, Foo::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
|
||||
}
|
||||
|
|
|
@ -32,187 +32,187 @@ import org.springframework.web.multipart.support.MissingServletRequestPartExcept
|
|||
*/
|
||||
class RequestParamMethodArgumentResolverKotlinTests {
|
||||
|
||||
lateinit var resolver: RequestParamMethodArgumentResolver
|
||||
lateinit var webRequest: NativeWebRequest
|
||||
lateinit var binderFactory: WebDataBinderFactory
|
||||
lateinit var request: MockHttpServletRequest
|
||||
lateinit var resolver: RequestParamMethodArgumentResolver
|
||||
lateinit var webRequest: NativeWebRequest
|
||||
lateinit var binderFactory: WebDataBinderFactory
|
||||
lateinit var request: MockHttpServletRequest
|
||||
|
||||
lateinit var nullableParamRequired: MethodParameter
|
||||
lateinit var nullableParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableParamRequired: MethodParameter
|
||||
lateinit var nonNullableParamNotRequired: MethodParameter
|
||||
lateinit var nullableParamRequired: MethodParameter
|
||||
lateinit var nullableParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableParamRequired: MethodParameter
|
||||
lateinit var nonNullableParamNotRequired: MethodParameter
|
||||
|
||||
lateinit var nullableMultipartParamRequired: MethodParameter
|
||||
lateinit var nullableMultipartParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableMultipartParamRequired: MethodParameter
|
||||
lateinit var nonNullableMultipartParamNotRequired: MethodParameter
|
||||
lateinit var nullableMultipartParamRequired: MethodParameter
|
||||
lateinit var nullableMultipartParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableMultipartParamRequired: MethodParameter
|
||||
lateinit var nonNullableMultipartParamNotRequired: MethodParameter
|
||||
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
resolver = RequestParamMethodArgumentResolver(null, true)
|
||||
request = MockHttpServletRequest()
|
||||
val initializer = ConfigurableWebBindingInitializer()
|
||||
initializer.conversionService = DefaultConversionService()
|
||||
binderFactory = DefaultDataBinderFactory(initializer)
|
||||
webRequest = ServletWebRequest(request, MockHttpServletResponse())
|
||||
@Before
|
||||
fun setup() {
|
||||
resolver = RequestParamMethodArgumentResolver(null, true)
|
||||
request = MockHttpServletRequest()
|
||||
val initializer = ConfigurableWebBindingInitializer()
|
||||
initializer.conversionService = DefaultConversionService()
|
||||
binderFactory = DefaultDataBinderFactory(initializer)
|
||||
webRequest = ServletWebRequest(request, MockHttpServletResponse())
|
||||
|
||||
val method = ReflectionUtils.findMethod(javaClass, "handle", String::class.java,
|
||||
String::class.java, String::class.java, String::class.java,
|
||||
MultipartFile::class.java, MultipartFile::class.java,
|
||||
MultipartFile::class.java, MultipartFile::class.java)
|
||||
val method = ReflectionUtils.findMethod(javaClass, "handle", String::class.java,
|
||||
String::class.java, String::class.java, String::class.java,
|
||||
MultipartFile::class.java, MultipartFile::class.java,
|
||||
MultipartFile::class.java, MultipartFile::class.java)
|
||||
|
||||
nullableParamRequired = SynthesizingMethodParameter(method, 0)
|
||||
nullableParamNotRequired = SynthesizingMethodParameter(method, 1)
|
||||
nonNullableParamRequired = SynthesizingMethodParameter(method, 2)
|
||||
nonNullableParamNotRequired = SynthesizingMethodParameter(method, 3)
|
||||
nullableParamRequired = SynthesizingMethodParameter(method, 0)
|
||||
nullableParamNotRequired = SynthesizingMethodParameter(method, 1)
|
||||
nonNullableParamRequired = SynthesizingMethodParameter(method, 2)
|
||||
nonNullableParamNotRequired = SynthesizingMethodParameter(method, 3)
|
||||
|
||||
nullableMultipartParamRequired = SynthesizingMethodParameter(method, 4)
|
||||
nullableMultipartParamNotRequired = SynthesizingMethodParameter(method, 5)
|
||||
nonNullableMultipartParamRequired = SynthesizingMethodParameter(method, 6)
|
||||
nonNullableMultipartParamNotRequired = SynthesizingMethodParameter(method, 7)
|
||||
}
|
||||
nullableMultipartParamRequired = SynthesizingMethodParameter(method, 4)
|
||||
nullableMultipartParamNotRequired = SynthesizingMethodParameter(method, 5)
|
||||
nonNullableMultipartParamRequired = SynthesizingMethodParameter(method, 6)
|
||||
nonNullableMultipartParamNotRequired = SynthesizingMethodParameter(method, 7)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nullableParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nullableParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutParameter() {
|
||||
var result = resolver.resolveArgument(nullableParamRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutParameter() {
|
||||
var result = resolver.resolveArgument(nullableParamRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutParameter() {
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutParameter() {
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
|
||||
@Test(expected = MissingServletRequestParameterException::class)
|
||||
fun resolveNonNullableRequiredWithoutParameter() {
|
||||
resolver.resolveArgument(nonNullableParamRequired, null, webRequest, binderFactory)
|
||||
}
|
||||
@Test(expected = MissingServletRequestParameterException::class)
|
||||
fun resolveNonNullableRequiredWithoutParameter() {
|
||||
resolver.resolveArgument(nonNullableParamRequired, null, webRequest, binderFactory)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithParameter() {
|
||||
request.addParameter("name", "123")
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals("123", result)
|
||||
}
|
||||
|
||||
@Test(expected = TypeCastException::class)
|
||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||
resolver.resolveArgument(nonNullableParamNotRequired, null, webRequest, binderFactory) as String
|
||||
}
|
||||
@Test(expected = TypeCastException::class)
|
||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||
resolver.resolveArgument(nonNullableParamNotRequired, null, webRequest, binderFactory) as String
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
@Test
|
||||
fun resolveNullableRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
|
||||
var result = resolver.resolveArgument(nullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
|
||||
var result = resolver.resolveArgument(nullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
|
||||
var result = resolver.resolveArgument(nullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
|
||||
var result = resolver.resolveArgument(nullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
|
||||
var result = resolver.resolveArgument(nonNullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nonNullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test(expected = MissingServletRequestPartException::class)
|
||||
fun resolveNonNullableRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
resolver.resolveArgument(nonNullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
}
|
||||
@Test(expected = MissingServletRequestPartException::class)
|
||||
fun resolveNonNullableRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
resolver.resolveArgument(nonNullableMultipartParamRequired, null, webRequest, binderFactory)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithMultipartParameter() {
|
||||
val request = MockMultipartHttpServletRequest()
|
||||
val expected = MockMultipartFile("mfile", "Hello World".toByteArray())
|
||||
request.addFile(expected)
|
||||
webRequest = ServletWebRequest(request)
|
||||
|
||||
var result = resolver.resolveArgument(nonNullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
var result = resolver.resolveArgument(nonNullableMultipartParamNotRequired, null, webRequest, binderFactory)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test(expected = TypeCastException::class)
|
||||
fun resolveNonNullableNotRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
resolver.resolveArgument(nonNullableMultipartParamNotRequired, null, webRequest, binderFactory) as MultipartFile
|
||||
}
|
||||
@Test(expected = TypeCastException::class)
|
||||
fun resolveNonNullableNotRequiredWithoutMultipartParameter() {
|
||||
request.method = HttpMethod.POST.name
|
||||
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
resolver.resolveArgument(nonNullableMultipartParamNotRequired, null, webRequest, binderFactory) as MultipartFile
|
||||
}
|
||||
|
||||
|
||||
@Suppress("unused_parameter")
|
||||
fun handle(
|
||||
@RequestParam("name") nullableParamRequired: String?,
|
||||
@RequestParam("name", required = false) nullableParamNotRequired: String?,
|
||||
@RequestParam("name") nonNullableParamRequired: String,
|
||||
@RequestParam("name", required = false) nonNullableParamNotRequired: String,
|
||||
@Suppress("unused_parameter")
|
||||
fun handle(
|
||||
@RequestParam("name") nullableParamRequired: String?,
|
||||
@RequestParam("name", required = false) nullableParamNotRequired: String?,
|
||||
@RequestParam("name") nonNullableParamRequired: String,
|
||||
@RequestParam("name", required = false) nonNullableParamNotRequired: String,
|
||||
|
||||
@RequestParam("mfile") nullableMultipartParamRequired: MultipartFile?,
|
||||
@RequestParam("mfile", required = false) nullableMultipartParamNotRequired: MultipartFile?,
|
||||
@RequestParam("mfile") nonNullableMultipartParamRequired: MultipartFile,
|
||||
@RequestParam("mfile", required = false) nonNullableMultipartParamNotRequired: MultipartFile) {
|
||||
}
|
||||
@RequestParam("mfile") nullableMultipartParamRequired: MultipartFile?,
|
||||
@RequestParam("mfile", required = false) nullableMultipartParamNotRequired: MultipartFile?,
|
||||
@RequestParam("mfile") nonNullableMultipartParamRequired: MultipartFile,
|
||||
@RequestParam("mfile", required = false) nonNullableMultipartParamNotRequired: MultipartFile) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,25 +14,25 @@ import org.mockito.junit.MockitoJUnitRunner
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class BodyExtractorsExtensionsTests {
|
||||
|
||||
@Test
|
||||
fun `toMono with KClass`() {
|
||||
assertNotNull(toMono(Foo::class))
|
||||
}
|
||||
@Test
|
||||
fun `toMono with KClass`() {
|
||||
assertNotNull(toMono(Foo::class))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toMono with reified type parameter`() {
|
||||
assertNotNull(toMono<Foo>())
|
||||
}
|
||||
@Test
|
||||
fun `toMono with reified type parameter`() {
|
||||
assertNotNull(toMono<Foo>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toFlux with KClass`() {
|
||||
assertNotNull(toFlux(Foo::class))
|
||||
}
|
||||
@Test
|
||||
fun `toFlux with KClass`() {
|
||||
assertNotNull(toFlux(Foo::class))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toFlux with reified type parameter`() {
|
||||
assertNotNull(toFlux<Foo>())
|
||||
}
|
||||
@Test
|
||||
fun `toFlux with reified type parameter`() {
|
||||
assertNotNull(toFlux<Foo>())
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -16,17 +16,17 @@ import org.reactivestreams.Publisher
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class BodyInsertersExtensionsTests {
|
||||
|
||||
@Test
|
||||
fun `fromPublisher with reified type parameters`() {
|
||||
val publisher = mock<Publisher<Foo>>()
|
||||
assertNotNull(fromPublisher(publisher))
|
||||
}
|
||||
@Test
|
||||
fun `fromPublisher with reified type parameters`() {
|
||||
val publisher = mock<Publisher<Foo>>()
|
||||
assertNotNull(fromPublisher(publisher))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fromServerSentEvents with reified type parameters`() {
|
||||
val publisher = mock<Publisher<Foo>>()
|
||||
assertNotNull(fromServerSentEvents(publisher))
|
||||
}
|
||||
@Test
|
||||
fun `fromServerSentEvents with reified type parameters`() {
|
||||
val publisher = mock<Publisher<Foo>>()
|
||||
assertNotNull(fromServerSentEvents(publisher))
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
|
@ -16,32 +15,32 @@ import org.mockito.junit.MockitoJUnitRunner
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ClientResponseExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var response: ClientResponse
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var response: ClientResponse
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
response.bodyToMono(Foo::class)
|
||||
verify(response, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
response.bodyToMono(Foo::class)
|
||||
verify(response, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
response.bodyToMono<Foo>()
|
||||
verify(response, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
response.bodyToMono<Foo>()
|
||||
verify(response, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
response.bodyToFlux(Foo::class)
|
||||
verify(response, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
response.bodyToFlux(Foo::class)
|
||||
verify(response, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
response.bodyToFlux<Foo>()
|
||||
verify(response, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
response.bodyToFlux<Foo>()
|
||||
verify(response, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
|
||||
|
@ -18,67 +17,67 @@ import org.reactivestreams.Publisher
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class WebClientExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var requestBodySpec: WebClient.RequestBodySpec
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var requestBodySpec: WebClient.RequestBodySpec
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var responseSpec: WebClient.ResponseSpec
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var responseSpec: WebClient.ResponseSpec
|
||||
|
||||
|
||||
@Test
|
||||
fun `RequestBodySpec#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<Foo>>()
|
||||
requestBodySpec.body(body)
|
||||
verify(requestBodySpec, Mockito.times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `RequestBodySpec#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<Foo>>()
|
||||
requestBodySpec.body(body)
|
||||
verify(requestBodySpec, times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with KClass`() {
|
||||
responseSpec.bodyToMono(Foo::class)
|
||||
verify(responseSpec, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with KClass`() {
|
||||
responseSpec.bodyToMono(Foo::class)
|
||||
verify(responseSpec, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with reified type parameters`() {
|
||||
responseSpec.bodyToMono<Foo>()
|
||||
verify(responseSpec, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with reified type parameters`() {
|
||||
responseSpec.bodyToMono<Foo>()
|
||||
verify(responseSpec, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with KClass`() {
|
||||
responseSpec.bodyToFlux(Foo::class)
|
||||
verify(responseSpec, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with KClass`() {
|
||||
responseSpec.bodyToFlux(Foo::class)
|
||||
verify(responseSpec, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with reified type parameters`() {
|
||||
responseSpec.bodyToFlux<Foo>()
|
||||
verify(responseSpec, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with reified type parameters`() {
|
||||
responseSpec.bodyToFlux<Foo>()
|
||||
verify(responseSpec, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with KClass`() {
|
||||
responseSpec.toEntity(Foo::class)
|
||||
verify(responseSpec, Mockito.times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with KClass`() {
|
||||
responseSpec.toEntity(Foo::class)
|
||||
verify(responseSpec, times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with reified type parameters`() {
|
||||
responseSpec.toEntity<Foo>()
|
||||
verify(responseSpec, Mockito.times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with reified type parameters`() {
|
||||
responseSpec.toEntity<Foo>()
|
||||
verify(responseSpec, times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with KClass`() {
|
||||
responseSpec.toEntityList(Foo::class)
|
||||
verify(responseSpec, Mockito.times(1)).toEntityList(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with KClass`() {
|
||||
responseSpec.toEntityList(Foo::class)
|
||||
verify(responseSpec, times(1)).toEntityList(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with reified type parameters`() {
|
||||
responseSpec.toEntityList<Foo>()
|
||||
verify(responseSpec, Mockito.times(1)).toEntityList(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with reified type parameters`() {
|
||||
responseSpec.toEntityList<Foo>()
|
||||
verify(responseSpec, times(1)).toEntityList(Foo::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.web.reactive.function.server.ServerRequest
|
||||
import org.springframework.web.reactive.function.server.bodyToFlux
|
||||
|
@ -19,32 +18,32 @@ import org.springframework.web.reactive.function.server.bodyToMono
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ServerRequestExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var request: ServerRequest
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var request: ServerRequest
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
request.bodyToMono(Foo::class)
|
||||
verify(request, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
request.bodyToMono(Foo::class)
|
||||
verify(request, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
request.bodyToMono<Foo>()
|
||||
verify(request, Mockito.times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
request.bodyToMono<Foo>()
|
||||
verify(request, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
request.bodyToFlux(Foo::class)
|
||||
verify(request, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
request.bodyToFlux(Foo::class)
|
||||
verify(request, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
request.bodyToFlux<Foo>()
|
||||
verify(request, Mockito.times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
request.bodyToFlux<Foo>()
|
||||
verify(request, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
|
||||
|
@ -17,16 +17,16 @@ import org.reactivestreams.Publisher
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ServerResponseExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bodyBuilder: ServerResponse.BodyBuilder
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bodyBuilder: ServerResponse.BodyBuilder
|
||||
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<Foo>>()
|
||||
bodyBuilder.body(body)
|
||||
Mockito.verify(bodyBuilder, Mockito.times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
@Test
|
||||
fun `BodyBuilder#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<Foo>>()
|
||||
bodyBuilder.body(body)
|
||||
verify(bodyBuilder, times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo
|
||||
}
|
||||
|
|
|
@ -21,95 +21,95 @@ import reactor.test.StepVerifier
|
|||
*/
|
||||
class RequestParamMethodArgumentResolverKotlinTests {
|
||||
|
||||
lateinit var resolver: RequestParamMethodArgumentResolver
|
||||
lateinit var bindingContext: BindingContext
|
||||
lateinit var resolver: RequestParamMethodArgumentResolver
|
||||
lateinit var bindingContext: BindingContext
|
||||
|
||||
lateinit var nullableParamRequired: MethodParameter
|
||||
lateinit var nullableParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableParamRequired: MethodParameter
|
||||
lateinit var nonNullableParamNotRequired: MethodParameter
|
||||
lateinit var nullableParamRequired: MethodParameter
|
||||
lateinit var nullableParamNotRequired: MethodParameter
|
||||
lateinit var nonNullableParamRequired: MethodParameter
|
||||
lateinit var nonNullableParamNotRequired: MethodParameter
|
||||
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
this.resolver = RequestParamMethodArgumentResolver(null, ReactiveAdapterRegistry(), true)
|
||||
val initializer = ConfigurableWebBindingInitializer()
|
||||
initializer.conversionService = DefaultFormattingConversionService()
|
||||
bindingContext = BindingContext(initializer)
|
||||
@Before
|
||||
fun setup() {
|
||||
this.resolver = RequestParamMethodArgumentResolver(null, ReactiveAdapterRegistry(), true)
|
||||
val initializer = ConfigurableWebBindingInitializer()
|
||||
initializer.conversionService = DefaultFormattingConversionService()
|
||||
bindingContext = BindingContext(initializer)
|
||||
|
||||
val method = ReflectionUtils.findMethod(javaClass, "handle", String::class.java,
|
||||
String::class.java, String::class.java, String::class.java)
|
||||
val method = ReflectionUtils.findMethod(javaClass, "handle", String::class.java,
|
||||
String::class.java, String::class.java, String::class.java)
|
||||
|
||||
nullableParamRequired = SynthesizingMethodParameter(method, 0)
|
||||
nullableParamNotRequired = SynthesizingMethodParameter(method, 1)
|
||||
nonNullableParamRequired = SynthesizingMethodParameter(method, 2)
|
||||
nonNullableParamNotRequired = SynthesizingMethodParameter(method, 3)
|
||||
}
|
||||
nullableParamRequired = SynthesizingMethodParameter(method, 0)
|
||||
nullableParamNotRequired = SynthesizingMethodParameter(method, 1)
|
||||
nonNullableParamRequired = SynthesizingMethodParameter(method, 2)
|
||||
nonNullableParamNotRequired = SynthesizingMethodParameter(method, 3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectError(ServerWebInputException::class.java).verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectError(ServerWebInputException::class.java).verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
|
||||
@Suppress("unused_parameter")
|
||||
fun handle(
|
||||
@RequestParam("name") nullableParamRequired: String?,
|
||||
@RequestParam("name", required = false) nullableParamNotRequired: String?,
|
||||
@RequestParam("name") nonNullableParamRequired: String,
|
||||
@RequestParam("name", required = false) nonNullableParamNotRequired: String) {
|
||||
}
|
||||
@Suppress("unused_parameter")
|
||||
fun handle(
|
||||
@RequestParam("name") nullableParamRequired: String?,
|
||||
@RequestParam("name", required = false) nullableParamNotRequired: String?,
|
||||
@RequestParam("name") nonNullableParamRequired: String,
|
||||
@RequestParam("name", required = false) nonNullableParamNotRequired: String) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ package org.springframework.web.reactive.result.view.script
|
|||
import kotlin.script.templates.standard.ScriptTemplateWithBindings
|
||||
|
||||
fun ScriptTemplateWithBindings.include(path: String) =
|
||||
(bindings["include"] as (String) -> String).invoke(path)
|
||||
(bindings["include"] as (String) -> String).invoke(path)
|
||||
|
||||
|
||||
fun ScriptTemplateWithBindings.i18n(code: String) =
|
||||
(bindings["i18n"] as (String) -> String).invoke(code)
|
||||
(bindings["i18n"] as (String) -> String).invoke(code)
|
||||
|
||||
var ScriptTemplateWithBindings.foo: String
|
||||
get() = bindings["foo"] as String
|
||||
set(value) { throw UnsupportedOperationException()}
|
||||
get() = bindings["foo"] as String
|
||||
set(value) { throw UnsupportedOperationException() }
|
||||
|
|
|
@ -5,12 +5,12 @@ package org.springframework.web.reactive.result.view.script
|
|||
import kotlin.script.templates.standard.ScriptTemplateWithBindings
|
||||
|
||||
fun ScriptTemplateWithBindings.include(path: String) =
|
||||
(bindings["include"] as (String) -> String).invoke(path)
|
||||
(bindings["include"] as (String) -> String).invoke(path)
|
||||
|
||||
|
||||
fun ScriptTemplateWithBindings.i18n(code: String) =
|
||||
(bindings["i18n"] as (String) -> String).invoke(code)
|
||||
(bindings["i18n"] as (String) -> String).invoke(code)
|
||||
|
||||
var ScriptTemplateWithBindings.foo: String
|
||||
get() = bindings["foo"] as String
|
||||
set(value) { throw UnsupportedOperationException()}
|
||||
get() = bindings["foo"] as String
|
||||
set(value) { throw UnsupportedOperationException()}
|
||||
|
|
Loading…
Reference in New Issue