提交 bb514478 编写于 作者: S Sam Brannen

Fix typos in RequestResultMatchers

上级 f06581f5
......@@ -36,23 +36,23 @@ import static org.springframework.test.util.AssertionErrors.*;
* {@link MockMvcResultMatchers#request}.
*
* @author Rossen Stoyanchev
* @author Sam Brannen
* @since 3.2
*/
public class RequestResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#request()}.
* <p>Use {@link MockMvcResultMatchers#request()}.
*/
protected RequestResultMatchers() {
}
/**
* Assert a request attribute value with the given Hamcrest {@link Matcher}.
* Whether asynchronous processing started, usually as a result of a
* Assert whether asynchronous processing started, usually as a result of a
* controller method returning {@link Callable} or {@link DeferredResult}.
* The test will await the completion of a {@code Callable} so that
* <p>The test will await the completion of a {@code Callable} so that
* {@link #asyncResult(Matcher)} can be used to assert the resulting value.
* Neither a {@code Callable} nor a {@code DeferredResult} will complete
* processing all the way since a {@link MockHttpServletRequest} does not
......@@ -63,13 +63,13 @@ public class RequestResultMatchers {
@Override
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
assertEquals("Async started", true, request.isAsyncStarted());
assertAsyncStarted(request);
}
};
}
/**
* Assert that asynchronous processing was not start.
* Assert that asynchronous processing was not started.
* @see #asyncStarted()
*/
public ResultMatcher asyncNotStarted() {
......@@ -84,6 +84,8 @@ public class RequestResultMatchers {
/**
* Assert the result from asynchronous processing with the given matcher.
* <p>This method can be used when a controller method returns {@link Callable}
* or {@link WebAsyncTask}.
*/
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
return new ResultMatcher() {
......@@ -91,7 +93,7 @@ public class RequestResultMatchers {
@SuppressWarnings("unchecked")
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
assertEquals("Async started", true, request.isAsyncStarted());
assertAsyncStarted(request);
assertThat("Async result", (T) result.getAsyncResult(), matcher);
}
};
......@@ -99,7 +101,7 @@ public class RequestResultMatchers {
/**
* Assert the result from asynchronous processing.
* This method can be used when a controller method returns {@link Callable}
* <p>This method can be used when a controller method returns {@link Callable}
* or {@link WebAsyncTask}. The value matched is the value returned from the
* {@code Callable} or the exception raised.
*/
......@@ -108,7 +110,7 @@ public class RequestResultMatchers {
@Override
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
assertEquals("Async started", true, request.isAsyncStarted());
assertAsyncStarted(request);
assertEquals("Async result", expectedResult, result.getAsyncResult());
}
};
......@@ -149,21 +151,25 @@ public class RequestResultMatchers {
@SuppressWarnings("unchecked")
public void match(MvcResult result) {
T value = (T) result.getRequest().getSession().getAttribute(name);
assertThat("Request attribute", value, matcher);
assertThat("Session attribute", value, matcher);
}
};
}
/**
* Assert a session attribute value..
* Assert a session attribute value.
*/
public <T> ResultMatcher sessionAttribute(final String name, final Object value) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertEquals("Request attribute", value, result.getRequest().getSession().getAttribute(name));
assertEquals("Session attribute", value, result.getRequest().getSession().getAttribute(name));
}
};
}
private static void assertAsyncStarted(HttpServletRequest request) {
assertEquals("Async started", true, request.isAsyncStarted());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册