Skip to content

Commit c10cf59

Browse files
committed
Merge pull request #48630 from izeye
* pr/48630: Polish "Use static imports for Assertions.assertThat() consistently" Use static imports for Assertions.assertThat() consistently Closes gh-48630
2 parents 54d7f79 + 918325a commit c10cf59

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

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-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.assertj.core.api.AbstractCharSequenceAssert;
3131
import org.assertj.core.api.AbstractObjectAssert;
3232
import org.assertj.core.api.Assert;
33-
import org.assertj.core.api.Assertions;
3433
import org.assertj.core.api.ListAssert;
3534
import org.assertj.core.api.MapAssert;
3635
import org.skyscreamer.jsonassert.JSONCompare;
@@ -42,6 +41,8 @@
4241
import org.springframework.util.ObjectUtils;
4342
import org.springframework.util.StringUtils;
4443

44+
import static org.assertj.core.api.Assertions.assertThat;
45+
4546
/**
4647
* AssertJ {@link Assert} for {@link JsonContent}.
4748
*
@@ -915,7 +916,7 @@ public JsonContentAssert doesNotHaveEmptyJsonPathValue(CharSequence expression,
915916
* @throws AssertionError if the path is not valid
916917
*/
917918
public AbstractObjectAssert<?, Object> extractingJsonPathValue(CharSequence expression, Object... args) {
918-
return Assertions.assertThat(new JsonPathValue(expression, args).getValue(false));
919+
return assertThat(new JsonPathValue(expression, args).getValue(false));
919920
}
920921

921922
/**
@@ -928,7 +929,7 @@ public AbstractObjectAssert<?, Object> extractingJsonPathValue(CharSequence expr
928929
*/
929930
public AbstractCharSequenceAssert<?, String> extractingJsonPathStringValue(CharSequence expression,
930931
Object... args) {
931-
return Assertions.assertThat(extractingJsonPathValue(expression, args, String.class, "a string"));
932+
return assertThat(extractingJsonPathValue(expression, args, String.class, "a string"));
932933
}
933934

934935
/**
@@ -940,7 +941,7 @@ public AbstractCharSequenceAssert<?, String> extractingJsonPathStringValue(CharS
940941
* @throws AssertionError if the path is not valid or does not result in a number
941942
*/
942943
public AbstractObjectAssert<?, Number> extractingJsonPathNumberValue(CharSequence expression, Object... args) {
943-
return Assertions.assertThat(extractingJsonPathValue(expression, args, Number.class, "a number"));
944+
return assertThat(extractingJsonPathValue(expression, args, Number.class, "a number"));
944945
}
945946

946947
/**
@@ -952,7 +953,7 @@ public AbstractObjectAssert<?, Number> extractingJsonPathNumberValue(CharSequenc
952953
* @throws AssertionError if the path is not valid or does not result in a boolean
953954
*/
954955
public AbstractBooleanAssert<?> extractingJsonPathBooleanValue(CharSequence expression, Object... args) {
955-
return Assertions.assertThat(extractingJsonPathValue(expression, args, Boolean.class, "a boolean"));
956+
return assertThat(extractingJsonPathValue(expression, args, Boolean.class, "a boolean"));
956957
}
957958

958959
/**
@@ -966,7 +967,7 @@ public AbstractBooleanAssert<?> extractingJsonPathBooleanValue(CharSequence expr
966967
*/
967968
@SuppressWarnings("unchecked")
968969
public <E> ListAssert<E> extractingJsonPathArrayValue(CharSequence expression, Object... args) {
969-
return Assertions.assertThat(extractingJsonPathValue(expression, args, List.class, "an array"));
970+
return assertThat(extractingJsonPathValue(expression, args, List.class, "an array"));
970971
}
971972

972973
/**
@@ -981,7 +982,7 @@ public <E> ListAssert<E> extractingJsonPathArrayValue(CharSequence expression, O
981982
*/
982983
@SuppressWarnings("unchecked")
983984
public <K, V> MapAssert<K, V> extractingJsonPathMapValue(CharSequence expression, Object... args) {
984-
return Assertions.assertThat(extractingJsonPathValue(expression, args, Map.class, "a map"));
985+
return assertThat(extractingJsonPathValue(expression, args, Map.class, "a map"));
985986
}
986987

987988
@SuppressWarnings("unchecked")

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
}

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
2828
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
2929
import org.assertj.core.api.AbstractAssert;
30-
import org.assertj.core.api.Assertions;
3130
import org.assertj.core.api.ListAssert;
3231

3332
import org.springframework.boot.buildpack.platform.docker.DockerApi;
@@ -36,6 +35,8 @@
3635
import org.springframework.boot.test.json.JsonContentAssert;
3736
import org.springframework.util.StreamUtils;
3837

38+
import static org.assertj.core.api.Assertions.assertThat;
39+
3940
/**
4041
* AssertJ {@link org.assertj.core.api.Assert} for Docker image contents.
4142
*
@@ -92,7 +93,7 @@ public ListAssert<String> entries() {
9293
catch (IOException ex) {
9394
failWithMessage("IOException while reading image layer archive: '%s'", ex.getMessage());
9495
}
95-
return Assertions.assertThat(entryNames);
96+
return assertThat(entryNames);
9697
}
9798

9899
public void jsonEntry(String name, Consumer<JsonContentAssert> assertConsumer) {

0 commit comments

Comments
 (0)