Skip to content

Commit

Permalink
chore: upgrade to Spring Boot 3.2.2, Kotlin 1.9.22
Browse files Browse the repository at this point in the history
This upgrade includes
some changes of the test codes
which corresponds to significant changes
that have been made in Spring Boot 3.2.

mybatis project encountered the same issue,
so its pr helped a lot making this upgrade done.
The brief explanations are:

1. As of Spring Framework 6.1, we can't pass the value of `factoryBeanObjectType` as `String` to `BeanDefinition`.
2. `BeanFactory.getBean()` in `BeanFactoryExtensions` has been changed.

Good thing is, the changes above
don't seem to affact the implementations.
All we need to do is to correct the test code.

For the details, please check the references below.

## Reference

* mybatis pr: mybatis/spring#865
* as-is 1: https://github.com/spring-projects/spring-framework/blob/66f4509c2c7a1ad0255ed84f9e5efb340bd0b470/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java#L74-L83
* to-be 1: https://github.com/spring-projects/spring-framework/blob/00577ed80acfc22104b41d6a631f433a3fa7e6af/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java#L74-L87
* as-is 2: https://github.com/spring-projects/spring-framework/blob/66f4509c2c7a1ad0255ed84f9e5efb340bd0b470/spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtensions.kt#L28
* to-be 2: https://github.com/spring-projects/spring-framework/blob/00577ed80acfc22104b41d6a631f433a3fa7e6af/spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtensions.kt#L29-L30
  • Loading branch information
djkeh committed Feb 1, 2024
1 parent dcbe643 commit 8345211
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import java.time.Duration

plugins {
// if it's changed, it must also be channged in the bomProperty below
val kotlinVersion = "1.7.21"
val kotlinVersion = "1.9.22"

`java-library`
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
kotlin("plugin.noarg") version kotlinVersion
`maven-publish`
signing
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
id("org.jetbrains.kotlin.plugin.noarg") version kotlinVersion
id("org.springframework.boot") version "3.0.0" apply false
id("io.spring.dependency-management") version "1.1.0"
id("org.springframework.boot") version "3.2.2" apply false
id("io.spring.dependency-management") version "1.1.4"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

Expand Down Expand Up @@ -89,7 +89,7 @@ afterEvaluate {
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) {
bomProperty("kotlin.version", "1.7.21")
bomProperty("kotlin.version", "1.9.22")
}
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ publishing {
repositories {
maven {
name = "build"
url = uri("$buildDir/repo")
url = uri("${layout.buildDirectory}/repo")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.ninjasquad.springmockk.example.RealExampleService
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalStateException
import org.junit.jupiter.api.Test
import org.springframework.beans.BeanWrapper
import org.springframework.beans.BeansException
import org.springframework.beans.factory.FactoryBean
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.config.BeanFactoryPostProcessor
Expand Down Expand Up @@ -67,7 +65,7 @@ class MockkPostProcessorTests {
val factoryBeanDefinition = RootBeanDefinition(TestFactoryBean::class.java)
factoryBeanDefinition.setAttribute(
FactoryBean.OBJECT_TYPE_ATTRIBUTE,
SomeInterface::class.java.name
SomeInterface::class.java
)
context.registerBeanDefinition("beanToBeMocked", factoryBeanDefinition)
context.register(MockedFactoryBean::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.mockk.impl.annotations.MockK
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.getBean
import org.springframework.context.ApplicationContext
import org.springframework.test.context.TestContext
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener
Expand Down Expand Up @@ -41,10 +40,9 @@ class MockkTestExecutionListenerTests {

@Test
fun prepareTestInstanceShouldInjectMockBean() {
every { applicationContext.getBean<MockkPostProcessor>() } returns this.postProcessor
every { applicationContext.getBean(MockkPostProcessor::class.java) } returns this.postProcessor
val instance = WithMockkBean()
val testContext = mockTestContext(instance)
every { testContext.getApplicationContext() } returns this.applicationContext;
this.listener.prepareTestInstance(testContext)
verify {
postProcessor.inject(
Expand Down

0 comments on commit 8345211

Please sign in to comment.