Polishing (collapsed if checks, consistent downcasts, refined javadoc)
This commit is contained in:
@@ -31,9 +31,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.springframework.test.util.AssertionErrors.assertEquals;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.springframework.test.util.AssertionErrors.*;
|
||||
|
||||
/**
|
||||
* Static factory methods for {@link RequestMatcher} classes. Typically used to
|
||||
@@ -142,16 +141,17 @@ public abstract class MockRestRequestMatchers {
|
||||
return UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams();
|
||||
}
|
||||
|
||||
private static void assertValueCount(String valueType, final String name,
|
||||
MultiValueMap<String, String> map, int count) {
|
||||
private static void assertValueCount(
|
||||
String valueType, final String name, MultiValueMap<String, String> map, int count) {
|
||||
|
||||
List<String> values = map.get(name);
|
||||
|
||||
String message = "Expected " + valueType + " <" + name + ">";
|
||||
assertTrue(message + " to exist but was null", values != null);
|
||||
|
||||
assertTrue(message + " to have at least <" + count + "> values but found " + values,
|
||||
count <= values.size());
|
||||
if (values == null) {
|
||||
fail(message + " to exist but was null");
|
||||
}
|
||||
if (count > values.size()) {
|
||||
fail(message + " to have at least <" + count + "> values but found " + values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,8 +178,7 @@ public abstract class MockRestRequestMatchers {
|
||||
List<String> headerValues = request.getHeaders().get(name);
|
||||
Assert.state(headerValues != null, "No header values");
|
||||
for (int i = 0; i < expectedValues.length; i++) {
|
||||
assertEquals("Request header [" + name + "]",
|
||||
expectedValues[i], headerValues.get(i));
|
||||
assertEquals("Request header [" + name + "]", expectedValues[i], headerValues.get(i));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -127,15 +127,13 @@ public final class MockMvc {
|
||||
* @param requestBuilder used to prepare the request to execute;
|
||||
* see static factory methods in
|
||||
* {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders}
|
||||
* @return an instance of {@link ResultActions}; never {@code null}
|
||||
* @return an instance of {@link ResultActions} (never {@code null})
|
||||
* @see org.springframework.test.web.servlet.request.MockMvcRequestBuilders
|
||||
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||
*/
|
||||
public ResultActions perform(RequestBuilder requestBuilder) throws Exception {
|
||||
if (this.defaultRequestBuilder != null) {
|
||||
if (requestBuilder instanceof Mergeable) {
|
||||
requestBuilder = (RequestBuilder) ((Mergeable) requestBuilder).merge(this.defaultRequestBuilder);
|
||||
}
|
||||
if (this.defaultRequestBuilder != null && requestBuilder instanceof Mergeable) {
|
||||
requestBuilder = (RequestBuilder) ((Mergeable) requestBuilder).merge(this.defaultRequestBuilder);
|
||||
}
|
||||
|
||||
MockHttpServletRequest request = requestBuilder.buildRequest(this.servletContext);
|
||||
@@ -199,9 +197,7 @@ public final class MockMvc {
|
||||
return (MockHttpServletResponse) servletResponse;
|
||||
}
|
||||
|
||||
|
||||
private void applyDefaultResultActions(MvcResult mvcResult) throws Exception {
|
||||
|
||||
for (ResultMatcher matcher : this.defaultResultMatchers) {
|
||||
matcher.match(mvcResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user