Skip to content

Commit

Permalink
Use AssertJ static imports consistently in 5.3.x
Browse files Browse the repository at this point in the history
Closes gh-29282
  • Loading branch information
izeye authored and sbrannen committed Oct 8, 2022
1 parent a599601 commit 1c1a0af
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 104 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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 Down Expand Up @@ -34,7 +34,6 @@
import java.util.TreeMap;
import java.util.TreeSet;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import org.springframework.util.LinkedMultiValueMap;
Expand Down Expand Up @@ -156,7 +155,7 @@ void createMapIsNotTypeSafeForLinkedMultiValueMap() {
@Test
void createApproximateCollectionFromEmptyHashSet() {
Collection<String> set = createApproximateCollection(new HashSet<String>(), 2);
Assertions.assertThat(set).isEmpty();
assertThat(set).isEmpty();
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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 @@ -16,7 +16,7 @@

package org.springframework.core

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class KotlinBridgeMethodResolverTests {
Expand All @@ -25,22 +25,22 @@ class KotlinBridgeMethodResolverTests {
fun findBridgedMethod() {
val unbridged = GenericRepository::class.java.getDeclaredMethod("delete", Int::class.java)
val bridged = GenericRepository::class.java.getDeclaredMethod("delete", Any::class.java)
Assertions.assertThat(unbridged.isBridge).isFalse
Assertions.assertThat(bridged.isBridge).isTrue
assertThat(unbridged.isBridge).isFalse
assertThat(bridged.isBridge).isTrue

Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
}

@Test
fun findBridgedMethodWithArrays() {
val unbridged = GenericRepository::class.java.getDeclaredMethod("delete", Array<Int>::class.java)
val bridged = GenericRepository::class.java.getDeclaredMethod("delete", Array<Any>::class.java)
Assertions.assertThat(unbridged.isBridge).isFalse
Assertions.assertThat(bridged.isBridge).isTrue
assertThat(unbridged.isBridge).isFalse
assertThat(bridged.isBridge).isTrue

Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
Assertions.assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
assertThat(BridgeMethodResolver.findBridgedMethod(unbridged)).`as`("Unbridged method not returned directly").isEqualTo(unbridged)
assertThat(BridgeMethodResolver.findBridgedMethod(bridged)).`as`("Incorrect bridged method returned").isEqualTo(unbridged)
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors
* Copyright 2002-2022 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 @@ -16,7 +16,7 @@

package org.springframework.jdbc.core

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.jdbc.core.test.ConstructorPerson
import java.math.BigDecimal
Expand All @@ -31,7 +31,7 @@ class KotlinDataClassRowMapperTests : AbstractRowMapperTests() {
"select name, age, birth_date, balance from people",
DataClassRowMapper(ConstructorPerson::class.java)
)
Assertions.assertThat(result.size).isEqualTo(1)
assertThat(result.size).isEqualTo(1)
verifyPerson(result[0])
mock.verifyClosed()
}
Expand All @@ -43,8 +43,8 @@ class KotlinDataClassRowMapperTests : AbstractRowMapperTests() {
"select name, age, birth_date, balance from people",
DataClassRowMapper(KotlinPerson::class.java)
)
Assertions.assertThat(result.size).isEqualTo(1)
Assertions.assertThat(result[0].name).isEqualTo("Bubba appended by init")
assertThat(result.size).isEqualTo(1)
assertThat(result[0].name).isEqualTo("Bubba appended by init")
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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 @@ -17,7 +17,8 @@
package org.springframework.messaging.converter

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

Assertions.assertThat(result.bytes).containsExactly(0x1, 0x2)
Assertions.assertThat(result.array).containsExactly("Foo", "Bar")
Assertions.assertThat(result.number).isEqualTo(42)
Assertions.assertThat(result.string).isEqualTo("Foo")
Assertions.assertThat(result.bool).isTrue()
Assertions.assertThat(result.fraction).isEqualTo(42.0f)
assertThat(result.bytes).containsExactly(0x1, 0x2)
assertThat(result.array).containsExactly("Foo", "Bar")
assertThat(result.number).isEqualTo(42)
assertThat(result.string).isEqualTo("Foo")
assertThat(result.bool).isTrue()
assertThat(result.fraction).isEqualTo(42.0f)
}

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

Assertions.assertThat(result).hasSize(1)
Assertions.assertThat(result[0].bytes).containsExactly(0x1, 0x2)
Assertions.assertThat(result[0].array).containsExactly("Foo", "Bar")
Assertions.assertThat(result[0].number).isEqualTo(42)
Assertions.assertThat(result[0].string).isEqualTo("Foo")
Assertions.assertThat(result[0].bool).isTrue()
Assertions.assertThat(result[0].fraction).isEqualTo(42.0f)
assertThat(result).hasSize(1)
assertThat(result[0].bytes).containsExactly(0x1, 0x2)
assertThat(result[0].array).containsExactly("Foo", "Bar")
assertThat(result[0].number).isEqualTo(42)
assertThat(result[0].string).isEqualTo("Foo")
assertThat(result[0].bool).isTrue()
assertThat(result[0].fraction).isEqualTo(42.0f)
}

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

Assertions.assertThat(result).hasSize(1)
Assertions.assertThat(result[0].bytes).containsExactly(0x1, 0x2)
Assertions.assertThat(result[0].array).containsExactly("Foo", "Bar")
Assertions.assertThat(result[0].number).isEqualTo(42)
Assertions.assertThat(result[0].string).isEqualTo("Foo")
Assertions.assertThat(result[0].bool).isTrue()
Assertions.assertThat(result[0].fraction).isEqualTo(42.0f)
assertThat(result).hasSize(1)
assertThat(result[0].bytes).containsExactly(0x1, 0x2)
assertThat(result[0].array).containsExactly("Foo", "Bar")
assertThat(result[0].number).isEqualTo(42)
assertThat(result[0].string).isEqualTo("Foo")
assertThat(result[0].bool).isTrue()
assertThat(result[0].fraction).isEqualTo(42.0f)
}

@Test
Expand All @@ -134,7 +135,7 @@ class KotlinSerializationJsonMessageConverterTests {
""".trimIndent()

val message = MessageBuilder.withPayload(payload.toByteArray(StandardCharsets.UTF_8)).build()
Assertions.assertThatExceptionOfType(MessageConversionException::class.java).isThrownBy {
assertThatExceptionOfType(MessageConversionException::class.java).isThrownBy {
converter.fromMessage(message, SerializableBean::class.java)
}
}
Expand All @@ -145,7 +146,7 @@ class KotlinSerializationJsonMessageConverterTests {
val message = converter.toMessage(serializableBean, null)
val result = String((message!!.payload as ByteArray), StandardCharsets.UTF_8)

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

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

Assertions.assertThat(result).isEqualTo(expectedJson)
assertThat(result).isEqualTo(expectedJson)
}

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

Assertions.assertThat(result).isEqualTo(expectedJson)
assertThat(result).isEqualTo(expectedJson)
}

@Suppress("UNUSED_PARAMETER")
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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 @@ -15,7 +15,7 @@
*/
package org.springframework.test.context

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
Expand All @@ -36,8 +36,8 @@ class KotlinDynamicPropertySourceIntegrationTests {

@Test
fun hasInjectedValues(@Autowired service: Service) {
Assertions.assertThat(service.ip).isEqualTo("127.0.0.1")
Assertions.assertThat(service.port).isEqualTo(4242)
assertThat(service.ip).isEqualTo("127.0.0.1")
assertThat(service.port).isEqualTo(4242)
}

@Configuration
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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 @@ -21,7 +21,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.jupiter.api.Test
import org.springframework.aop.framework.ProxyFactory
import org.springframework.transaction.interceptor.TransactionInterceptor
Expand Down Expand Up @@ -60,7 +61,6 @@ class CoroutinesAnnotationTransactionInterceptorTests {
}
catch (ex: IllegalStateException) {
}

}
assertReactiveGetTransactionAndRollbackCount(1)
}
Expand All @@ -72,7 +72,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
val proxy = proxyFactory.proxy as TestWithCoroutines
runBlocking {
Assertions.assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo")
assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo")
}
assertReactiveGetTransactionAndCommitCount(1)
}
Expand All @@ -86,7 +86,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
runBlocking {
try {
proxy.suspendingValueFailure()
Assertions.fail("No exception thrown as expected")
fail("No exception thrown as expected")
}
catch (ex: IllegalStateException) {
}
Expand All @@ -101,7 +101,7 @@ class CoroutinesAnnotationTransactionInterceptorTests {
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
val proxy = proxyFactory.proxy as TestWithCoroutines
runBlocking {
Assertions.assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo")
assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo")
}
assertReactiveGetTransactionAndCommitCount(1)
}
Expand All @@ -113,19 +113,19 @@ class CoroutinesAnnotationTransactionInterceptorTests {
proxyFactory.addAdvice(TransactionInterceptor(rtm, source))
val proxy = proxyFactory.proxy as TestWithCoroutines
runBlocking {
Assertions.assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo")
assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo")
}
assertReactiveGetTransactionAndCommitCount(1)
}

private fun assertReactiveGetTransactionAndCommitCount(expectedCount: Int) {
Assertions.assertThat(rtm.begun).isEqualTo(expectedCount)
Assertions.assertThat(rtm.commits).isEqualTo(expectedCount)
assertThat(rtm.begun).isEqualTo(expectedCount)
assertThat(rtm.commits).isEqualTo(expectedCount)
}

private fun assertReactiveGetTransactionAndRollbackCount(expectedCount: Int) {
Assertions.assertThat(rtm.begun).isEqualTo(expectedCount)
Assertions.assertThat(rtm.rollbacks).isEqualTo(expectedCount)
assertThat(rtm.begun).isEqualTo(expectedCount)
assertThat(rtm.rollbacks).isEqualTo(expectedCount)
}

@Transactional
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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 @@ -18,7 +18,7 @@ package org.springframework.transaction.interceptor

import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Fail
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -188,7 +188,7 @@ abstract class AbstractCoroutinesTransactionAspectTests {
ex: Exception, shouldRollback: Boolean, rollbackException: Boolean) {
val txatt: TransactionAttribute = object : DefaultTransactionAttribute() {
override fun rollbackOn(t: Throwable): Boolean {
Assertions.assertThat(t).isSameAs(ex)
assertThat(t).isSameAs(ex)
return shouldRollback
}
}
Expand Down Expand Up @@ -218,9 +218,9 @@ abstract class AbstractCoroutinesTransactionAspectTests {
}
catch (actual: Exception) {
if (rollbackException) {
Assertions.assertThat(actual).hasMessage(tex.message).isInstanceOf(tex::class.java)
assertThat(actual).hasMessage(tex.message).isInstanceOf(tex::class.java)
} else {
Assertions.assertThat(actual).hasMessage(ex.message).isInstanceOf(ex::class.java)
assertThat(actual).hasMessage(ex.message).isInstanceOf(ex::class.java)
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ abstract class AbstractCoroutinesTransactionAspectTests {
itb.getName()
}
catch (actual: Exception) {
Assertions.assertThat(actual).isInstanceOf(CannotCreateTransactionException::class.java)
assertThat(actual).isInstanceOf(CannotCreateTransactionException::class.java)
}
}
}
Expand Down Expand Up @@ -291,11 +291,11 @@ abstract class AbstractCoroutinesTransactionAspectTests {
itb.setName(name)
}
catch (ex: Exception) {
Assertions.assertThat(ex).isInstanceOf(RuntimeException::class.java)
Assertions.assertThat(ex.cause).hasMessage(ex.message).isInstanceOf(ex::class.java)
assertThat(ex).isInstanceOf(RuntimeException::class.java)
assertThat(ex.cause).hasMessage(ex.message).isInstanceOf(ex::class.java)
}
// Should have invoked target and changed name
Assertions.assertThat(itb.getName()).isEqualTo(name)
assertThat(itb.getName()).isEqualTo(name)
}
}

Expand Down

0 comments on commit 1c1a0af

Please sign in to comment.