Browse Source

Polish "Use static imports for Assertions.assertThat() consistently"

See gh-48630
3.5.x
Stéphane Nicoll 3 weeks ago
parent
commit
918325aecc
  1. 19
      spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java
  2. 5
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java

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

@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractAssert; @@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractObjectArrayAssert;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.AbstractThrowableAssert;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.MapAssert;
import org.assertj.core.error.BasicErrorMessageFactory;
@ -223,8 +222,8 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -223,8 +222,8 @@ public class ApplicationContextAssert<C extends ApplicationContext>
if (this.startupFailure != null) {
throwAssertionError(contextFailedToStartWhenExpecting("to get beans names with type:%n <%s>", type));
}
return Assertions.assertThat(getApplicationContext().getBeanNamesForType(type))
.as("Bean names of type <%s> from <%s>", type, getApplicationContext());
return assertThat(getApplicationContext().getBeanNamesForType(type)).as("Bean names of type <%s> from <%s>",
type, getApplicationContext());
}
/**
@ -277,7 +276,7 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -277,7 +276,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
getApplicationContext(), type, names));
}
T bean = (name != null) ? getApplicationContext().getBean(name, type) : null;
return Assertions.assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext());
return assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext());
}
private String getPrimary(String[] names, Scope scope) {
@ -328,7 +327,7 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -328,7 +327,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
throwAssertionError(contextFailedToStartWhenExpecting("to contain a bean of name:%n <%s>", name));
}
Object bean = findBean(name);
return Assertions.assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext());
return assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext());
}
/**
@ -360,8 +359,8 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -360,8 +359,8 @@ public class ApplicationContextAssert<C extends ApplicationContext>
"%nExpecting:%n <%s>%nto contain a bean of name:%n <%s> (%s)%nbut found:%n <%s> of type <%s>",
getApplicationContext(), name, type, bean, bean.getClass()));
}
return Assertions.assertThat((T) bean)
.as("Bean of name <%s> and type <%s> from <%s>", name, type, getApplicationContext());
return assertThat((T) bean).as("Bean of name <%s> and type <%s> from <%s>", name, type,
getApplicationContext());
}
private Object findBean(String name) {
@ -411,8 +410,8 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -411,8 +410,8 @@ public class ApplicationContextAssert<C extends ApplicationContext>
if (this.startupFailure != null) {
throwAssertionError(contextFailedToStartWhenExpecting("to get beans of type:%n <%s>", type));
}
return Assertions.assertThat(scope.getBeansOfType(getApplicationContext(), type))
.as("Beans of type <%s> from <%s>", type, getApplicationContext());
return assertThat(scope.getBeansOfType(getApplicationContext(), type)).as("Beans of type <%s> from <%s>", type,
getApplicationContext());
}
/**
@ -482,7 +481,6 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -482,7 +481,6 @@ public class ApplicationContextAssert<C extends ApplicationContext>
* Limited to the current context.
*/
NO_ANCESTORS {
@Override
String[] getBeanNamesForType(ApplicationContext applicationContext, Class<?> type) {
return applicationContext.getBeanNamesForType(type);
@ -499,7 +497,6 @@ public class ApplicationContextAssert<C extends ApplicationContext> @@ -499,7 +497,6 @@ public class ApplicationContextAssert<C extends ApplicationContext>
* Consider the ancestor contexts as well as the current context.
*/
INCLUDE_ANCESTORS {
@Override
String[] getBeanNamesForType(ApplicationContext applicationContext, Class<?> type) {
return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, type);

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

@ -32,7 +32,6 @@ import io.rsocket.SocketAcceptor; @@ -32,7 +32,6 @@ import io.rsocket.SocketAcceptor;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.client.WebsocketClientTransport;
import io.rsocket.util.DefaultPayload;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
@ -375,7 +374,7 @@ class NettyRSocketServerFactoryTests { @@ -375,7 +374,7 @@ class NettyRSocketServerFactoryTests {
}
private HttpClient createHttpClient() {
Assertions.assertThat(this.server).isNotNull();
assertThat(this.server).isNotNull();
InetSocketAddress address = this.server.address();
return HttpClient.create().host(address.getHostName()).port(address.getPort());
}
@ -389,7 +388,7 @@ class NettyRSocketServerFactoryTests { @@ -389,7 +388,7 @@ class NettyRSocketServerFactoryTests {
}
private TcpClient createTcpClient() {
Assertions.assertThat(this.server).isNotNull();
assertThat(this.server).isNotNull();
InetSocketAddress address = this.server.address();
return TcpClient.create().host(address.getHostName()).port(address.getPort());
}

Loading…
Cancel
Save