Browse Source
Prior to this commit constructor bound configuration properties could not be mocked because it would fail validation from ConfigurationPropertiesBeanDefinitionValidator. The MockitoPostProcessor registers the mocked bean as a singleton and validation can be skipped if a singleton for the type is found in the bean factory. Fixes gh-18652pull/18915/head
3 changed files with 64 additions and 2 deletions
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
package org.springframework.boot.context.properties |
||||
|
||||
import org.junit.jupiter.api.Test |
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry |
||||
import org.springframework.beans.factory.support.RootBeanDefinition |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext |
||||
import org.springframework.context.annotation.Configuration |
||||
|
||||
/** |
||||
* Tests for {@link ConfigurationProperties @ConfigurationProperties}-annotated beans. |
||||
* |
||||
* @author Madhura Bhave |
||||
*/ |
||||
class KotlinConfigurationPropertiesTests { |
||||
|
||||
private var context = AnnotationConfigApplicationContext() |
||||
|
||||
@Test //gh-18652 |
||||
fun `type with constructor binding and existing singleton should not fail`() { |
||||
val beanFactory = this.context.beanFactory |
||||
(beanFactory as BeanDefinitionRegistry).registerBeanDefinition("foo", |
||||
RootBeanDefinition(BingProperties::class.java)) |
||||
beanFactory.registerSingleton("foo", BingProperties("")) |
||||
this.context.register(TestConfig::class.java) |
||||
this.context.refresh(); |
||||
} |
||||
|
||||
@ConfigurationProperties(prefix = "foo") |
||||
@ConstructorBinding |
||||
class BingProperties(@Suppress("UNUSED_PARAMETER") bar: String) { |
||||
|
||||
} |
||||
|
||||
@Configuration(proxyBeanMethods = false) |
||||
@EnableConfigurationProperties |
||||
internal open class TestConfig { |
||||
|
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue