[英]How to test DropWizard resource that returns a collection of objects?
I'm building a service using DropWizard. 我正在使用DropWizard构建服务。 I have a endpoint that is expected to return a
List<Person>
我有一个端点,预计会返回
List<Person>
My unit tests looks like: 我的单元测试看起来像:
@Test
public void testGetListOfPeople() {
assertThat(
resources.client().target("/people/?age=10").request().get(ArrayList<Person>.class))
.containsAll(expectedList);
}
However, request().get
won't allow me to specify a parameterized collection. 但是,
request().get
将不允许我指定参数化集合。
I've tried getting the response directly with: 我已尝试直接获得响应:
r = resources.client().target("/people/?age=10").request().get()
but then its not clear how I convert r
into a List<Person>
但后来我不清楚如何将
r
转换为List<Person>
How can I update this test to work? 如何更新此测试?
Yes, the Jersey client with collections can be a little frustrating. 是的,拥有收藏品的泽西岛客户可能有点令人沮丧。 The solution is easy though, simply do the following:
解决方案很简单,只需执行以下操作:
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.