Skip to content

Commit 9e22ac4

Browse files
committed
Remove a couple more dependencies on hamcrest-lib
Issue: SPR-9961
1 parent 4812fcc commit 9e22ac4

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
package org.springframework.test.web.servlet.result;
1818

19-
import static org.hamcrest.Matchers.equalTo;
20-
import static org.hamcrest.Matchers.instanceOf;
21-
22-
import java.util.List;
23-
2419
import org.hamcrest.Matcher;
2520
import org.springframework.test.util.JsonPathExpectationsHelper;
2621
import org.springframework.test.web.servlet.MvcResult;
@@ -64,8 +59,12 @@ public void match(MvcResult result) throws Exception {
6459
/**
6560
* Evaluate the JSONPath and assert the value of the content found.
6661
*/
67-
public ResultMatcher value(Object value) {
68-
return value(equalTo(value));
62+
public ResultMatcher value(final Object expectedValue) {
63+
return new ResultMatcher() {
64+
public void match(MvcResult result) throws Exception {
65+
jsonPathHelper.assertValue(result.getResponse().getContentAsString(), expectedValue);
66+
}
67+
};
6968
}
7069

7170
/**
@@ -96,6 +95,11 @@ public void match(MvcResult result) throws Exception {
9695
* Evluate the JSON path and assert the content found is an array.
9796
*/
9897
public ResultMatcher isArray() {
99-
return value(instanceOf(List.class));
98+
return new ResultMatcher() {
99+
public void match(MvcResult result) throws Exception {
100+
String content = result.getResponse().getContentAsString();
101+
jsonPathHelper.assertValueIsArray(content);
102+
}
103+
};
100104
}
101105
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.test.web.servlet.result;
1818

19-
import static org.hamcrest.Matchers.equalTo;
2019
import static org.springframework.test.util.AssertionErrors.assertEquals;
2120
import static org.springframework.test.util.MatcherAssertionErrors.assertThat;
2221

@@ -62,7 +61,7 @@ public ResultMatcher asyncStarted() {
6261
return new ResultMatcher() {
6362
public void match(MvcResult result) {
6463
HttpServletRequest request = result.getRequest();
65-
assertThat("Async started", request.isAsyncStarted(), equalTo(true));
64+
assertEquals("Async started", true, request.isAsyncStarted());
6665
}
6766
};
6867
}
@@ -75,7 +74,7 @@ public ResultMatcher asyncNotStarted() {
7574
return new ResultMatcher() {
7675
public void match(MvcResult result) {
7776
HttpServletRequest request = result.getRequest();
78-
assertThat("Async started", request.isAsyncStarted(), equalTo(false));
77+
assertEquals("Async started", false, request.isAsyncStarted());
7978
}
8079
};
8180
}
@@ -88,7 +87,7 @@ public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
8887
@SuppressWarnings("unchecked")
8988
public void match(MvcResult result) {
9089
HttpServletRequest request = result.getRequest();
91-
assertThat("Async started", request.isAsyncStarted(), equalTo(true));
90+
assertEquals("Async started", true, request.isAsyncStarted());
9291
assertThat("Async result", (T) result.getAsyncResult(), matcher);
9392
}
9493
};
@@ -100,8 +99,14 @@ public void match(MvcResult result) {
10099
* or {@link MvcAsyncTask}. The value matched is the value returned from the
101100
* {@code Callable} or the exception raised.
102101
*/
103-
public <T> ResultMatcher asyncResult(Object expectedResult) {
104-
return asyncResult(equalTo(expectedResult));
102+
public <T> ResultMatcher asyncResult(final Object expectedResult) {
103+
return new ResultMatcher() {
104+
public void match(MvcResult result) {
105+
HttpServletRequest request = result.getRequest();
106+
assertEquals("Async started", true, request.isAsyncStarted());
107+
assertEquals("Async result", expectedResult, result.getAsyncResult());
108+
}
109+
};
105110
}
106111

107112
/**

0 commit comments

Comments
 (0)