Skip to content

Commit 1c1a0af

Browse files
izeyesbrannen
authored andcommitted
Use AssertJ static imports consistently in 5.3.x
Closes gh-29282
1 parent a599601 commit 1c1a0af

File tree

10 files changed

+104
-104
lines changed

10 files changed

+104
-104
lines changed

spring-core/src/test/java/org/springframework/core/CollectionFactoryTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,6 @@
3434
import java.util.TreeMap;
3535
import java.util.TreeSet;
3636

37-
import org.assertj.core.api.Assertions;
3837
import org.junit.jupiter.api.Test;
3938

4039
import org.springframework.util.LinkedMultiValueMap;
@@ -156,7 +155,7 @@ void createMapIsNotTypeSafeForLinkedMultiValueMap() {
156155
@Test
157156
void createApproximateCollectionFromEmptyHashSet() {
158157
Collection<String> set = createApproximateCollection(new HashSet<String>(), 2);
159-
Assertions.assertThat(set).isEmpty();
158+
assertThat(set).isEmpty();
160159
}
161160

162161
@Test

spring-core/src/test/kotlin/org/springframework/core/KotlinBridgeMethodResolverTests.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.core
1818

19-
import org.assertj.core.api.Assertions
19+
import org.assertj.core.api.Assertions.assertThat
2020
import org.junit.jupiter.api.Test
2121

2222
class KotlinBridgeMethodResolverTests {
@@ -25,22 +25,22 @@ class KotlinBridgeMethodResolverTests {
2525
fun findBridgedMethod() {
2626
val unbridged = GenericRepository::class.java.getDeclaredMethod("delete", Int::class.java)
2727
val bridged = GenericRepository::class.java.getDeclaredMethod("delete", Any::class.java)
28-
Assertions.assertThat(unbridged.isBridge).isFalse
29-
Assertions.assertThat(bridged.isBridge).isTrue
28+
assertThat(unbridged.isBridge).isFalse
29+
assertThat(bridged.isBridge).isTrue
3030

31-
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
32-
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
31+
assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
32+
assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
3333
}
3434

3535
@Test
3636
fun findBridgedMethodWithArrays() {
3737
val unbridged = GenericRepository::class.java.getDeclaredMethod("delete", Array<Int>::class.java)
3838
val bridged = GenericRepository::class.java.getDeclaredMethod("delete", Array<Any>::class.java)
39-
Assertions.assertThat(unbridged.isBridge).isFalse
40-
Assertions.assertThat(bridged.isBridge).isTrue
39+
assertThat(unbridged.isBridge).isFalse
40+
assertThat(bridged.isBridge).isTrue
4141

42-
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
43-
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
42+
assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
43+
assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
4444
}
4545
}
4646

spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/KotlinDataClassRowMapperTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors
2+
* Copyright 2002-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.jdbc.core
1818

19-
import org.assertj.core.api.Assertions
19+
import org.assertj.core.api.Assertions.assertThat
2020
import org.junit.jupiter.api.Test
2121
import org.springframework.jdbc.core.test.ConstructorPerson
2222
import java.math.BigDecimal
@@ -31,7 +31,7 @@ class KotlinDataClassRowMapperTests : AbstractRowMapperTests() {
3131
"select name, age, birth_date, balance from people",
3232
DataClassRowMapper(ConstructorPerson::class.java)
3333
)
34-
Assertions.assertThat(result.size).isEqualTo(1)
34+
assertThat(result.size).isEqualTo(1)
3535
verifyPerson(result[0])
3636
mock.verifyClosed()
3737
}
@@ -43,8 +43,8 @@ class KotlinDataClassRowMapperTests : AbstractRowMapperTests() {
4343
"select name, age, birth_date, balance from people",
4444
DataClassRowMapper(KotlinPerson::class.java)
4545
)
46-
Assertions.assertThat(result.size).isEqualTo(1)
47-
Assertions.assertThat(result[0].name).isEqualTo("Bubba appended by init")
46+
assertThat(result.size).isEqualTo(1)
47+
assertThat(result[0].name).isEqualTo("Bubba appended by init")
4848
}
4949

5050

spring-messaging/src/test/kotlin/org/springframework/messaging/converter/KotlinSerializationJsonMessageConverterTests.kt

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,8 @@
1717
package org.springframework.messaging.converter
1818

1919
import kotlinx.serialization.Serializable
20-
import org.assertj.core.api.Assertions
20+
import org.assertj.core.api.Assertions.assertThat
21+
import org.assertj.core.api.Assertions.assertThatExceptionOfType
2122
import org.junit.jupiter.api.Test
2223
import org.springframework.core.MethodParameter
2324
import org.springframework.messaging.support.MessageBuilder
@@ -50,12 +51,12 @@ class KotlinSerializationJsonMessageConverterTests {
5051
val message = MessageBuilder.withPayload(payload.toByteArray(StandardCharsets.UTF_8)).build()
5152
val result = converter.fromMessage(message, SerializableBean::class.java) as SerializableBean
5253

53-
Assertions.assertThat(result.bytes).containsExactly(0x1, 0x2)
54-
Assertions.assertThat(result.array).containsExactly("Foo", "Bar")
55-
Assertions.assertThat(result.number).isEqualTo(42)
56-
Assertions.assertThat(result.string).isEqualTo("Foo")
57-
Assertions.assertThat(result.bool).isTrue()
58-
Assertions.assertThat(result.fraction).isEqualTo(42.0f)
54+
assertThat(result.bytes).containsExactly(0x1, 0x2)
55+
assertThat(result.array).containsExactly("Foo", "Bar")
56+
assertThat(result.number).isEqualTo(42)
57+
assertThat(result.string).isEqualTo("Foo")
58+
assertThat(result.bool).isTrue()
59+
assertThat(result.fraction).isEqualTo(42.0f)
5960
}
6061

6162
@Test
@@ -82,13 +83,13 @@ class KotlinSerializationJsonMessageConverterTests {
8283
val message = MessageBuilder.withPayload(payload.toByteArray(StandardCharsets.UTF_8)).build()
8384
val result = converter.fromMessage(message, Array<SerializableBean>::class.java) as Array<SerializableBean>
8485

85-
Assertions.assertThat(result).hasSize(1)
86-
Assertions.assertThat(result[0].bytes).containsExactly(0x1, 0x2)
87-
Assertions.assertThat(result[0].array).containsExactly("Foo", "Bar")
88-
Assertions.assertThat(result[0].number).isEqualTo(42)
89-
Assertions.assertThat(result[0].string).isEqualTo("Foo")
90-
Assertions.assertThat(result[0].bool).isTrue()
91-
Assertions.assertThat(result[0].fraction).isEqualTo(42.0f)
86+
assertThat(result).hasSize(1)
87+
assertThat(result[0].bytes).containsExactly(0x1, 0x2)
88+
assertThat(result[0].array).containsExactly("Foo", "Bar")
89+
assertThat(result[0].number).isEqualTo(42)
90+
assertThat(result[0].string).isEqualTo("Foo")
91+
assertThat(result[0].bool).isTrue()
92+
assertThat(result[0].fraction).isEqualTo(42.0f)
9293
}
9394

9495
@Test
@@ -118,13 +119,13 @@ class KotlinSerializationJsonMessageConverterTests {
118119
val message = MessageBuilder.withPayload(payload.toByteArray(StandardCharsets.UTF_8)).build()
119120
val result = converter.fromMessage(message, typeOf<List<SerializableBean>>()::class.java, param) as List<SerializableBean>
120121

121-
Assertions.assertThat(result).hasSize(1)
122-
Assertions.assertThat(result[0].bytes).containsExactly(0x1, 0x2)
123-
Assertions.assertThat(result[0].array).containsExactly("Foo", "Bar")
124-
Assertions.assertThat(result[0].number).isEqualTo(42)
125-
Assertions.assertThat(result[0].string).isEqualTo("Foo")
126-
Assertions.assertThat(result[0].bool).isTrue()
127-
Assertions.assertThat(result[0].fraction).isEqualTo(42.0f)
122+
assertThat(result).hasSize(1)
123+
assertThat(result[0].bytes).containsExactly(0x1, 0x2)
124+
assertThat(result[0].array).containsExactly("Foo", "Bar")
125+
assertThat(result[0].number).isEqualTo(42)
126+
assertThat(result[0].string).isEqualTo("Foo")
127+
assertThat(result[0].bool).isTrue()
128+
assertThat(result[0].fraction).isEqualTo(42.0f)
128129
}
129130

130131
@Test
@@ -134,7 +135,7 @@ class KotlinSerializationJsonMessageConverterTests {
134135
""".trimIndent()
135136

136137
val message = MessageBuilder.withPayload(payload.toByteArray(StandardCharsets.UTF_8)).build()
137-
Assertions.assertThatExceptionOfType(MessageConversionException::class.java).isThrownBy {
138+
assertThatExceptionOfType(MessageConversionException::class.java).isThrownBy {
138139
converter.fromMessage(message, SerializableBean::class.java)
139140
}
140141
}
@@ -145,7 +146,7 @@ class KotlinSerializationJsonMessageConverterTests {
145146
val message = converter.toMessage(serializableBean, null)
146147
val result = String((message!!.payload as ByteArray), StandardCharsets.UTF_8)
147148

148-
Assertions.assertThat(result)
149+
assertThat(result)
149150
.contains("\"bytes\":[1,2]")
150151
.contains("\"array\":[\"Foo\",\"Bar\"]")
151152
.contains("\"number\":42")
@@ -160,7 +161,7 @@ class KotlinSerializationJsonMessageConverterTests {
160161
val message = converter.toMessage(serializableBean, null)
161162
val result = String((message!!.payload as ByteArray), StandardCharsets.UTF_8)
162163

163-
Assertions.assertThat(result)
164+
assertThat(result)
164165
.contains("\"bytes\":[1,2]")
165166
.contains("\"array\":[\"Foo\",\"Bar\"]")
166167
.contains("\"number\":42")
@@ -179,7 +180,7 @@ class KotlinSerializationJsonMessageConverterTests {
179180
val message = converter.toMessage(arrayOf(serializableBean), null)
180181
val result = String((message!!.payload as ByteArray), StandardCharsets.UTF_8)
181182

182-
Assertions.assertThat(result).isEqualTo(expectedJson)
183+
assertThat(result).isEqualTo(expectedJson)
183184
}
184185

185186
@Test
@@ -195,7 +196,7 @@ class KotlinSerializationJsonMessageConverterTests {
195196
val message = converter.toMessage(arrayListOf(serializableBean), null, param)
196197
val result = String((message!!.payload as ByteArray), StandardCharsets.UTF_8)
197198

198-
Assertions.assertThat(result).isEqualTo(expectedJson)
199+
assertThat(result).isEqualTo(expectedJson)
199200
}
200201

201202
@Suppress("UNUSED_PARAMETER")

spring-test/src/test/kotlin/org/springframework/test/context/KotlinDynamicPropertySourceIntegrationTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.test.context
1717

18-
import org.assertj.core.api.Assertions
18+
import org.assertj.core.api.Assertions.assertThat
1919
import org.junit.jupiter.api.Test
2020
import org.springframework.beans.factory.annotation.Autowired
2121
import org.springframework.beans.factory.annotation.Value
@@ -36,8 +36,8 @@ class KotlinDynamicPropertySourceIntegrationTests {
3636

3737
@Test
3838
fun hasInjectedValues(@Autowired service: Service) {
39-
Assertions.assertThat(service.ip).isEqualTo("127.0.0.1")
40-
Assertions.assertThat(service.port).isEqualTo(4242)
39+
assertThat(service.ip).isEqualTo("127.0.0.1")
40+
assertThat(service.port).isEqualTo(4242)
4141
}
4242

4343
@Configuration

spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,8 @@ import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.flow.flow
2222
import kotlinx.coroutines.flow.toList
2323
import kotlinx.coroutines.runBlocking
24-
import org.assertj.core.api.Assertions
24+
import org.assertj.core.api.Assertions.assertThat
25+
import org.assertj.core.api.Assertions.fail
2526
import org.junit.jupiter.api.Test
2627
import org.springframework.aop.framework.ProxyFactory
2728
import org.springframework.transaction.interceptor.TransactionInterceptor
@@ -60,7 +61,6 @@ class CoroutinesAnnotationTransactionInterceptorTests {
6061
}
6162
catch (ex: IllegalStateException) {
6263
}
63-
6464
}
6565
assertReactiveGetTransactionAndRollbackCount(1)
6666
}
@@ -72,7 +72,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
7272
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
7373
val proxy = proxyFactory.proxy as TestWithCoroutines
7474
runBlocking {
75-
Assertions.assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo")
75+
assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo")
7676
}
7777
assertReactiveGetTransactionAndCommitCount(1)
7878
}
@@ -86,7 +86,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
8686
runBlocking {
8787
try {
8888
proxy.suspendingValueFailure()
89-
Assertions.fail("No exception thrown as expected")
89+
fail("No exception thrown as expected")
9090
}
9191
catch (ex: IllegalStateException) {
9292
}
@@ -101,7 +101,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
101101
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
102102
val proxy = proxyFactory.proxy as TestWithCoroutines
103103
runBlocking {
104-
Assertions.assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo")
104+
assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo")
105105
}
106106
assertReactiveGetTransactionAndCommitCount(1)
107107
}
@@ -113,19 +113,19 @@ class CoroutinesAnnotationTransactionInterceptorTests {
113113
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
114114
val proxy = proxyFactory.proxy as TestWithCoroutines
115115
runBlocking {
116-
Assertions.assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo")
116+
assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo")
117117
}
118118
assertReactiveGetTransactionAndCommitCount(1)
119119
}
120120

121121
private fun assertReactiveGetTransactionAndCommitCount(expectedCount: Int) {
122-
Assertions.assertThat(rtm.begun).isEqualTo(expectedCount)
123-
Assertions.assertThat(rtm.commits).isEqualTo(expectedCount)
122+
assertThat(rtm.begun).isEqualTo(expectedCount)
123+
assertThat(rtm.commits).isEqualTo(expectedCount)
124124
}
125125

126126
private fun assertReactiveGetTransactionAndRollbackCount(expectedCount: Int) {
127-
Assertions.assertThat(rtm.begun).isEqualTo(expectedCount)
128-
Assertions.assertThat(rtm.rollbacks).isEqualTo(expectedCount)
127+
assertThat(rtm.begun).isEqualTo(expectedCount)
128+
assertThat(rtm.rollbacks).isEqualTo(expectedCount)
129129
}
130130

131131
@Transactional

spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.transaction.interceptor
1818

1919
import kotlinx.coroutines.delay
2020
import kotlinx.coroutines.runBlocking
21-
import org.assertj.core.api.Assertions
21+
import org.assertj.core.api.Assertions.assertThat
2222
import org.assertj.core.api.Fail
2323
import org.junit.jupiter.api.BeforeEach
2424
import org.junit.jupiter.api.Test
@@ -188,7 +188,7 @@ abstract class AbstractCoroutinesTransactionAspectTests {
188188
ex: Exception, shouldRollback: Boolean, rollbackException: Boolean) {
189189
val txatt: TransactionAttribute = object : DefaultTransactionAttribute() {
190190
override fun rollbackOn(t: Throwable): Boolean {
191-
Assertions.assertThat(t).isSameAs(ex)
191+
assertThat(t).isSameAs(ex)
192192
return shouldRollback
193193
}
194194
}
@@ -218,9 +218,9 @@ abstract class AbstractCoroutinesTransactionAspectTests {
218218
}
219219
catch (actual: Exception) {
220220
if (rollbackException) {
221-
Assertions.assertThat(actual).hasMessage(tex.message).isInstanceOf(tex::class.java)
221+
assertThat(actual).hasMessage(tex.message).isInstanceOf(tex::class.java)
222222
} else {
223-
Assertions.assertThat(actual).hasMessage(ex.message).isInstanceOf(ex::class.java)
223+
assertThat(actual).hasMessage(ex.message).isInstanceOf(ex::class.java)
224224
}
225225
}
226226
}
@@ -259,7 +259,7 @@ abstract class AbstractCoroutinesTransactionAspectTests {
259259
itb.getName()
260260
}
261261
catch (actual: Exception) {
262-
Assertions.assertThat(actual).isInstanceOf(CannotCreateTransactionException::class.java)
262+
assertThat(actual).isInstanceOf(CannotCreateTransactionException::class.java)
263263
}
264264
}
265265
}
@@ -291,11 +291,11 @@ abstract class AbstractCoroutinesTransactionAspectTests {
291291
itb.setName(name)
292292
}
293293
catch (ex: Exception) {
294-
Assertions.assertThat(ex).isInstanceOf(RuntimeException::class.java)
295-
Assertions.assertThat(ex.cause).hasMessage(ex.message).isInstanceOf(ex::class.java)
294+
assertThat(ex).isInstanceOf(RuntimeException::class.java)
295+
assertThat(ex.cause).hasMessage(ex.message).isInstanceOf(ex::class.java)
296296
}
297297
// Should have invoked target and changed name
298-
Assertions.assertThat(itb.getName()).isEqualTo(name)
298+
assertThat(itb.getName()).isEqualTo(name)
299299
}
300300
}
301301

0 commit comments

Comments
 (0)