Permalink
Browse files

Remove a couple more dependencies on hamcrest-lib

Issue: SPR-9961
  • Loading branch information...
1 parent 4812fcc commit 9e22ac496d684d922bda21acea800e4f0ef88cb1 @rstoyanchev rstoyanchev committed Nov 7, 2012
@@ -16,11 +16,6 @@
package org.springframework.test.web.servlet.result;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-
-import java.util.List;
-
import org.hamcrest.Matcher;
import org.springframework.test.util.JsonPathExpectationsHelper;
import org.springframework.test.web.servlet.MvcResult;
@@ -64,8 +59,12 @@ public void match(MvcResult result) throws Exception {
/**
* Evaluate the JSONPath and assert the value of the content found.
*/
- public ResultMatcher value(Object value) {
- return value(equalTo(value));
+ public ResultMatcher value(final Object expectedValue) {
+ return new ResultMatcher() {
+ public void match(MvcResult result) throws Exception {
+ jsonPathHelper.assertValue(result.getResponse().getContentAsString(), expectedValue);
+ }
+ };
}
/**
@@ -96,6 +95,11 @@ public void match(MvcResult result) throws Exception {
* Evluate the JSON path and assert the content found is an array.
*/
public ResultMatcher isArray() {
- return value(instanceOf(List.class));
+ return new ResultMatcher() {
+ public void match(MvcResult result) throws Exception {
+ String content = result.getResponse().getContentAsString();
+ jsonPathHelper.assertValueIsArray(content);
+ }
+ };
}
}
@@ -16,7 +16,6 @@
package org.springframework.test.web.servlet.result;
-import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.util.AssertionErrors.assertEquals;
import static org.springframework.test.util.MatcherAssertionErrors.assertThat;
@@ -62,7 +61,7 @@ public ResultMatcher asyncStarted() {
return new ResultMatcher() {
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
- assertThat("Async started", request.isAsyncStarted(), equalTo(true));
+ assertEquals("Async started", true, request.isAsyncStarted());
}
};
}
@@ -75,7 +74,7 @@ public ResultMatcher asyncNotStarted() {
return new ResultMatcher() {
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
- assertThat("Async started", request.isAsyncStarted(), equalTo(false));
+ assertEquals("Async started", false, request.isAsyncStarted());
}
};
}
@@ -88,7 +87,7 @@ public void match(MvcResult result) {
@SuppressWarnings("unchecked")
public void match(MvcResult result) {
HttpServletRequest request = result.getRequest();
- assertThat("Async started", request.isAsyncStarted(), equalTo(true));
+ assertEquals("Async started", true, request.isAsyncStarted());
assertThat("Async result", (T) result.getAsyncResult(), matcher);
}
};
@@ -100,8 +99,14 @@ public void match(MvcResult result) {
* or {@link MvcAsyncTask}. The value matched is the value returned from the
* {@code Callable} or the exception raised.
*/
- public <T> ResultMatcher asyncResult(Object expectedResult) {
- return asyncResult(equalTo(expectedResult));
+ public <T> ResultMatcher asyncResult(final Object expectedResult) {
+ return new ResultMatcher() {
+ public void match(MvcResult result) {
+ HttpServletRequest request = result.getRequest();
+ assertEquals("Async started", true, request.isAsyncStarted());
+ assertEquals("Async result", expectedResult, result.getAsyncResult());
+ }
+ };
}
/**

0 comments on commit 9e22ac4

Please sign in to comment.