|
| 1 | +package org.sdkotlin.springdemo |
| 2 | + |
| 3 | +import org.assertj.core.api.Assertions.assertThat |
| 4 | +import org.assertj.core.api.Assertions.assertThatNoException |
| 5 | +import org.junit.jupiter.api.Disabled |
| 6 | +import org.junit.jupiter.api.Test |
| 7 | +import org.springframework.beans.factory.BeanFactory |
| 8 | +import org.springframework.beans.factory.annotation.Autowired |
| 9 | +import org.springframework.beans.factory.getBean |
| 10 | +import org.springframework.boot.test.context.SpringBootTest |
| 11 | +import org.springframework.context.ApplicationContext |
| 12 | +import org.springframework.context.annotation.Bean |
| 13 | +import org.springframework.context.annotation.Configuration |
| 14 | +import org.springframework.core.ParameterizedTypeReference |
| 15 | +import org.springframework.core.ResolvableType |
| 16 | + |
| 17 | +/** |
| 18 | + * Test case for |
| 19 | + * [spring-projects/spring-framework#31439](https://github.com/spring-projects/spring-framework/issues/31439). |
| 20 | + * |
| 21 | + * Passes with: |
| 22 | + * |
| 23 | + * ```kotlin |
| 24 | + * inline fun <reified T : Any> BeanFactory.getBean(): T = |
| 25 | + * getBeanProvider<T>( |
| 26 | + * ResolvableType.forType( |
| 27 | + * (object : ParameterizedTypeReference<T>() {}).type |
| 28 | + * ) |
| 29 | + * ).`object` |
| 30 | + * ``` |
| 31 | + */ |
| 32 | +@SpringBootTest |
| 33 | +internal class SpringGetBeanNestedGenericIT { |
| 34 | + |
| 35 | + companion object { |
| 36 | + |
| 37 | + val LIST_OF_STRING: List<String> = |
| 38 | + listOf("Testing") |
| 39 | + |
| 40 | + val LIST_OF_LIST_OF_STRING: List<List<String>> = |
| 41 | + listOf(listOf("Testing")) |
| 42 | + } |
| 43 | + |
| 44 | + @Configuration |
| 45 | + class TestConfig { |
| 46 | + |
| 47 | + @Bean |
| 48 | + fun listOfString(): List<String> = |
| 49 | + LIST_OF_STRING |
| 50 | + |
| 51 | + @Bean |
| 52 | + fun listOfListOfString(): List<List<String>> = |
| 53 | + LIST_OF_LIST_OF_STRING |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + @Disabled |
| 58 | + fun `test getBean with nested generic`( |
| 59 | + applicationContext: ApplicationContext |
| 60 | + ) { |
| 61 | + assertThatNoException().isThrownBy { |
| 62 | + |
| 63 | + applicationContext.getBean<List<String>>() |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + fun `test listOfString is injected`( |
| 69 | + @Autowired |
| 70 | + listOfString: List<String> |
| 71 | + ) { |
| 72 | + assertThat(listOfString).isEqualTo(LIST_OF_STRING) |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun `test listOfListOfString is injected`( |
| 77 | + @Autowired |
| 78 | + listOfListOfString: List<List<String>> |
| 79 | + ) { |
| 80 | + assertThat(listOfListOfString).isEqualTo(LIST_OF_LIST_OF_STRING) |
| 81 | + } |
| 82 | +} |
0 commit comments