RestImpl { void getUserDirectMessageList(final SimpleListCallback<Subscription> callback) { checkNotNull(callback, "callback == null"); HttpUrl httpUrl = requestUrl(baseUrl, getRestApiMethodNameByRoomType(BaseRoom.RoomType.ONE_TO_ONE, "list")) .build(); Request request = requestBuilder(httpUrl) .get() .build(); client.newCall(request).enqueue(new okhttp3.Callback() { @Override public void onFailure(Call call, IOException e) { callback.onError(new RocketChatNetworkErrorException("network error", e)); } @Override public void onResponse(Call call, Response response) throws IOException { if (!response.isSuccessful()) { processCallbackError(response, ERROR_HANDLER(callback)); return; } try { JSONObject json = new JSONObject(response.body().string()); logger.info("Response = " + json.toString()); Type type = Types.newParameterizedType(List.class, Subscription.class); JsonAdapter<List<Subscription>> adapter = moshi.adapter(type); List<Subscription> subscriptionList = adapter.fromJson(json.getJSONArray("ims").toString()); callback.onSuccess(subscriptionList); } catch (JSONException e) { callback.onError(new RocketChatInvalidResponseException(e.getMessage(), e)); } } }); } RestImpl(OkHttpClient client, Moshi moshi, HttpUrl baseUrl, TokenProvider tokenProvider, Logger logger);   }
@Test(expected = NullPointerException.class) public void testUserDirectMessagelListShouldFailWithNullCallback() { rest.getUserDirectMessageList(null); }
@Test public void testUserDirectMessagelListShouldBeSuccessful() { mockServer.expect() .get() .withPath("/api/v1/dm.list") .andReturn(200, "{" + " \"success\":true," + " \"ims\":[" + " {" + " \"msgs\":90," + " \"lm\":\"2017-09-29T14:43:54.207Z\"," + " \"t\":\"d\"," + " \"usernames\":[" + " \"user1\"," + " \"user2\"" + " ]," + " \"_id\":\"0WCaFa2Jve4FEjMYacBD6dHcSoBvGjkrzM\"," + " \"_updatedAt\":\"2017-09-29T14:43:54.286Z\"," + " \"ts\":\"2017-08-15T17:56:09.013Z\"" + " }," + " {" + " \"msgs\":2," + " \"lm\":\"2017-08-18T18:01:33.580Z\"," + " \"t\":\"d\"," + " \"usernames\":[" + " \"user1\"," + " \"user3\"" + " ]," + " \"_id\":\"0WCaFa2Jve4FEjMYacBD6dHcIoBEGjJszO\"," + " \"_updatedAt\":\"2017-08-18T18:01:33.667Z\"," + " \"ts\":\"2017-08-18T18:00:57.369Z\"" + " }" + " ]" + "}") .once(); rest.getUserDirectMessageList(simpleListCallback); verify(simpleListCallback, timeout(DEFAULT_TIMEOUT).only()) .onSuccess(listCaptor.capture()); List<Subscription> subscriptionList = listCaptor.getValue(); assertThat(subscriptionList, is(notNullValue())); assertThat(subscriptionList.size(), is(equalTo(2))); Subscription subscription = subscriptionList.get(0); assertThat(subscription.roomId(), is(equalTo("0WCaFa2Jve4FEjMYacBD6dHcSoBvGjkrzM"))); assertThat(subscription.type(), is(equalTo(BaseRoom.RoomType.ONE_TO_ONE))); }