forked from JavaOPs/topjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtil.java
More file actions
26 lines (20 loc) · 1 KB
/
Copy pathTestUtil.java
File metadata and controls
26 lines (20 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package ru.javawebinar.topjava;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import ru.javawebinar.topjava.web.json.JsonUtil;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class TestUtil {
public static String getContent(MvcResult result) throws UnsupportedEncodingException {
return result.getResponse().getContentAsString();
}
public static <T> T readFromJson(ResultActions action, Class<T> clazz) throws UnsupportedEncodingException {
return JsonUtil.readValue(getContent(action.andReturn()), clazz);
}
public static <T> T readFromJsonMvcResult(MvcResult result, Class<T> clazz) throws UnsupportedEncodingException {
return JsonUtil.readValue(getContent(result), clazz);
}
public static <T> List<T> readListFromJsonMvcResult(MvcResult result, Class<T> clazz) throws UnsupportedEncodingException {
return JsonUtil.readValues(getContent(result), clazz);
}
}