### Question:
SessionClientImpl implements SessionClient { @Override public void authorizedRequest(@NonNull Uri uri, @Nullable Map<String, String> properties, @Nullable Map<String, String> postParameters, @NonNull ConnectionParameters.RequestMethod method, final RequestCallback<JSONObject, AuthorizationException> cb) { cancelFuture(); mFutureTask = mDispatcher.submit(() -> { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); try { JSONObject result = mSyncSessionClient .authorizedRequest(uri, properties, postParameters, method); mDispatcher.submitResults(() -> cb.onSuccess(result)); } catch (AuthorizationException ae) { mDispatcher.submitResults(() -> cb.onError(ae.error, ae)); } catch (Exception ex) { mDispatcher.submitResults(() -> cb.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex))); } }); } SessionClientImpl(Executor callbackExecutor, SyncSessionClient syncSessionClient); void getUserProfile(final RequestCallback<UserInfo, AuthorizationException> cb); void introspectToken(String token, String tokenType,
                                final RequestCallback<IntrospectInfo, AuthorizationException> cb); void revokeToken(String token,
                            final RequestCallback<Boolean, AuthorizationException> cb); void refreshToken(final RequestCallback<Tokens, AuthorizationException> cb); @Override Tokens getTokens(); @Override void authorizedRequest(@NonNull Uri uri, @Nullable Map<String, String> properties,
                                  @Nullable Map<String, String> postParameters,
                                  @NonNull ConnectionParameters.RequestMethod method,
                                  final RequestCallback<JSONObject, AuthorizationException> cb); boolean isAuthenticated(); void clear(); @Override void cancel(); @Override void migrateTo(EncryptionManager manager);  }### Answer:
@Test public void authorizedRequest() throws InterruptedException, JSONException { mEndPoint.enqueueUserInfoSuccess(); Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint); HashMap<String, String> properties = new HashMap<>(); properties.put("state", CUSTOM_STATE); final CountDownLatch latch = new CountDownLatch(1); MockRequestCallback<JSONObject, AuthorizationException> cb = new MockRequestCallback<>(latch); mSessionClient.authorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, cb); latch.await(); RecordedRequest recordedRequest = mEndPoint.takeRequest(); assertNotNull(cb.getResult()); JSONObject result = cb.getResult(); assertThat(recordedRequest.getHeader("state"), is(CUSTOM_STATE)); assertNull(cb.getException()); assertEquals("John Doe", result.getString("name")); assertEquals("Jimmy", result.getString("nickname")); }
@Test public void authorizedRequestFailure() throws InterruptedException, JSONException { mEndPoint.enqueueReturnInvalidClient(); Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint); HashMap<String, String> properties = new HashMap<>(); properties.put("state", CUSTOM_STATE); final CountDownLatch latch = new CountDownLatch(1); MockRequestCallback<JSONObject, AuthorizationException> cb = new MockRequestCallback<>(latch); mSessionClient.authorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, cb); latch.await(); assertNull(cb.getResult()); assertNotNull(cb.getException()); }