[英]How to test DropWizard resource that returns a collection of objects?
我正在使用DropWizard构建服务。 我有一个端点,预计会返回List<Person>
我的单元测试看起来像:
@Test
public void testGetListOfPeople() {
assertThat(
resources.client().target("/people/?age=10").request().get(ArrayList<Person>.class))
.containsAll(expectedList);
}
但是, request().get
将不允许我指定参数化集合。
我已尝试直接获得响应:
r = resources.client().target("/people/?age=10").request().get()
但后来我不清楚如何将r
转换为List<Person>
如何更新此测试?
是的,拥有收藏品的泽西岛客户可能有点令人沮丧。 解决方案很简单,只需执行以下操作:
import javax.ws.rs.core.GenericType;
resources.client().target("/people/?age=10").request()
.get(new GenericType<List<Person>>(){});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.