LastfmClient { public void updateNowPlaying(com.peterjosling.scroball.Track track, Handler.Callback callback) { int now = (int) System.currentTimeMillis() / 1000; new UpdateNowPlayingTask(api, session, callback).execute(getScrobbleData(track, now)); } LastfmClient(LastfmApi api, Caller caller, String userAgent, String sessionKey);  LastfmClient(LastfmApi api, Caller caller, String userAgent); boolean isAuthenticated(); Uri getAuthUrl(); void getSession(String token, Handler.Callback callback); void updateNowPlaying(com.peterjosling.scroball.Track track, Handler.Callback callback); void scrobbleTracks(List<Scrobble> scrobbles, Handler.Callback callback); void getTrackInfo(com.peterjosling.scroball.Track track, Handler.Callback callback); void loveTrack(com.peterjosling.scroball.Track track, Handler.Callback callback); void clearSession(); static boolean isTransientError(int errorCode); static boolean isAuthenticationError(int errorCode); static final int ERROR_NO_ERROR; static final int ERROR_UNKNOWN; static final int ERROR_OPERATION_FAILED; static final int ERROR_INVALID_SESSION; static final int ERROR_SERVICE_OFFLINE; static final int ERROR_UNAUTHORIZED_TOKEN; static final int ERROR_SERVICE_TEMPORARILY_UNAVAILABLE; static final ImmutableSet<Integer> TRANSIENT_ERROR_CODES; }
@Test public void updateNowPlaying_returnsResultOnSuccess() { String track = "My Track"; String artist = "Some Artist"; when(lastfmApi.updateNowPlaying(any(), any())).thenReturn(scrobbleResult); when(scrobbleResult.isSuccessful()).thenReturn(true); client.updateNowPlaying(Track.builder().track(track).artist(artist).build(), callback); ScrobbleData expectedScrobbleData = new ScrobbleData(); expectedScrobbleData.setTrack(track); expectedScrobbleData.setArtist(artist); verify(lastfmApi).updateNowPlaying(refEq(expectedScrobbleData, "timestamp"), refEq(session)); verify(callback) .handleMessage(argThat(message -> ((LastfmClient.Result) message.obj).isSuccessful())); }
@Test public void updateNowPlaying_returnsResultOnNullResponse() { String track = "My Track"; String artist = "Some Artist"; when(lastfmApi.updateNowPlaying(any(), any())).thenReturn(null); client.updateNowPlaying(Track.builder().track(track).artist(artist).build(), callback); verify(callback) .handleMessage(argThat(message -> !((LastfmClient.Result) message.obj).isSuccessful())); }
@Test public void updateNowPlaying_returnsResultOnError() { String track = "My Track"; String artist = "Some Artist"; when(lastfmApi.updateNowPlaying(any(), any())).thenReturn(scrobbleResult); when(scrobbleResult.isSuccessful()).thenReturn(false); when(scrobbleResult.getErrorCode()).thenReturn(LastfmClient.ERROR_OPERATION_FAILED); client.updateNowPlaying(Track.builder().track(track).artist(artist).build(), callback); verify(callback) .handleMessage(argThat(message -> !((LastfmClient.Result) message.obj).isSuccessful())); }