LastfmClient { public void getSession(String token, Handler.Callback callback) { new GetSessionTask( api, caller, message -> { AuthResult result = (AuthResult) message.obj; if (result.sessionKey().isPresent()) { setSession(result.sessionKey().get()); } callback.handleMessage(message); return true; }) .execute(token); } 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 getSession_returnsErrorResultData() { int errorCode = 123; int httpErrorCode = 456; String error = "error"; AuthResult expectedResult = AuthResult.builder().errorCode(errorCode).httpErrorCode(httpErrorCode).error(error).build(); when(lastfmApi.getSession(any(), any(), any())).thenReturn(null); when(caller.getLastResult()).thenReturn(result); when(result.isSuccessful()).thenReturn(false); when(result.getErrorCode()).thenReturn(errorCode); when(result.getHttpErrorCode()).thenReturn(httpErrorCode); when(result.getErrorMessage()).thenReturn(error); client = new LastfmClient(lastfmApi, caller, "test"); client.getSession("abc", callback); verify(callback).handleMessage(argThat(message -> expectedResult.equals(message.obj))); }