Merge pull request #11809 from izeye:parameter-name
* pr/11809: Polish contribution Fix to assert parameter names in EndpointServlet.withInitParameters()
This commit is contained in:
commit
c533cb28bc
|
|
@ -61,9 +61,9 @@ public final class EndpointServlet {
|
||||||
|
|
||||||
public EndpointServlet withInitParameters(Map<String, String> initParameters) {
|
public EndpointServlet withInitParameters(Map<String, String> initParameters) {
|
||||||
Assert.notNull(initParameters, "InitParameters must not be null");
|
Assert.notNull(initParameters, "InitParameters must not be null");
|
||||||
boolean hasEmptyKey = initParameters.values().stream()
|
boolean hasEmptyName = initParameters.keySet().stream()
|
||||||
.anyMatch((key) -> !StringUtils.hasText(key));
|
.anyMatch((name) -> !StringUtils.hasText(name));
|
||||||
Assert.isTrue(!hasEmptyKey, "InitParameters must not contain empty keys");
|
Assert.isTrue(!hasEmptyName, "InitParameters must not contain empty names");
|
||||||
Map<String, String> mergedInitParameters = new LinkedHashMap<>(
|
Map<String, String> mergedInitParameters = new LinkedHashMap<>(
|
||||||
this.initParameters);
|
this.initParameters);
|
||||||
mergedInitParameters.putAll(initParameters);
|
mergedInitParameters.putAll(initParameters);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.entry;
|
||||||
* Tests for {@link EndpointServlet}.
|
* Tests for {@link EndpointServlet}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class EndpointServletTests {
|
public class EndpointServletTests {
|
||||||
|
|
||||||
|
|
@ -71,6 +72,20 @@ public class EndpointServletTests {
|
||||||
assertThat(endpointServlet.getServlet()).isEqualTo(servlet);
|
assertThat(endpointServlet.getServlet()).isEqualTo(servlet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withInitParameterNullName() {
|
||||||
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
|
this.thrown.expect(IllegalArgumentException.class);
|
||||||
|
endpointServlet.withInitParameters(Collections.singletonMap(null, "value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withInitParameterEmptyName() {
|
||||||
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
|
this.thrown.expect(IllegalArgumentException.class);
|
||||||
|
endpointServlet.withInitParameters(Collections.singletonMap(" ", "value"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withInitParameterShouldReturnNewInstance() {
|
public void withInitParameterShouldReturnNewInstance() {
|
||||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue