|
| 1 | +/* |
| 2 | + * Copyright 2002-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.context.annotation |
| 18 | + |
| 19 | +import org.junit.Assert.assertEquals |
| 20 | +import org.junit.Test |
| 21 | +import org.springframework.beans.factory.getBean |
| 22 | +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException |
| 23 | + |
| 24 | +class KotlinConfigurationClassTests { |
| 25 | + |
| 26 | + @Test(expected = BeanDefinitionParsingException::class) |
| 27 | + fun `Final configuration with default proxyBeanMethods value`() { |
| 28 | + AnnotationConfigApplicationContext(FinalConfigurationWithProxy::class.java) |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + fun `Final configuration with proxyBeanMethods set to false`() { |
| 33 | + val context = AnnotationConfigApplicationContext(FinalConfigurationWithoutProxy::class.java) |
| 34 | + val foo = context.getBean<Foo>() |
| 35 | + assertEquals(foo, context.getBean<Bar>().foo) |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + @Configuration |
| 40 | + class FinalConfigurationWithProxy { |
| 41 | + |
| 42 | + @Bean |
| 43 | + fun foo() = Foo() |
| 44 | + |
| 45 | + @Bean |
| 46 | + fun bar(foo: Foo) = Bar(foo) |
| 47 | + } |
| 48 | + |
| 49 | + @Configuration(proxyBeanMethods = false) |
| 50 | + class FinalConfigurationWithoutProxy { |
| 51 | + |
| 52 | + @Bean |
| 53 | + fun foo() = Foo() |
| 54 | + |
| 55 | + @Bean |
| 56 | + fun bar(foo: Foo) = Bar(foo) |
| 57 | + } |
| 58 | + |
| 59 | + class Foo |
| 60 | + |
| 61 | + class Bar(val foo: Foo) |
| 62 | +} |
0 commit comments