@Test
public void listCollections() throws Exception {
// GIVEN a fake remote kinto url
String remote = "https://fake.kinto.url";
// AND expected headers
Map<String, List<String>> expectedHeaders = new HashMap<>(defaultHeaders);
// AND a kintoClient
KintoClient kintoClient = spy(new KintoClient(remote));
// AND a mocked kintoClient
doAnswer(new Answer<JSONObject>() {
public JSONObject answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
GetRequest getRequest = (GetRequest)args[0];
// THEN the correct endpoint is called
assertThat(getRequest.getUrl(), is(remote + "/buckets/bucketName/collections"));
// AND headers are corrects
assertThat(getRequest.getHeaders(), is(expectedHeaders));
// AND the get method is used
assertThat(getRequest.getHttpMethod(), is(HttpMethod.GET));
return new JSONObject("{data:[{id: \"col1\"},{id:\"col2\"}]}");
}
})
.when(kintoClient)
.execute(any(GetRequest.class));
// WHEN calling listBuckets
Set<Collection> collections = kintoClient.bucket("bucketName").listCollections();
// THEN check if the answer is correctly called by checking the result
assertThat(collections.size(), is(2));
}
BucketTest.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:kinto-http-java
作者:
评论列表
文章目录