Replace anonymous inner class with lambda

See gh-15438
This commit is contained in:
igor-suhorukov
2018-12-11 00:37:41 +03:00
committed by Stephane Nicoll
parent 3a7406fe3a
commit e578d30722
19 changed files with 75 additions and 232 deletions

View File

@@ -669,26 +669,18 @@ public class SpringApplicationTests {
CommandLineRunner commandLineRunner = mock(CommandLineRunner.class);
application.addInitializers((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("commandLineRunner", new CommandLineRunner() {
@Override
public void run(String... args) throws Exception {
assertThat(SpringApplicationTests.this.output.toString())
.contains("Started");
commandLineRunner.run(args);
}
});
beanFactory.registerSingleton("applicationRunner", new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
assertThat(SpringApplicationTests.this.output.toString())
.contains("Started");
applicationRunner.run(args);
}
});
beanFactory.registerSingleton("commandLineRunner",
(CommandLineRunner) (args) -> {
assertThat(SpringApplicationTests.this.output.toString())
.contains("Started");
commandLineRunner.run(args);
});
beanFactory.registerSingleton("applicationRunner",
(ApplicationRunner) (args) -> {
assertThat(SpringApplicationTests.this.output.toString())
.contains("Started");
applicationRunner.run(args);
});
});
application.setWebApplicationType(WebApplicationType.NONE);
ApplicationListener<ApplicationReadyEvent> eventListener = mock(

View File

@@ -301,25 +301,20 @@ public class JettyServletWebServerFactoryTests
@Test
public void faultyListenerCausesStartFailure() throws Exception {
JettyServletWebServerFactory factory = getFactory();
factory.addServerCustomizers(new JettyServerCustomizer() {
factory.addServerCustomizers((JettyServerCustomizer) (server) -> {
Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class);
contexts.iterator().next().addEventListener(new ServletContextListener() {
@Override
public void customize(Server server) {
Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class);
contexts.iterator().next().addEventListener(new ServletContextListener() {
@Override
public void contextInitialized(ServletContextEvent sce) {
throw new RuntimeException();
}
@Override
public void contextInitialized(ServletContextEvent sce) {
throw new RuntimeException();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
});
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
});
});
assertThatExceptionOfType(WebServerException.class).isThrownBy(() -> {
JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer();

View File

@@ -38,11 +38,9 @@ import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.Scope;
@@ -475,16 +473,10 @@ public class ServletWebServerApplicationContextTests {
beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
this.context.registerBeanDefinition("withAutowiredServletRequest",
beanDefinition);
this.context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException {
WithAutowiredServletRequest bean = beanFactory
.getBean(WithAutowiredServletRequest.class);
assertThat(bean.getRequest()).isNotNull();
}
this.context.addBeanFactoryPostProcessor((beanFactory) -> {
WithAutowiredServletRequest bean = beanFactory
.getBean(WithAutowiredServletRequest.class);
assertThat(bean.getRequest()).isNotNull();
});
this.context.refresh();
String output = this.output.toString().substring(initialOutputLength);