Use modern language features in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -557,12 +557,7 @@ class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor {
|
||||
public int count;
|
||||
|
||||
public TestBeanAdvisor() {
|
||||
setAdvice(new MethodBeforeAdvice() {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
||||
++count;
|
||||
}
|
||||
});
|
||||
setAdvice((MethodBeforeAdvice) (method, args, target) -> ++count);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -372,17 +372,14 @@ public abstract class AbstractAopProxyTests {
|
||||
private void testContext(final boolean context) throws Throwable {
|
||||
final String s = "foo";
|
||||
// Test return value
|
||||
MethodInterceptor mi = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
if (!context) {
|
||||
assertNoInvocationContext();
|
||||
}
|
||||
else {
|
||||
assertThat(ExposeInvocationInterceptor.currentInvocation()).as("have context").isNotNull();
|
||||
}
|
||||
return s;
|
||||
MethodInterceptor mi = invocation -> {
|
||||
if (!context) {
|
||||
assertNoInvocationContext();
|
||||
}
|
||||
else {
|
||||
assertThat(ExposeInvocationInterceptor.currentInvocation()).as("have context").isNotNull();
|
||||
}
|
||||
return s;
|
||||
};
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
if (context) {
|
||||
@@ -422,11 +419,8 @@ public abstract class AbstractAopProxyTests {
|
||||
public void testDeclaredException() throws Throwable {
|
||||
final Exception expectedException = new Exception();
|
||||
// Test return value
|
||||
MethodInterceptor mi = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
throw expectedException;
|
||||
}
|
||||
MethodInterceptor mi = invocation -> {
|
||||
throw expectedException;
|
||||
};
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||
@@ -453,11 +447,8 @@ public abstract class AbstractAopProxyTests {
|
||||
public void testUndeclaredCheckedException() throws Throwable {
|
||||
final Exception unexpectedException = new Exception();
|
||||
// Test return value
|
||||
MethodInterceptor mi = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
throw unexpectedException;
|
||||
}
|
||||
MethodInterceptor mi = invocation -> {
|
||||
throw unexpectedException;
|
||||
};
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||
@@ -477,11 +468,8 @@ public abstract class AbstractAopProxyTests {
|
||||
public void testUndeclaredUncheckedException() throws Throwable {
|
||||
final RuntimeException unexpectedException = new RuntimeException();
|
||||
// Test return value
|
||||
MethodInterceptor mi = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
throw unexpectedException;
|
||||
}
|
||||
MethodInterceptor mi = invocation -> {
|
||||
throw unexpectedException;
|
||||
};
|
||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||
@@ -660,12 +648,7 @@ public abstract class AbstractAopProxyTests {
|
||||
NopInterceptor di = new NopInterceptor();
|
||||
pc.addAdvice(di);
|
||||
final long ts = 37;
|
||||
pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
|
||||
@Override
|
||||
public long getTimeStamp() {
|
||||
return ts;
|
||||
}
|
||||
}));
|
||||
pc.addAdvice(new DelegatingIntroductionInterceptor((TimeStamped) () -> ts));
|
||||
|
||||
ITestBean proxied = (ITestBean) createProxy(pc);
|
||||
assertThat(proxied.getName()).isEqualTo(name);
|
||||
@@ -1039,17 +1022,14 @@ public abstract class AbstractAopProxyTests {
|
||||
ProxyFactory pc = new ProxyFactory(tb);
|
||||
pc.addInterface(ITestBean.class);
|
||||
|
||||
MethodInterceptor twoBirthdayInterceptor = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
// Clone the invocation to proceed three times
|
||||
// "The Moor's Last Sigh": this technology can cause premature aging
|
||||
MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
clone1.proceed();
|
||||
clone2.proceed();
|
||||
return mi.proceed();
|
||||
}
|
||||
MethodInterceptor twoBirthdayInterceptor = mi -> {
|
||||
// Clone the invocation to proceed three times
|
||||
// "The Moor's Last Sigh": this technology can cause premature aging
|
||||
MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
clone1.proceed();
|
||||
clone2.proceed();
|
||||
return mi.proceed();
|
||||
};
|
||||
@SuppressWarnings("serial")
|
||||
StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
|
||||
@@ -1082,16 +1062,13 @@ public abstract class AbstractAopProxyTests {
|
||||
/**
|
||||
* Changes the name, then changes it back.
|
||||
*/
|
||||
MethodInterceptor nameReverter = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
String oldName = ((ITestBean) mi.getThis()).getName();
|
||||
clone.getArguments()[0] = oldName;
|
||||
// Original method invocation should be unaffected by changes to argument list of clone
|
||||
mi.proceed();
|
||||
return clone.proceed();
|
||||
}
|
||||
MethodInterceptor nameReverter = mi -> {
|
||||
MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||
String oldName = ((ITestBean) mi.getThis()).getName();
|
||||
clone.getArguments()[0] = oldName;
|
||||
// Original method invocation should be unaffected by changes to argument list of clone
|
||||
mi.proceed();
|
||||
return clone.proceed();
|
||||
};
|
||||
|
||||
class NameSaver implements MethodInterceptor {
|
||||
@@ -1347,8 +1324,9 @@ public abstract class AbstractAopProxyTests {
|
||||
@Override
|
||||
public void before(Method m, Object[] args, Object target) throws Throwable {
|
||||
super.before(m, args, target);
|
||||
if (m.getName().startsWith("set"))
|
||||
if (m.getName().startsWith("set")) {
|
||||
throw rex;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1563,13 +1541,10 @@ public abstract class AbstractAopProxyTests {
|
||||
@SuppressWarnings("serial")
|
||||
protected static class StringSetterNullReplacementAdvice extends DefaultPointcutAdvisor {
|
||||
|
||||
private static MethodInterceptor cleaner = new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
// We know it can only be invoked if there's a single parameter of type string
|
||||
mi.getArguments()[0] = "";
|
||||
return mi.proceed();
|
||||
}
|
||||
private static MethodInterceptor cleaner = mi -> {
|
||||
// We know it can only be invoked if there's a single parameter of type string
|
||||
mi.getArguments()[0] = "";
|
||||
return mi.proceed();
|
||||
};
|
||||
|
||||
public StringSetterNullReplacementAdvice() {
|
||||
@@ -1601,7 +1576,9 @@ public abstract class AbstractAopProxyTests {
|
||||
@Override
|
||||
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
||||
boolean run = m.getName().contains(pattern);
|
||||
if (run) ++count;
|
||||
if (run) {
|
||||
++count;
|
||||
}
|
||||
return run;
|
||||
}
|
||||
});
|
||||
@@ -1620,7 +1597,9 @@ public abstract class AbstractAopProxyTests {
|
||||
@Override
|
||||
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
||||
boolean run = m.getName().contains(pattern);
|
||||
if (run) ++count;
|
||||
if (run) {
|
||||
++count;
|
||||
}
|
||||
return run;
|
||||
}
|
||||
@Override
|
||||
@@ -1924,8 +1903,9 @@ public abstract class AbstractAopProxyTests {
|
||||
*/
|
||||
@Override
|
||||
public void releaseTarget(Object pTarget) throws Exception {
|
||||
if (pTarget != this.target)
|
||||
if (pTarget != this.target) {
|
||||
throw new RuntimeException("Released wrong target");
|
||||
}
|
||||
++releases;
|
||||
}
|
||||
|
||||
@@ -1934,8 +1914,9 @@ public abstract class AbstractAopProxyTests {
|
||||
*
|
||||
*/
|
||||
public void verify() {
|
||||
if (gets != releases)
|
||||
if (gets != releases) {
|
||||
throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,10 +198,16 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Person person = (Person) o;
|
||||
if (!name.equals(person.name)) return false;
|
||||
if (!name.equals(person.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,11 +304,8 @@ public class ProxyFactoryBeanTests {
|
||||
|
||||
final Exception ex = new UnsupportedOperationException("invoke");
|
||||
// Add evil interceptor to head of list
|
||||
config.addAdvice(0, new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
throw ex;
|
||||
}
|
||||
config.addAdvice(0, (MethodInterceptor) invocation -> {
|
||||
throw ex;
|
||||
});
|
||||
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
|
||||
|
||||
@@ -691,12 +688,9 @@ public class ProxyFactoryBeanTests {
|
||||
}
|
||||
|
||||
public PointcutForVoid() {
|
||||
setAdvice(new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
methodNames.add(invocation.getMethod().getName());
|
||||
return invocation.proceed();
|
||||
}
|
||||
setAdvice((MethodInterceptor) invocation -> {
|
||||
methodNames.add(invocation.getMethod().getName());
|
||||
return invocation.proceed();
|
||||
});
|
||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
@@ -434,6 +432,7 @@ public class AutoProxyCreatorTests {
|
||||
@SuppressWarnings("serial")
|
||||
public static class IntroductionTestAutoProxyCreator extends TestAutoProxyCreator {
|
||||
|
||||
@Override
|
||||
protected Object[] getAdvicesAndAdvisors() {
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(this.testInterceptor);
|
||||
advisor.addInterface(Serializable.class);
|
||||
@@ -491,12 +490,8 @@ public class AutoProxyCreatorTests {
|
||||
|
||||
@Override
|
||||
public ITestBean getObject() {
|
||||
return (ITestBean) Proxy.newProxyInstance(CustomProxyFactoryBean.class.getClassLoader(), new Class<?>[]{ITestBean.class}, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return ReflectionUtils.invokeMethod(method, tb, args);
|
||||
}
|
||||
});
|
||||
return (ITestBean) Proxy.newProxyInstance(CustomProxyFactoryBean.class.getClassLoader(), new Class<?>[]{ITestBean.class},
|
||||
(proxy, method, args) -> ReflectionUtils.invokeMethod(method, tb, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -158,8 +158,8 @@ class CommonsPool2TargetSourceTests {
|
||||
pooledInstances[9] = targetSource.getTarget();
|
||||
|
||||
// release all objects
|
||||
for (int i = 0; i < pooledInstances.length; i++) {
|
||||
targetSource.releaseTarget(pooledInstances[i]);
|
||||
for (Object element : pooledInstances) {
|
||||
targetSource.releaseTarget(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,21 +33,24 @@ public class LifecycleContextBean extends LifecycleBean implements ApplicationCo
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
super.setBeanFactory(beanFactory);
|
||||
if (this.owningContext != null)
|
||||
if (this.owningContext != null) {
|
||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
if (this.owningContext == null)
|
||||
if (this.owningContext == null) {
|
||||
throw new RuntimeException("Factory didn't call setApplicationContext before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (this.owningFactory == null)
|
||||
if (this.owningFactory == null) {
|
||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
||||
}
|
||||
|
||||
this.owningContext = applicationContext;
|
||||
}
|
||||
|
||||
@@ -544,19 +544,24 @@ class TestBean {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (obj == null)
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TestBean other = (TestBean) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!name.equals(other.name))
|
||||
else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,12 +215,7 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||
bf.registerBeanDefinition("testBean4", tbd);
|
||||
|
||||
bf.registerResolvableDependency(BeanFactory.class, bf);
|
||||
bf.registerResolvableDependency(INestedTestBean.class, new ObjectFactory<Object>() {
|
||||
@Override
|
||||
public Object getObject() throws BeansException {
|
||||
return new NestedTestBean();
|
||||
}
|
||||
});
|
||||
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) () -> new NestedTestBean());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.springframework.context.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -72,11 +70,8 @@ public class ConfigurationClassAndBFPPTests {
|
||||
|
||||
@Bean
|
||||
public BeanFactoryPostProcessor bfpp() {
|
||||
return new BeanFactoryPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
// no-op
|
||||
}
|
||||
return beanFactory -> {
|
||||
// no-op
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -88,11 +83,8 @@ public class ConfigurationClassAndBFPPTests {
|
||||
|
||||
@Bean
|
||||
public static final BeanFactoryPostProcessor bfpp() {
|
||||
return new BeanFactoryPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
// no-op
|
||||
}
|
||||
return beanFactory -> {
|
||||
// no-op
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,9 @@ public class ConfigurationClassWithConditionTests {
|
||||
static class ImportsNotCreated {
|
||||
|
||||
static {
|
||||
if (true) throw new RuntimeException();
|
||||
if (true) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,14 +301,18 @@ public class ConfigurationClassWithConditionTests {
|
||||
static class ConfigurationNotCreated {
|
||||
|
||||
static {
|
||||
if (true) throw new RuntimeException();
|
||||
if (true) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class RegistrarNotCreated implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
static {
|
||||
if (true) throw new RuntimeException();
|
||||
if (true) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,7 +324,9 @@ public class ConfigurationClassWithConditionTests {
|
||||
static class ImportSelectorNotCreated implements ImportSelector {
|
||||
|
||||
static {
|
||||
if (true) throw new RuntimeException();
|
||||
if (true) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,10 +136,7 @@ public class ConfigurationClassAspectIntegrationTests {
|
||||
|
||||
@Bean
|
||||
Runnable fromInnerClass() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
}
|
||||
return () -> {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||
import org.springframework.beans.factory.config.ListFactoryBean;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
@@ -559,12 +558,9 @@ public class ConfigurationClassProcessingTests {
|
||||
|
||||
// @Bean
|
||||
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
|
||||
return new BeanFactoryPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
||||
BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
|
||||
bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
|
||||
}
|
||||
return beanFactory -> {
|
||||
BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
|
||||
bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -141,12 +140,9 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
||||
|
||||
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
||||
smc.setTaskExecutor(new Executor() {
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
command.run();
|
||||
command.run();
|
||||
}
|
||||
smc.setTaskExecutor(command -> {
|
||||
command.run();
|
||||
command.run();
|
||||
});
|
||||
smc.addApplicationListener(listener);
|
||||
|
||||
@@ -429,12 +425,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
public void anonymousClassAsListener() {
|
||||
final Set<MyEvent> seenEvents = new HashSet<>();
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.addApplicationListener(new ApplicationListener<MyEvent>() {
|
||||
@Override
|
||||
public void onApplicationEvent(MyEvent event) {
|
||||
seenEvents.add(event);
|
||||
}
|
||||
});
|
||||
context.addApplicationListener((MyEvent event) -> seenEvents.add(event));
|
||||
context.refresh();
|
||||
|
||||
MyEvent event1 = new MyEvent(context);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PayloadApplicationEventTests {
|
||||
public void testProgrammaticPayloadListener() {
|
||||
List<String> events = new ArrayList<>();
|
||||
ApplicationListener<PayloadApplicationEvent<String>> listener = ApplicationListener.forPayload(events::add);
|
||||
ApplicationListener<PayloadApplicationEvent<Integer>> mismatch = ApplicationListener.forPayload(payload -> payload.intValue());
|
||||
ApplicationListener<PayloadApplicationEvent<Integer>> mismatch = ApplicationListener.forPayload(Integer::intValue);
|
||||
|
||||
ConfigurableApplicationContext ac = new GenericApplicationContext();
|
||||
ac.addApplicationListener(listener);
|
||||
|
||||
@@ -36,8 +36,12 @@ public abstract class AbstractIdentifiable implements Identifiable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractIdentifiable that = (AbstractIdentifiable) o;
|
||||
|
||||
|
||||
@@ -38,8 +38,12 @@ public class GenericEventPojo<T> implements ResolvableTypeProvider {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GenericEventPojo<?> that = (GenericEventPojo<?>) o;
|
||||
|
||||
|
||||
@@ -50,8 +50,12 @@ public abstract class IdentifiableApplicationEvent extends ApplicationEvent impl
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IdentifiableApplicationEvent that = (IdentifiableApplicationEvent) o;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -99,8 +99,7 @@ public class ConversionServiceFactoryBeanTests {
|
||||
Set<Object> converters = new HashSet<>();
|
||||
converters.add("bogus");
|
||||
factory.setConverters(converters);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
factory::afterPropertiesSet);
|
||||
assertThatIllegalArgumentException().isThrownBy(factory::afterPropertiesSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.format.annotation.NumberFormat;
|
||||
import org.springframework.format.annotation.NumberFormat.Style;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
import org.springframework.validation.DataBinder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -49,15 +48,12 @@ public class NumberFormattingTests {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
DefaultConversionService.addDefaultConverters(conversionService);
|
||||
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
|
||||
@Override
|
||||
public String resolveStringValue(String strVal) {
|
||||
if ("${pattern}".equals(strVal)) {
|
||||
return "#,##.00";
|
||||
}
|
||||
else {
|
||||
return strVal;
|
||||
}
|
||||
conversionService.setEmbeddedValueResolver(strVal -> {
|
||||
if ("${pattern}".equals(strVal)) {
|
||||
return "#,##.00";
|
||||
}
|
||||
else {
|
||||
return strVal;
|
||||
}
|
||||
});
|
||||
conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -189,24 +189,14 @@ public class FormattingConversionServiceFactoryBeanTests {
|
||||
public Printer<?> getPrinter(SpecialInt annotation, Class<?> fieldType) {
|
||||
assertThat(annotation.value()).isEqualTo("aliased");
|
||||
assertThat(annotation.alias()).isEqualTo("aliased");
|
||||
return new Printer<Integer>() {
|
||||
@Override
|
||||
public String print(Integer object, Locale locale) {
|
||||
return ":" + object.toString();
|
||||
}
|
||||
};
|
||||
return (object, locale) -> ":" + object.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parser<?> getParser(SpecialInt annotation, Class<?> fieldType) {
|
||||
assertThat(annotation.value()).isEqualTo("aliased");
|
||||
assertThat(annotation.alias()).isEqualTo("aliased");
|
||||
return new Parser<Integer>() {
|
||||
@Override
|
||||
public Integer parse(String text, Locale locale) throws ParseException {
|
||||
return Integer.parseInt(text.substring(1));
|
||||
}
|
||||
};
|
||||
return (text, locale) -> Integer.parseInt(text.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.jmx.AbstractMBeanServerTests;
|
||||
import org.springframework.jmx.JmxTestBean;
|
||||
import org.springframework.jmx.export.naming.ObjectNamingStrategy;
|
||||
import org.springframework.jmx.support.ObjectNameManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -74,12 +73,7 @@ class MBeanExporterOperationsTests extends AbstractMBeanServerTests {
|
||||
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setServer(getServer());
|
||||
exporter.setNamingStrategy(new ObjectNamingStrategy() {
|
||||
@Override
|
||||
public ObjectName getObjectName(Object managedBean, String beanKey) {
|
||||
return objectNameTemplate;
|
||||
}
|
||||
});
|
||||
exporter.setNamingStrategy((managedBean, beanKey) -> objectNameTemplate);
|
||||
|
||||
JmxTestBean bean1 = new JmxTestBean();
|
||||
JmxTestBean bean2 = new JmxTestBean();
|
||||
@@ -101,12 +95,7 @@ class MBeanExporterOperationsTests extends AbstractMBeanServerTests {
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setServer(getServer());
|
||||
exporter.setEnsureUniqueRuntimeObjectNames(false);
|
||||
exporter.setNamingStrategy(new ObjectNamingStrategy() {
|
||||
@Override
|
||||
public ObjectName getObjectName(Object managedBean, String beanKey) {
|
||||
return objectNameTemplate;
|
||||
}
|
||||
});
|
||||
exporter.setNamingStrategy((managedBean, beanKey) -> objectNameTemplate);
|
||||
|
||||
JmxTestBean bean1 = new JmxTestBean();
|
||||
JmxTestBean bean2 = new JmxTestBean();
|
||||
|
||||
@@ -90,11 +90,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
@Test
|
||||
void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
|
||||
Map<String, NotificationListener> listeners = new HashMap<>();
|
||||
NotificationListener dummyListener = new NotificationListener() {
|
||||
@Override
|
||||
public void handleNotification(Notification notification, Object handback) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
NotificationListener dummyListener = (notification, handback) -> {
|
||||
throw new UnsupportedOperationException();
|
||||
};
|
||||
// the MBean with the supplied object name does not exist...
|
||||
listeners.put("spring:type=Test", dummyListener);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -23,7 +23,6 @@ import javax.management.Attribute;
|
||||
import javax.management.AttributeChangeNotification;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationFilter;
|
||||
import javax.management.NotificationListener;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
@@ -117,7 +116,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setServer(server);
|
||||
exporter.setBeans(beans);
|
||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
||||
exporter.setNotificationListeners(listenerBean);
|
||||
start(exporter);
|
||||
|
||||
// update the attribute
|
||||
@@ -145,7 +144,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setServer(server);
|
||||
exporter.setBeans(beans);
|
||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
||||
exporter.setNotificationListeners(listenerBean);
|
||||
start(exporter);
|
||||
|
||||
// update the attribute
|
||||
@@ -168,23 +167,20 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||
|
||||
NotificationListenerBean listenerBean = new NotificationListenerBean();
|
||||
listenerBean.setNotificationListener(listener);
|
||||
listenerBean.setNotificationFilter(new NotificationFilter() {
|
||||
@Override
|
||||
public boolean isNotificationEnabled(Notification notification) {
|
||||
if (notification instanceof AttributeChangeNotification) {
|
||||
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
|
||||
return "Name".equals(changeNotification.getAttributeName());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
listenerBean.setNotificationFilter(notification -> {
|
||||
if (notification instanceof AttributeChangeNotification) {
|
||||
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
|
||||
return "Name".equals(changeNotification.getAttributeName());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setServer(server);
|
||||
exporter.setBeans(beans);
|
||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
||||
exporter.setNotificationListeners(listenerBean);
|
||||
start(exporter);
|
||||
|
||||
// update the attributes
|
||||
|
||||
@@ -83,9 +83,9 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
MBeanAttributeInfo[] inf = info.getAttributes();
|
||||
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
|
||||
|
||||
for (int x = 0; x < inf.length; x++) {
|
||||
assertThat(inf[x]).as("MBeanAttributeInfo should not be null").isNotNull();
|
||||
assertThat(inf[x].getDescription()).as("Description for MBeanAttributeInfo should not be null").isNotNull();
|
||||
for (MBeanAttributeInfo element : inf) {
|
||||
assertThat(element).as("MBeanAttributeInfo should not be null").isNotNull();
|
||||
assertThat(element.getDescription()).as("Description for MBeanAttributeInfo should not be null").isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
MBeanOperationInfo[] inf = info.getOperations();
|
||||
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
|
||||
|
||||
for (int x = 0; x < inf.length; x++) {
|
||||
assertThat(inf[x]).as("MBeanOperationInfo should not be null").isNotNull();
|
||||
assertThat(inf[x].getDescription()).as("Description for MBeanOperationInfo should not be null").isNotNull();
|
||||
for (MBeanOperationInfo element : inf) {
|
||||
assertThat(element).as("MBeanOperationInfo should not be null").isNotNull();
|
||||
assertThat(element.getDescription()).as("Description for MBeanOperationInfo should not be null").isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -613,16 +612,13 @@ public class AsyncExecutionTests {
|
||||
|
||||
public DynamicAsyncInterfaceBean() {
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||
assertThat(condition).isTrue();
|
||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||
}
|
||||
return null;
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
|
||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||
assertThat(condition).isTrue();
|
||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||
}
|
||||
return null;
|
||||
});
|
||||
advisor.addInterface(AsyncInterface.class);
|
||||
pf.addAdvisor(advisor);
|
||||
@@ -686,16 +682,13 @@ public class AsyncExecutionTests {
|
||||
|
||||
public DynamicAsyncMethodsInterfaceBean() {
|
||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||
assertThat(condition).isTrue();
|
||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||
}
|
||||
return null;
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
|
||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||
assertThat(condition).isTrue();
|
||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||
}
|
||||
return null;
|
||||
});
|
||||
advisor.addInterface(AsyncMethodsInterface.class);
|
||||
pf.addAdvisor(advisor);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.scheduling.config;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
@@ -59,12 +58,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
||||
|
||||
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return "foo";
|
||||
}
|
||||
});
|
||||
FutureTask<String> task = new FutureTask<>(() -> "foo");
|
||||
executor.execute(task);
|
||||
assertThat(task.get()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.codehaus.groovy.control.BytecodeProcessor;
|
||||
*/
|
||||
public class MyBytecodeProcessor implements BytecodeProcessor {
|
||||
|
||||
public final Set<String> processed = new HashSet<String>();
|
||||
public final Set<String> processed = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public byte[] processBytecode(String name, byte[] original) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.ui;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -281,12 +279,7 @@ public class ModelMapTests {
|
||||
Object proxy = Proxy.newProxyInstance(
|
||||
getClass().getClassLoader(),
|
||||
new Class<?>[] {Map.class},
|
||||
new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||
return "proxy";
|
||||
}
|
||||
});
|
||||
(proxy1, method, args) -> "proxy");
|
||||
map.addAttribute(proxy);
|
||||
assertThat(map.get("map")).isSameAs(proxy);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user