Use pattern matching for instanceof where appropriate
See gh-31475
This commit is contained in:
committed by
Andy Wilkinson
parent
a7b98e7312
commit
5db04da275
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,9 +51,8 @@ public class SpringBootDependencyInjectionTestExecutionListener extends Dependen
|
||||
private void outputConditionEvaluationReport(TestContext testContext) {
|
||||
try {
|
||||
ApplicationContext context = testContext.getApplicationContext();
|
||||
if (context instanceof ConfigurableApplicationContext) {
|
||||
ConditionEvaluationReport report = ConditionEvaluationReport
|
||||
.get(((ConfigurableApplicationContext) context).getBeanFactory());
|
||||
if (context instanceof ConfigurableApplicationContext configurableContext) {
|
||||
ConditionEvaluationReport report = ConditionEvaluationReport.get(configurableContext.getBeanFactory());
|
||||
System.err.println(new ConditionEvaluationReportMessage(report));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,12 +172,11 @@ public class TestDatabaseAutoConfiguration {
|
||||
|
||||
EmbeddedDataSourceFactory(Environment environment) {
|
||||
this.environment = environment;
|
||||
if (environment instanceof ConfigurableEnvironment) {
|
||||
if (environment instanceof ConfigurableEnvironment configurableEnvironment) {
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put("spring.datasource.schema-username", "");
|
||||
source.put("spring.sql.init.username", "");
|
||||
((ConfigurableEnvironment) environment).getPropertySources()
|
||||
.addFirst(new MapPropertySource("testDatabase", source));
|
||||
configurableEnvironment.getPropertySources().addFirst(new MapPropertySource("testDatabase", source));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -134,8 +134,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
|
||||
putProperties(name + "[" + i + "]", defaultSkip, array[i], properties);
|
||||
}
|
||||
}
|
||||
else if (value instanceof MergedAnnotation<?>) {
|
||||
MergedAnnotation<?> annotation = (MergedAnnotation<?>) value;
|
||||
else if (value instanceof MergedAnnotation<?> annotation) {
|
||||
for (Method attribute : annotation.getType().getDeclaredMethods()) {
|
||||
collectProperties(name, defaultSkip, (MergedAnnotation<?>) value, attribute, properties);
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ public class WebDriverScope implements Scope {
|
||||
synchronized (this.instances) {
|
||||
for (Object instance : this.instances.values()) {
|
||||
reset = true;
|
||||
if (instance instanceof WebDriver) {
|
||||
((WebDriver) instance).quit();
|
||||
if (instance instanceof WebDriver webDriver) {
|
||||
webDriver.quit();
|
||||
}
|
||||
}
|
||||
this.instances.clear();
|
||||
@@ -138,9 +138,9 @@ public class WebDriverScope implements Scope {
|
||||
* @return the web driver scope or {@code null}
|
||||
*/
|
||||
static WebDriverScope getFrom(ApplicationContext context) {
|
||||
if (context instanceof ConfigurableApplicationContext) {
|
||||
Scope scope = ((ConfigurableApplicationContext) context).getBeanFactory().getRegisteredScope(NAME);
|
||||
return (scope instanceof WebDriverScope) ? (WebDriverScope) scope : null;
|
||||
if (context instanceof ConfigurableApplicationContext configurableContext) {
|
||||
Scope scope = configurableContext.getBeanFactory().getRegisteredScope(NAME);
|
||||
return (scope instanceof WebDriverScope webDriverScope) ? webDriverScope : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user