SpringApplicationExtensionsTests Class — spring-boot Architecture
Architecture documentation for the SpringApplicationExtensionsTests class in SpringApplicationExtensionsTests.kt from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt lines 33–120
class SpringApplicationExtensionsTests {
@Test
fun `Kotlin runApplication() top level function`() {
val context = runApplication<ExampleConfig>()
assertThat(context).isNotNull()
}
@Test
fun `Kotlin runApplication() top level function with a custom environment`() {
val environment = StandardEnvironment()
val context = runApplication<ExampleConfig> {
setEnvironment(environment)
}
assertThat(context).isNotNull()
assertThat(environment).isEqualTo(context.environment)
}
@Test
fun `Kotlin runApplication(arg1, arg2) top level function`() {
val context = runApplication<ExampleConfig>("--debug", "spring", "boot")
val args = context.getBean<ApplicationArguments>()
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
assertThat(args.containsOption("debug")).isTrue()
}
@Test
fun `Kotlin runApplication(arg1, arg2) top level function with a custom environment`() {
val environment = StandardEnvironment()
val context = runApplication<ExampleConfig>("--debug", "spring", "boot") {
setEnvironment(environment)
}
val args = context.getBean<ApplicationArguments>()
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
assertThat(args.containsOption("debug")).isTrue()
assertThat(environment).isEqualTo(context.environment)
}
@Test
fun `Kotlin fromApplication() top level function`() {
val context = fromApplication<TestKotlinApplication>().with(ExampleConfig::class).run().applicationContext
assertThat(context.getBean<ExampleBean>()).isNotNull()
}
@Test
fun `Kotlin fromApplication() top level function with multiple sources`() {
val context = fromApplication<TestKotlinApplication>()
.with(ExampleConfig::class, AnotherExampleConfig::class).run().applicationContext
assertThat(context.getBean<ExampleBean>()).isNotNull()
assertThat(context.getBean<AnotherExampleBean>()).isNotNull()
}
@Test
fun `Kotlin fromApplication() top level function when no main`() {
assertThatIllegalStateException().isThrownBy { fromApplication<ExampleConfig>().run() }
.withMessage("Unable to use 'fromApplication' with " +
"org.springframework.boot.SpringApplicationExtensionsTests.ExampleConfig")
}
@Configuration(proxyBeanMethods = false)
internal open class ExampleConfig {
@Bean
open fun exampleBean(): ExampleBean {
return ExampleBean()
}
}
@Configuration(proxyBeanMethods = false)
internal open class AnotherExampleConfig {
@Bean
open fun anotherExampleBean(): AnotherExampleBean {
return AnotherExampleBean()
}
}
class ExampleBean {
}
class AnotherExampleBean {
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free