Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 15:35:32 +01:00
parent 32cd73261a
commit b3f786728e
58 changed files with 117 additions and 151 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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()));
}

View File

@@ -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;