Skip to content

Commit 918325a

Browse files
committed
Polish "Use static imports for Assertions.assertThat() consistently"
See gh-48630
1 parent 88f51fa commit 918325a

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.assertj.core.api.AbstractObjectArrayAssert;
2727
import org.assertj.core.api.AbstractObjectAssert;
2828
import org.assertj.core.api.AbstractThrowableAssert;
29-
import org.assertj.core.api.Assertions;
3029
import org.assertj.core.api.MapAssert;
3130
import org.assertj.core.error.BasicErrorMessageFactory;
3231

@@ -223,8 +222,8 @@ public <T> AbstractObjectArrayAssert<?, String> getBeanNames(Class<T> type) {
223222
if (this.startupFailure != null) {
224223
throwAssertionError(contextFailedToStartWhenExpecting("to get beans names with type:%n <%s>", type));
225224
}
226-
return Assertions.assertThat(getApplicationContext().getBeanNamesForType(type))
227-
.as("Bean names of type <%s> from <%s>", type, getApplicationContext());
225+
return assertThat(getApplicationContext().getBeanNamesForType(type)).as("Bean names of type <%s> from <%s>",
226+
type, getApplicationContext());
228227
}
229228

230229
/**
@@ -277,7 +276,7 @@ public <T> AbstractObjectAssert<?, T> getBean(Class<T> type, Scope scope) {
277276
getApplicationContext(), type, names));
278277
}
279278
T bean = (name != null) ? getApplicationContext().getBean(name, type) : null;
280-
return Assertions.assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext());
279+
return assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext());
281280
}
282281

283282
private String getPrimary(String[] names, Scope scope) {
@@ -328,7 +327,7 @@ public AbstractObjectAssert<?, Object> getBean(String name) {
328327
throwAssertionError(contextFailedToStartWhenExpecting("to contain a bean of name:%n <%s>", name));
329328
}
330329
Object bean = findBean(name);
331-
return Assertions.assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext());
330+
return assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext());
332331
}
333332

334333
/**
@@ -360,8 +359,8 @@ public <T> AbstractObjectAssert<?, T> getBean(String name, Class<T> type) {
360359
"%nExpecting:%n <%s>%nto contain a bean of name:%n <%s> (%s)%nbut found:%n <%s> of type <%s>",
361360
getApplicationContext(), name, type, bean, bean.getClass()));
362361
}
363-
return Assertions.assertThat((T) bean)
364-
.as("Bean of name <%s> and type <%s> from <%s>", name, type, getApplicationContext());
362+
return assertThat((T) bean).as("Bean of name <%s> and type <%s> from <%s>", name, type,
363+
getApplicationContext());
365364
}
366365

367366
private Object findBean(String name) {
@@ -411,8 +410,8 @@ public <T> MapAssert<String, T> getBeans(Class<T> type, Scope scope) {
411410
if (this.startupFailure != null) {
412411
throwAssertionError(contextFailedToStartWhenExpecting("to get beans of type:%n <%s>", type));
413412
}
414-
return Assertions.assertThat(scope.getBeansOfType(getApplicationContext(), type))
415-
.as("Beans of type <%s> from <%s>", type, getApplicationContext());
413+
return assertThat(scope.getBeansOfType(getApplicationContext(), type)).as("Beans of type <%s> from <%s>", type,
414+
getApplicationContext());
416415
}
417416

418417
/**
@@ -482,7 +481,6 @@ public enum Scope {
482481
* Limited to the current context.
483482
*/
484483
NO_ANCESTORS {
485-
486484
@Override
487485
String[] getBeanNamesForType(ApplicationContext applicationContext, Class<?> type) {
488486
return applicationContext.getBeanNamesForType(type);
@@ -499,7 +497,6 @@ <T> Map<String, T> getBeansOfType(ApplicationContext applicationContext, Class<T
499497
* Consider the ancestor contexts as well as the current context.
500498
*/
501499
INCLUDE_ANCESTORS {
502-
503500
@Override
504501
String[] getBeanNamesForType(ApplicationContext applicationContext, Class<?> type) {
505502
return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, type);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import io.rsocket.transport.netty.client.TcpClientTransport;
3333
import io.rsocket.transport.netty.client.WebsocketClientTransport;
3434
import io.rsocket.util.DefaultPayload;
35-
import org.assertj.core.api.Assertions;
3635
import org.junit.jupiter.api.AfterEach;
3736
import org.junit.jupiter.api.Test;
3837
import org.mockito.InOrder;
@@ -375,7 +374,7 @@ private HttpClient createSecureHttpClient() {
375374
}
376375

377376
private HttpClient createHttpClient() {
378-
Assertions.assertThat(this.server).isNotNull();
377+
assertThat(this.server).isNotNull();
379378
InetSocketAddress address = this.server.address();
380379
return HttpClient.create().host(address.getHostName()).port(address.getPort());
381380
}
@@ -389,7 +388,7 @@ private TcpClient createSecureTcpClient() {
389388
}
390389

391390
private TcpClient createTcpClient() {
392-
Assertions.assertThat(this.server).isNotNull();
391+
assertThat(this.server).isNotNull();
393392
InetSocketAddress address = this.server.address();
394393
return TcpClient.create().host(address.getHostName()).port(address.getPort());
395394
}

0 commit comments

Comments
 (0)