From 7528b9487d15fcdb4fbf86714bee32a99a0bed23 Mon Sep 17 00:00:00 2001 From: Hyunjin Choi Date: Thu, 20 Feb 2020 01:28:22 +0900 Subject: [PATCH] Simplify code in spring-test by using Collections.addAll Closes gh-24555 --- .../test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java | 7 +++---- .../htmlunit/MockMvcWebConnectionBuilderSupport.java | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java index e6a9f9f68ff..6308d61603d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -22,6 +22,7 @@ import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Locale; @@ -291,9 +292,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable { Cookie[] parentCookies = request.getCookies(); if (parentCookies != null) { - for (Cookie cookie : parentCookies) { - cookies.add(cookie); - } + Collections.addAll(cookies, parentCookies); } if (!ObjectUtils.isEmpty(cookies)) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java index fa343d4fd51..fa4418e5232 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionBuilderSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,6 +17,7 @@ package org.springframework.test.web.servlet.htmlunit; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.gargoylesoftware.htmlunit.WebClient; @@ -118,9 +119,7 @@ public abstract class MockMvcWebConnectionBuilderSupport