[英]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.