Migrate to AssertJ in Kotlin tests
Closes gh-23475
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.context.annotation
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.getBean
|
||||
import org.springframework.context.support.registerBean
|
||||
@@ -34,9 +34,9 @@ class AnnotationConfigApplicationContextExtensionsTests {
|
||||
val applicationContext = AnnotationConfigApplicationContext {
|
||||
registerBean<Foo>()
|
||||
}
|
||||
assertThat(applicationContext).isNotNull()
|
||||
applicationContext.refresh()
|
||||
assertNotNull(applicationContext)
|
||||
assertNotNull(applicationContext.getBean<Foo>())
|
||||
applicationContext.getBean<Foo>()
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.context.annotation
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.fail
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.getBean
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException
|
||||
@@ -26,12 +27,8 @@ class KotlinConfigurationClassTests {
|
||||
|
||||
@Test
|
||||
fun `Final configuration with default proxyBeanMethods value`() {
|
||||
try {
|
||||
assertThatExceptionOfType(BeanDefinitionParsingException::class.java).isThrownBy {
|
||||
AnnotationConfigApplicationContext(FinalConfigurationWithProxy::class.java)
|
||||
fail("should have thrown a BeanDefinitionParsingException")
|
||||
}
|
||||
catch (e: BeanDefinitionParsingException) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +36,7 @@ class KotlinConfigurationClassTests {
|
||||
fun `Final configuration with proxyBeanMethods set to false`() {
|
||||
val context = AnnotationConfigApplicationContext(FinalConfigurationWithoutProxy::class.java)
|
||||
val foo = context.getBean<Foo>()
|
||||
assertEquals(foo, context.getBean<Bar>().foo)
|
||||
assertThat(context.getBean<Bar>().foo).isEqualTo(foo)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.context.annotation
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.BeanFactory
|
||||
import org.springframework.beans.factory.getBean
|
||||
@@ -39,11 +39,11 @@ class Spr16022Tests {
|
||||
|
||||
private fun assert(context: BeanFactory) {
|
||||
val bean1 = context.getBean<MultipleConstructorsTestBean>("bean1")
|
||||
assertEquals(0, bean1.foo)
|
||||
assertThat(bean1.foo).isEqualTo(0)
|
||||
val bean2 = context.getBean<MultipleConstructorsTestBean>("bean2")
|
||||
assertEquals(1, bean2.foo)
|
||||
assertThat(bean2.foo).isEqualTo(1)
|
||||
val bean3 = context.getBean<MultipleConstructorsTestBean>("bean3")
|
||||
assertEquals(3, bean3.foo)
|
||||
assertThat(bean3.foo).isEqualTo(3)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.context.support
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||
@@ -45,10 +44,10 @@ class BeanDefinitionDslTests {
|
||||
refresh()
|
||||
}
|
||||
|
||||
assertNotNull(context.getBean<Foo>())
|
||||
assertNotNull(context.getBean<Bar>("bar"))
|
||||
assertTrue(context.isPrototype("bar"))
|
||||
assertNotNull(context.getBean<Baz>())
|
||||
context.getBean<Foo>()
|
||||
context.getBean<Bar>("bar")
|
||||
assertThat(context.isPrototype("bar")).isTrue()
|
||||
context.getBean<Baz>()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,13 +71,9 @@ class BeanDefinitionDslTests {
|
||||
refresh()
|
||||
}
|
||||
|
||||
assertNotNull(context.getBean<Foo>())
|
||||
assertNotNull(context.getBean<Bar>("bar"))
|
||||
try {
|
||||
context.getBean<Baz>()
|
||||
fail("Expect NoSuchBeanDefinitionException to be thrown")
|
||||
}
|
||||
catch(ex: NoSuchBeanDefinitionException) { null }
|
||||
context.getBean<Foo>()
|
||||
context.getBean<Bar>("bar")
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException::class.java).isThrownBy { context.getBean<Baz>() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,14 +95,10 @@ class BeanDefinitionDslTests {
|
||||
refresh()
|
||||
}
|
||||
|
||||
assertNotNull(context.getBean<Foo>())
|
||||
assertNotNull(context.getBean<Bar>("bar"))
|
||||
assertEquals("foofoo", context.getBean<FooFoo>().name)
|
||||
try {
|
||||
context.getBean<Baz>()
|
||||
fail("Expect NoSuchBeanDefinitionException to be thrown")
|
||||
}
|
||||
catch(ex: NoSuchBeanDefinitionException) { null }
|
||||
context.getBean<Foo>()
|
||||
context.getBean<Bar>("bar")
|
||||
assertThat(context.getBean<FooFoo>().name).isEqualTo("foofoo")
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException::class.java).isThrownBy { context.getBean<Baz>() }
|
||||
}
|
||||
|
||||
@Test // SPR-16412
|
||||
@@ -126,7 +117,7 @@ class BeanDefinitionDslTests {
|
||||
}
|
||||
|
||||
for (i in 1..5) {
|
||||
assertNotNull(context.getBean("string$i"))
|
||||
context.getBean("string$i")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +135,7 @@ class BeanDefinitionDslTests {
|
||||
}
|
||||
|
||||
val barbar = context.getBean<BarBar>()
|
||||
assertEquals(2, barbar.foos.size)
|
||||
assertThat(barbar.foos.size).isEqualTo(2)
|
||||
}
|
||||
|
||||
@Test // SPR-17292
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.context.support
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.getBean
|
||||
|
||||
@@ -32,7 +31,7 @@ class GenericApplicationContextExtensionsTests {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean<BeanA>()
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
context.getBean<BeanA>()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,7 +39,7 @@ class GenericApplicationContextExtensionsTests {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean<BeanA>("a")
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
context.getBean("a")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,7 +47,7 @@ class GenericApplicationContextExtensionsTests {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean { BeanA() }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
context.getBean<BeanA>()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,7 +55,7 @@ class GenericApplicationContextExtensionsTests {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean("a") { BeanA() }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
context.getBean("a")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,8 +64,8 @@ class GenericApplicationContextExtensionsTests {
|
||||
context.registerBean<BeanA>()
|
||||
context.registerBean { BeanB(it.getBean<BeanA>()) }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
assertNotNull(context.getBean<BeanB>())
|
||||
context.getBean<BeanA>()
|
||||
context.getBean<BeanB>()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,8 +74,8 @@ class GenericApplicationContextExtensionsTests {
|
||||
context.registerBean<BeanA>("a")
|
||||
context.registerBean("b") { BeanB(it.getBean<BeanA>()) }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
assertNotNull(context.getBean("b"))
|
||||
context.getBean("a")
|
||||
context.getBean("b")
|
||||
}
|
||||
|
||||
class BeanA
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.ui
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,7 @@ class ModelExtensionsTests {
|
||||
fun setAttribute() {
|
||||
val model:Model = ConcurrentModel()
|
||||
model["foo"] = "bing"
|
||||
assertTrue(model.containsAttribute("foo"))
|
||||
assertEquals("bing", model.asMap()["foo"])
|
||||
assertThat(model.containsAttribute("foo")).isTrue()
|
||||
assertThat(model.asMap()["foo"]).isEqualTo("bing")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.ui
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
@@ -31,8 +30,8 @@ class ModelMapExtensionsTests {
|
||||
fun setAttribute() {
|
||||
val model = ModelMap()
|
||||
model["foo"] = "bing"
|
||||
assertTrue(model.containsAttribute("foo"))
|
||||
assertEquals("bing", model["foo"])
|
||||
assertThat(model.containsAttribute("foo"))
|
||||
assertThat(model["foo"]).isEqualTo("bing")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user