Use modern language features in tests
This commit is contained in:
@@ -1358,7 +1358,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<String> stringRepo() {
|
||||
return new Repository<String>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<String>";
|
||||
@@ -1368,7 +1368,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<Integer> integerRepo() {
|
||||
return new Repository<Integer>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<Integer>";
|
||||
@@ -1378,7 +1378,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public Repository<?> genericRepo() {
|
||||
return new Repository<Object>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<Object>";
|
||||
@@ -1423,7 +1423,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
public Repository<String> stringRepo() {
|
||||
return new Repository<String>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<String>";
|
||||
@@ -1434,7 +1434,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
public Repository<Integer> integerRepo() {
|
||||
return new Repository<Integer>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<Integer>";
|
||||
@@ -1446,7 +1446,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
@Scope("prototype")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Repository genericRepo() {
|
||||
return new Repository<Object>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<Object>";
|
||||
@@ -1468,7 +1468,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
@Bean
|
||||
@Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public Repository<String> stringRepo() {
|
||||
return new Repository<String>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<String>";
|
||||
@@ -1479,7 +1479,7 @@ class ConfigurationClassPostProcessorTests {
|
||||
@Bean
|
||||
@PrototypeScoped
|
||||
public Repository<Integer> integerRepo() {
|
||||
return new Repository<Integer>() {
|
||||
return new Repository<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Repository<Integer>";
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
|
||||
beanDefinition.setFactoryBeanName("factoryBean");
|
||||
beanDefinition.setFactoryMethodName("myBean");
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
try {
|
||||
try (context) {
|
||||
context.registerBeanDefinition("factoryBean", factoryBeanDefinition);
|
||||
context.registerBeanDefinition("myBean", beanDefinition);
|
||||
NameCollectingBeanFactoryPostProcessor postProcessor = new NameCollectingBeanFactoryPostProcessor();
|
||||
@@ -103,9 +103,6 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
|
||||
context.refresh();
|
||||
assertContainsMyBeanName(postProcessor.getNames());
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertPostFreeze(Class<?> configurationClass) {
|
||||
@@ -118,16 +115,13 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
|
||||
BeanFactoryPostProcessor... postProcessors) {
|
||||
NameCollectingBeanFactoryPostProcessor postProcessor = new NameCollectingBeanFactoryPostProcessor();
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
try {
|
||||
try (context) {
|
||||
Arrays.stream(postProcessors).forEach(context::addBeanFactoryPostProcessor);
|
||||
context.addBeanFactoryPostProcessor(postProcessor);
|
||||
context.register(configurationClass);
|
||||
context.refresh();
|
||||
assertContainsMyBeanName(postProcessor.getNames());
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertContainsMyBeanName(AnnotationConfigApplicationContext context) {
|
||||
|
||||
@@ -327,7 +327,7 @@ class PropertySourceAnnotationTests {
|
||||
@Bean
|
||||
FactoryBean<TestBean> testBean() {
|
||||
final String name = env.getProperty("testbean.name");
|
||||
return new FactoryBean<TestBean>() {
|
||||
return new FactoryBean<>() {
|
||||
@Override
|
||||
public TestBean getObject() {
|
||||
return new TestBean(name);
|
||||
@@ -417,7 +417,7 @@ class PropertySourceAnnotationTests {
|
||||
@Override
|
||||
public org.springframework.core.env.PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
|
||||
Properties props = PropertiesLoaderUtils.loadProperties(resource);
|
||||
return new org.springframework.core.env.PropertySource<Properties>("my" + name, props) {
|
||||
return new org.springframework.core.env.PropertySource<>("my" + name, props) {
|
||||
@Override
|
||||
public Object getProperty(String name) {
|
||||
String value = props.getProperty(name);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class Spr15275Tests {
|
||||
|
||||
@Bean
|
||||
public FactoryBean<Foo> foo() {
|
||||
return new FactoryBean<Foo>() {
|
||||
return new FactoryBean<>() {
|
||||
@Override
|
||||
public Foo getObject() {
|
||||
return new Foo("x");
|
||||
@@ -103,7 +103,7 @@ public class Spr15275Tests {
|
||||
|
||||
@Bean
|
||||
public FactoryBean<Foo> foo() {
|
||||
return new AbstractFactoryBean<Foo>() {
|
||||
return new AbstractFactoryBean<>() {
|
||||
@Override
|
||||
public Foo createInstance() {
|
||||
return new Foo("x");
|
||||
@@ -128,7 +128,7 @@ public class Spr15275Tests {
|
||||
|
||||
@Bean
|
||||
public FactoryBean<FooInterface> foo() {
|
||||
return new AbstractFactoryBean<FooInterface>() {
|
||||
return new AbstractFactoryBean<>() {
|
||||
@Override
|
||||
public FooInterface createInstance() {
|
||||
return new Foo("x");
|
||||
@@ -153,7 +153,7 @@ public class Spr15275Tests {
|
||||
|
||||
@Bean
|
||||
public AbstractFactoryBean<FooInterface> foo() {
|
||||
return new AbstractFactoryBean<FooInterface>() {
|
||||
return new AbstractFactoryBean<>() {
|
||||
@Override
|
||||
public FooInterface createInstance() {
|
||||
return new Foo("x");
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Spr16179Tests {
|
||||
|
||||
@Bean
|
||||
Assembler<SomeType> someAssembler() {
|
||||
return new Assembler<SomeType>() {};
|
||||
return new Assembler<>() {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -774,8 +774,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
if (event.content == null) {
|
||||
return null;
|
||||
}
|
||||
else if (event.content instanceof String) {
|
||||
String s = (String) event.content;
|
||||
else if (event.content instanceof String s) {
|
||||
if (s.equals("String")) {
|
||||
return event.content;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ConversionServiceFactoryBeanTests {
|
||||
converters.add(new ConverterFactory<String, Bar>() {
|
||||
@Override
|
||||
public <T extends Bar> Converter<String, T> getConverter(Class<T> targetType) {
|
||||
return new Converter<String, T> () {
|
||||
return new Converter<> () {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T convert(String source) {
|
||||
|
||||
@@ -265,7 +265,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
|
||||
|
||||
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
|
||||
|
||||
PropertySource<?> ps = new PropertySource<Object>("simplePropertySource", new Object()) {
|
||||
PropertySource<?> ps = new PropertySource<>("simplePropertySource", new Object()) {
|
||||
@Override
|
||||
public Object getProperty(String key) {
|
||||
return "bar";
|
||||
|
||||
@@ -168,8 +168,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||
NotificationListenerBean listenerBean = new NotificationListenerBean();
|
||||
listenerBean.setNotificationListener(listener);
|
||||
listenerBean.setNotificationFilter(notification -> {
|
||||
if (notification instanceof AttributeChangeNotification) {
|
||||
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
|
||||
if (notification instanceof AttributeChangeNotification changeNotification) {
|
||||
return "Name".equals(changeNotification.getAttributeName());
|
||||
}
|
||||
else {
|
||||
@@ -450,8 +449,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||
|
||||
@Override
|
||||
public void handleNotification(Notification notification, Object handback) {
|
||||
if (notification instanceof AttributeChangeNotification) {
|
||||
AttributeChangeNotification attNotification = (AttributeChangeNotification) notification;
|
||||
if (notification instanceof AttributeChangeNotification attNotification) {
|
||||
String attributeName = attNotification.getAttributeName();
|
||||
|
||||
Integer currentCount = (Integer) this.attributeCounts.get(attributeName);
|
||||
|
||||
@@ -108,7 +108,7 @@ class BitsCronFieldTests {
|
||||
}
|
||||
|
||||
private static Condition<BitsCronField> set(int... indices) {
|
||||
return new Condition<BitsCronField>(String.format("set bits %s", Arrays.toString(indices))) {
|
||||
return new Condition<>(String.format("set bits %s", Arrays.toString(indices))) {
|
||||
@Override
|
||||
public boolean matches(BitsCronField value) {
|
||||
for (int index : indices) {
|
||||
@@ -122,7 +122,7 @@ class BitsCronFieldTests {
|
||||
}
|
||||
|
||||
private static Condition<BitsCronField> setRange(int min, int max) {
|
||||
return new Condition<BitsCronField>(String.format("set range %d-%d", min, max)) {
|
||||
return new Condition<>(String.format("set range %d-%d", min, max)) {
|
||||
@Override
|
||||
public boolean matches(BitsCronField value) {
|
||||
for (int i = min; i < max; i++) {
|
||||
@@ -136,7 +136,7 @@ class BitsCronFieldTests {
|
||||
}
|
||||
|
||||
private static Condition<BitsCronField> clear(int... indices) {
|
||||
return new Condition<BitsCronField>(String.format("clear bits %s", Arrays.toString(indices))) {
|
||||
return new Condition<>(String.format("clear bits %s", Arrays.toString(indices))) {
|
||||
@Override
|
||||
public boolean matches(BitsCronField value) {
|
||||
for (int index : indices) {
|
||||
@@ -150,7 +150,7 @@ class BitsCronFieldTests {
|
||||
}
|
||||
|
||||
private static Condition<BitsCronField> clearRange(int min, int max) {
|
||||
return new Condition<BitsCronField>(String.format("clear range %d-%d", min, max)) {
|
||||
return new Condition<>(String.format("clear range %d-%d", min, max)) {
|
||||
@Override
|
||||
public boolean matches(BitsCronField value) {
|
||||
for (int i = min; i < max; i++) {
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class CronExpressionTests {
|
||||
|
||||
private static final Condition<Temporal> weekday = new Condition<Temporal>("weekday") {
|
||||
private static final Condition<Temporal> weekday = new Condition<>("weekday") {
|
||||
|
||||
@Override
|
||||
public boolean matches(Temporal value) {
|
||||
|
||||
Reference in New Issue
Block a user