Fix typos in RequestResultMatchers
This commit is contained in:
@@ -36,23 +36,23 @@ import static org.springframework.test.util.AssertionErrors.*;
|
|||||||
* {@link MockMvcResultMatchers#request}.
|
* {@link MockMvcResultMatchers#request}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class RequestResultMatchers {
|
public class RequestResultMatchers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protected constructor.
|
* Protected constructor.
|
||||||
* Use {@link MockMvcResultMatchers#request()}.
|
* <p>Use {@link MockMvcResultMatchers#request()}.
|
||||||
*/
|
*/
|
||||||
protected RequestResultMatchers() {
|
protected RequestResultMatchers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert a request attribute value with the given Hamcrest {@link Matcher}.
|
* Assert whether asynchronous processing started, usually as a result of a
|
||||||
* Whether asynchronous processing started, usually as a result of a
|
|
||||||
* controller method returning {@link Callable} or {@link DeferredResult}.
|
* 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.
|
* {@link #asyncResult(Matcher)} can be used to assert the resulting value.
|
||||||
* Neither a {@code Callable} nor a {@code DeferredResult} will complete
|
* Neither a {@code Callable} nor a {@code DeferredResult} will complete
|
||||||
* processing all the way since a {@link MockHttpServletRequest} does not
|
* processing all the way since a {@link MockHttpServletRequest} does not
|
||||||
@@ -63,13 +63,13 @@ public class RequestResultMatchers {
|
|||||||
@Override
|
@Override
|
||||||
public void match(MvcResult result) {
|
public void match(MvcResult result) {
|
||||||
HttpServletRequest request = result.getRequest();
|
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()
|
* @see #asyncStarted()
|
||||||
*/
|
*/
|
||||||
public ResultMatcher asyncNotStarted() {
|
public ResultMatcher asyncNotStarted() {
|
||||||
@@ -84,6 +84,8 @@ public class RequestResultMatchers {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert the result from asynchronous processing with the given matcher.
|
* 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) {
|
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
|
||||||
return new ResultMatcher() {
|
return new ResultMatcher() {
|
||||||
@@ -91,7 +93,7 @@ public class RequestResultMatchers {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void match(MvcResult result) {
|
public void match(MvcResult result) {
|
||||||
HttpServletRequest request = result.getRequest();
|
HttpServletRequest request = result.getRequest();
|
||||||
assertEquals("Async started", true, request.isAsyncStarted());
|
assertAsyncStarted(request);
|
||||||
assertThat("Async result", (T) result.getAsyncResult(), matcher);
|
assertThat("Async result", (T) result.getAsyncResult(), matcher);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -99,7 +101,7 @@ public class RequestResultMatchers {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert the result from asynchronous processing.
|
* 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
|
* or {@link WebAsyncTask}. The value matched is the value returned from the
|
||||||
* {@code Callable} or the exception raised.
|
* {@code Callable} or the exception raised.
|
||||||
*/
|
*/
|
||||||
@@ -108,7 +110,7 @@ public class RequestResultMatchers {
|
|||||||
@Override
|
@Override
|
||||||
public void match(MvcResult result) {
|
public void match(MvcResult result) {
|
||||||
HttpServletRequest request = result.getRequest();
|
HttpServletRequest request = result.getRequest();
|
||||||
assertEquals("Async started", true, request.isAsyncStarted());
|
assertAsyncStarted(request);
|
||||||
assertEquals("Async result", expectedResult, result.getAsyncResult());
|
assertEquals("Async result", expectedResult, result.getAsyncResult());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -149,21 +151,25 @@ public class RequestResultMatchers {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void match(MvcResult result) {
|
public void match(MvcResult result) {
|
||||||
T value = (T) result.getRequest().getSession().getAttribute(name);
|
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) {
|
public <T> ResultMatcher sessionAttribute(final String name, final Object value) {
|
||||||
return new ResultMatcher() {
|
return new ResultMatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void match(MvcResult result) {
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user