@Test public void shouldAddToMySavedTracks_sync() throws Exception { final String accessToken = "someAccessToken"; final Api api = Api.builder().accessToken(accessToken).build(); final List<String> tracksToAdd = Arrays.asList("4BYGxv4rxSNcTgT3DsFB9o", "0BG2iE6McPhmAEKIhfqy1X"); final AddToMySavedTracksRequest request = api.addToMySavedTracks(tracksToAdd) .httpManager(TestUtil.MockedHttpManager.returningString("")) .build(); final String addTrackResponse = request.get(); assertEquals("", addTrackResponse); }
@Test public void shouldAddToMySavedTracks_async() throws Exception { final String accessToken = "someAccessToken"; final Api api = Api.builder().accessToken(accessToken).build(); final List<String> tracksToAdd = Arrays.asList("4BYGxv4rxSNcTgT3DsFB9o", "0BG2iE6McPhmAEKIhfqy1X"); final AddToMySavedTracksRequest request = api.addToMySavedTracks(tracksToAdd) .httpManager(TestUtil.MockedHttpManager.returningString("")) .build(); final CountDownLatch asyncCompleted = new CountDownLatch(1); final SettableFuture<String> addTrackFuture = request.getAsync(); Futures.addCallback( addTrackFuture, new FutureCallback<String>() { @Override public void onSuccess(String response) { assertEquals("", response); asyncCompleted.countDown(); } @Override public void onFailure(Throwable throwable) { fail("Failed to resolve future: " + throwable.getMessage()); } }); asyncCompleted.await(1, TimeUnit.SECONDS); }