Skip to content

Improve BeanFactoryExtensionsTests #34696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,13 +19,15 @@ package org.springframework.beans.factory
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.core.ResolvableType

/**
* Mock object based tests for BeanFactory Kotlin extensions.
*
* @author Sebastien Deleuze
* @author Yanming Zhou
*/
class BeanFactoryExtensionsTests {

Expand All @@ -35,10 +37,18 @@ class BeanFactoryExtensionsTests {
fun `getBean with reified type parameters`() {
val foo = Foo()
every { bf.getBeanProvider<Foo>(ofType<ResolvableType>()).getObject() } returns foo
bf.getBean<Foo>()
assertThat(bf.getBean<Foo>()).isSameAs(foo)
verify { bf.getBeanProvider<ObjectProvider<Foo>>(ofType<ResolvableType>()).getObject() }
}

@Test
fun `getBean with reified generic type parameters`() {
val foo = listOf(Foo())
every { bf.getBeanProvider<List<Foo>>(ofType<ResolvableType>()).getObject() } returns foo
assertThat(bf.getBean<List<Foo>>()).isSameAs(foo)
verify { bf.getBeanProvider<ObjectProvider<List<Foo>>>(ofType<ResolvableType>()).getObject() }
}

@Test
fun `getBean with String and reified type parameters`() {
val name = "foo"
Expand All @@ -52,7 +62,7 @@ class BeanFactoryExtensionsTests {
val arg2 = "arg2"
val bar = Bar(arg1, arg2)
every { bf.getBeanProvider<Bar>(ofType<ResolvableType>()).getObject(arg1, arg2) } returns bar
bf.getBean<Bar>(arg1, arg2)
assertThat(bf.getBean<Bar>(arg1, arg2)).isSameAs(bar)
verify { bf.getBeanProvider<Bar>(ofType<ResolvableType>()).getObject(arg1, arg2) }
}

Expand Down