Browse Source

Fix ListableBeanFactory#findAnnotationOnBean extension return type

Closes gh-26908
pull/27953/head
danthonywalker 4 years ago committed by Sébastien Deleuze
parent
commit
50771237cc
  1. 2
      spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensions.kt
  2. 6
      spring-beans/src/test/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensionsTests.kt

2
spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensions.kt

@ -64,6 +64,6 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation() @@ -64,6 +64,6 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation()
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String): Annotation? =
inline fun <reified T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String): T? =
findAnnotationOnBean(beanName, T::class.java)

6
spring-beans/src/test/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtensionsTests.kt

@ -16,9 +16,11 @@ @@ -16,9 +16,11 @@
package org.springframework.beans.factory
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
import kotlin.reflect.full.createInstance
/**
* Mock object based tests for ListableBeanFactory Kotlin extensions
@ -77,10 +79,12 @@ class ListableBeanFactoryExtensionsTests { @@ -77,10 +79,12 @@ class ListableBeanFactoryExtensionsTests {
verify { lbf.getBeansWithAnnotation(Bar::class.java) }
}
@Suppress("UNUSED_VARIABLE")
@Test
fun `findAnnotationOnBean with String and reified type parameters`() {
val name = "bar"
lbf.findAnnotationOnBean<Bar>(name)
every { lbf.findAnnotationOnBean(name, Bar::class.java) } returns Bar::class.createInstance()
val annotation: Bar? = lbf.findAnnotationOnBean(name)
verify { lbf.findAnnotationOnBean(name, Bar::class.java) }
}

Loading…
Cancel
Save