Browse Source

Remove a couple more dependencies on hamcrest-lib

Issue: SPR-9961
pull/180/head
Rossen Stoyanchev 14 years ago
parent
commit
9e22ac496d
  1. 20
      spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java
  2. 17
      spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java

20
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java

@ -16,11 +16,6 @@ @@ -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 class JsonPathResultMatchers { @@ -64,8 +59,12 @@ public class JsonPathResultMatchers {
/**
* 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 class JsonPathResultMatchers { @@ -96,6 +95,11 @@ public class JsonPathResultMatchers {
* 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);
}
};
}
}

17
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java

@ -16,7 +16,6 @@ @@ -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 class RequestResultMatchers { @@ -62,7 +61,7 @@ public class RequestResultMatchers {
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 class RequestResultMatchers { @@ -75,7 +74,7 @@ public class RequestResultMatchers {
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 class RequestResultMatchers { @@ -88,7 +87,7 @@ public class RequestResultMatchers {
@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 class RequestResultMatchers { @@ -100,8 +99,14 @@ public class RequestResultMatchers {
* 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());
}
};
}
/**

Loading…
Cancel
Save