Use modern language features in tests
This commit is contained in:
@@ -347,7 +347,7 @@ class ContextLoaderTests {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
environment.getPropertySources().addFirst(new PropertySource<Object>("testPropertySource") {
|
||||
environment.getPropertySources().addFirst(new PropertySource<>("testPropertySource") {
|
||||
@Override
|
||||
public Object getProperty(String key) {
|
||||
return "name".equals(key) ? "testName" : null;
|
||||
|
||||
@@ -56,8 +56,8 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
root.addBeanFactoryPostProcessor(beanFactory -> beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof TestBean) {
|
||||
((TestBean) bean).getFriends().add("myFriend");
|
||||
if (bean instanceof TestBean testBean) {
|
||||
testBean.getFriends().add("myFriend");
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -182,8 +182,7 @@ public class InterceptorRegistryTests {
|
||||
PathMatcher pathMatcher = new AntPathMatcher();
|
||||
List<HandlerInterceptor> result = new ArrayList<>();
|
||||
for (Object interceptor : this.registry.getInterceptors()) {
|
||||
if (interceptor instanceof MappedInterceptor) {
|
||||
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
|
||||
if (interceptor instanceof MappedInterceptor mappedInterceptor) {
|
||||
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
|
||||
result.add(mappedInterceptor.getInterceptor());
|
||||
}
|
||||
|
||||
@@ -83,8 +83,7 @@ public class LocaleResolverTests {
|
||||
}
|
||||
|
||||
// check LocaleContext
|
||||
if (localeResolver instanceof LocaleContextResolver) {
|
||||
LocaleContextResolver localeContextResolver = (LocaleContextResolver) localeResolver;
|
||||
if (localeResolver instanceof LocaleContextResolver localeContextResolver) {
|
||||
LocaleContext localeContext = localeContextResolver.resolveLocaleContext(request);
|
||||
if (shouldSet) {
|
||||
assertThat(localeContext.getLocale()).isEqualTo(Locale.GERMANY);
|
||||
|
||||
@@ -46,10 +46,9 @@ public class ItemPet {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof ItemPet)) {
|
||||
if (!(other instanceof ItemPet otherPet)) {
|
||||
return false;
|
||||
}
|
||||
ItemPet otherPet = (ItemPet) other;
|
||||
return (this.name != null && this.name.equals(otherPet.getName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -556,8 +556,7 @@ class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof RulesVariant) {
|
||||
RulesVariant other = (RulesVariant) obj;
|
||||
if (obj instanceof RulesVariant other) {
|
||||
return this.toId().equals(other.toId());
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user