mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Replace loops with Arrays.setAll where possible
See gh-14125
This commit is contained in:
parent
a92277b679
commit
0bc66dc4a9
@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.configurationprocessor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
@ -86,9 +87,7 @@ class TypeUtils {
|
||||
private TypeMirror getDeclaredType(Types types, Class<?> typeClass,
|
||||
int numberOfTypeArgs) {
|
||||
TypeMirror[] typeArgs = new TypeMirror[numberOfTypeArgs];
|
||||
for (int i = 0; i < typeArgs.length; i++) {
|
||||
typeArgs[i] = types.getWildcardType(null, null);
|
||||
}
|
||||
Arrays.setAll(typeArgs, i -> types.getWildcardType(null, null));
|
||||
TypeElement typeElement = this.env.getElementUtils()
|
||||
.getTypeElement(typeClass.getName());
|
||||
try {
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.testsupport.web.servlet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -114,9 +115,7 @@ public abstract class MockServletWebServer {
|
||||
|
||||
public Servlet[] getServlets() {
|
||||
Servlet[] servlets = new Servlet[this.registeredServlets.size()];
|
||||
for (int i = 0; i < servlets.length; i++) {
|
||||
servlets[i] = this.registeredServlets.get(i).getServlet();
|
||||
}
|
||||
Arrays.setAll(servlets, i -> this.registeredServlets.get(i).getServlet());
|
||||
return servlets;
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,7 @@ public class JettyReactiveWebServerFactoryTests
|
||||
HttpHandler handler = mock(HttpHandler.class);
|
||||
JettyReactiveWebServerFactory factory = getFactory();
|
||||
JettyServerCustomizer[] configurations = new JettyServerCustomizer[4];
|
||||
for (int i = 0; i < configurations.length; i++) {
|
||||
configurations[i] = mock(JettyServerCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(configurations, i -> mock(JettyServerCustomizer.class));
|
||||
factory.setServerCustomizers(Arrays.asList(configurations[0], configurations[1]));
|
||||
factory.addServerCustomizers(configurations[2], configurations[3]);
|
||||
this.webServer = factory.getWebServer(handler);
|
||||
|
@ -75,9 +75,7 @@ public class JettyServletWebServerFactoryTests
|
||||
public void jettyConfigurations() throws Exception {
|
||||
JettyServletWebServerFactory factory = getFactory();
|
||||
Configuration[] configurations = new Configuration[4];
|
||||
for (int i = 0; i < configurations.length; i++) {
|
||||
configurations[i] = mock(Configuration.class);
|
||||
}
|
||||
Arrays.setAll(configurations, i -> mock(Configuration.class));
|
||||
factory.setConfigurations(Arrays.asList(configurations[0], configurations[1]));
|
||||
factory.addConfigurations(configurations[2], configurations[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
@ -91,9 +89,7 @@ public class JettyServletWebServerFactoryTests
|
||||
public void jettyCustomizations() {
|
||||
JettyServletWebServerFactory factory = getFactory();
|
||||
JettyServerCustomizer[] configurations = new JettyServerCustomizer[4];
|
||||
for (int i = 0; i < configurations.length; i++) {
|
||||
configurations[i] = mock(JettyServerCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(configurations, i -> mock(JettyServerCustomizer.class));
|
||||
factory.setServerCustomizers(Arrays.asList(configurations[0], configurations[1]));
|
||||
factory.addServerCustomizers(configurations[2], configurations[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
|
@ -54,9 +54,7 @@ public class TomcatReactiveWebServerFactoryTests
|
||||
public void tomcatCustomizers() {
|
||||
TomcatReactiveWebServerFactory factory = getFactory();
|
||||
TomcatContextCustomizer[] listeners = new TomcatContextCustomizer[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(TomcatContextCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(TomcatContextCustomizer.class));
|
||||
factory.setTomcatContextCustomizers(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addContextCustomizers(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer(mock(HttpHandler.class));
|
||||
@ -88,9 +86,7 @@ public class TomcatReactiveWebServerFactoryTests
|
||||
public void tomcatListeners() {
|
||||
TomcatReactiveWebServerFactory factory = getFactory();
|
||||
LifecycleListener[] listeners = new LifecycleListener[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(LifecycleListener.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(LifecycleListener.class));
|
||||
factory.setContextLifecycleListeners(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addContextLifecycleListeners(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer(mock(HttpHandler.class));
|
||||
@ -121,9 +117,7 @@ public class TomcatReactiveWebServerFactoryTests
|
||||
TomcatReactiveWebServerFactory factory = getFactory();
|
||||
HttpHandler handler = mock(HttpHandler.class);
|
||||
TomcatConnectorCustomizer[] listeners = new TomcatConnectorCustomizer[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(TomcatConnectorCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(TomcatConnectorCustomizer.class));
|
||||
factory.setTomcatConnectorCustomizers(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addConnectorCustomizers(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer(handler);
|
||||
|
@ -121,9 +121,7 @@ public class TomcatServletWebServerFactoryTests
|
||||
public void tomcatListeners() {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
LifecycleListener[] listeners = new LifecycleListener[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(LifecycleListener.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(LifecycleListener.class));
|
||||
factory.setContextLifecycleListeners(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addContextLifecycleListeners(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
@ -137,9 +135,7 @@ public class TomcatServletWebServerFactoryTests
|
||||
public void tomcatCustomizers() {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
TomcatContextCustomizer[] listeners = new TomcatContextCustomizer[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(TomcatContextCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(TomcatContextCustomizer.class));
|
||||
factory.setTomcatContextCustomizers(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addContextCustomizers(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
@ -164,9 +160,7 @@ public class TomcatServletWebServerFactoryTests
|
||||
public void tomcatConnectorCustomizers() {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
TomcatConnectorCustomizer[] listeners = new TomcatConnectorCustomizer[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
listeners[i] = mock(TomcatConnectorCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(listeners, i -> mock(TomcatConnectorCustomizer.class));
|
||||
factory.setTomcatConnectorCustomizers(Arrays.asList(listeners[0], listeners[1]));
|
||||
factory.addConnectorCustomizers(listeners[2], listeners[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
@ -180,11 +174,7 @@ public class TomcatServletWebServerFactoryTests
|
||||
public void tomcatAdditionalConnectors() {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
Connector[] listeners = new Connector[4];
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
Connector connector = mock(Connector.class);
|
||||
given(connector.getState()).willReturn(LifecycleState.STOPPED);
|
||||
listeners[i] = connector;
|
||||
}
|
||||
Arrays.setAll(listeners, i -> stoppedConnector());
|
||||
factory.addAdditionalTomcatConnectors(listeners);
|
||||
this.webServer = factory.getWebServer();
|
||||
Map<Service, Connector[]> connectors = ((TomcatWebServer) this.webServer)
|
||||
@ -193,6 +183,12 @@ public class TomcatServletWebServerFactoryTests
|
||||
.isEqualTo(listeners.length + 1);
|
||||
}
|
||||
|
||||
private Connector stoppedConnector() {
|
||||
Connector connector = mock(Connector.class);
|
||||
given(connector.getState()).willReturn(LifecycleState.STOPPED);
|
||||
return connector;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNullAdditionalConnectorThrows() {
|
||||
TomcatServletWebServerFactory factory = getFactory();
|
||||
|
@ -77,9 +77,7 @@ public class UndertowReactiveWebServerFactoryTests
|
||||
UndertowReactiveWebServerFactory factory = getFactory();
|
||||
HttpHandler handler = mock(HttpHandler.class);
|
||||
UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4];
|
||||
for (int i = 0; i < customizers.length; i++) {
|
||||
customizers[i] = mock(UndertowBuilderCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(customizers, i -> mock(UndertowBuilderCustomizer.class));
|
||||
factory.setBuilderCustomizers(Arrays.asList(customizers[0], customizers[1]));
|
||||
factory.addBuilderCustomizers(customizers[2], customizers[3]);
|
||||
this.webServer = factory.getWebServer(handler);
|
||||
|
@ -102,9 +102,7 @@ public class UndertowServletWebServerFactoryTests
|
||||
public void builderCustomizers() {
|
||||
UndertowServletWebServerFactory factory = getFactory();
|
||||
UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4];
|
||||
for (int i = 0; i < customizers.length; i++) {
|
||||
customizers[i] = mock(UndertowBuilderCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(customizers, i -> mock(UndertowBuilderCustomizer.class));
|
||||
factory.setBuilderCustomizers(Arrays.asList(customizers[0], customizers[1]));
|
||||
factory.addBuilderCustomizers(customizers[2], customizers[3]);
|
||||
this.webServer = factory.getWebServer();
|
||||
@ -134,9 +132,7 @@ public class UndertowServletWebServerFactoryTests
|
||||
public void deploymentInfo() {
|
||||
UndertowServletWebServerFactory factory = getFactory();
|
||||
UndertowDeploymentInfoCustomizer[] customizers = new UndertowDeploymentInfoCustomizer[4];
|
||||
for (int i = 0; i < customizers.length; i++) {
|
||||
customizers[i] = mock(UndertowDeploymentInfoCustomizer.class);
|
||||
}
|
||||
Arrays.setAll(customizers, i -> mock(UndertowDeploymentInfoCustomizer.class));
|
||||
factory.setDeploymentInfoCustomizers(
|
||||
Arrays.asList(customizers[0], customizers[1]));
|
||||
factory.addDeploymentInfoCustomizers(customizers[2], customizers[3]);
|
||||
|
@ -305,9 +305,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
public void multipleConfigurations() throws Exception {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
ServletContextInitializer[] initializers = new ServletContextInitializer[6];
|
||||
for (int i = 0; i < initializers.length; i++) {
|
||||
initializers[i] = mock(ServletContextInitializer.class);
|
||||
}
|
||||
Arrays.setAll(initializers, i -> mock(ServletContextInitializer.class));
|
||||
factory.setInitializers(Arrays.asList(initializers[2], initializers[3]));
|
||||
factory.addInitializers(initializers[4], initializers[5]);
|
||||
this.webServer = factory.getWebServer(initializers[0], initializers[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user