AuthUtils { static String parseAuthorizationCode(@NonNull Uri uri) throws LoginAuthenticationException { final String code = uri.getQueryParameter(KEY_AUTHENTICATION_CODE); if (TextUtils.isEmpty(code)) { throw new LoginAuthenticationException(AuthenticationError.INVALID_RESPONSE); } return code; }  static boolean isRedirectUriRegistered(@NonNull Activity activity, @NonNull Uri uri); @NonNull static String scopeCollectionToString(@NonNull Collection<Scope> scopes); static String customScopeCollectionToString(@NonNull Collection<String> scopes); static String mergeScopeStrings(String... scopes);  }
@Test public void getCodeFromUrl_whenValidAuthorizationCodePassed() throws LoginAuthenticationException { String redirectUrl = "http: assertThat(AuthUtils.parseAuthorizationCode(Uri.parse(redirectUrl))).isEqualTo(AUTH_CODE); }
@Test public void getCodeFromUrl_whenNoValidAuthorizationCodePassed() { String redirectUrl = "http: + "&expires_in=" + EXPIRATION_TIME + "&scope=history"; try { AuthUtils.parseAuthorizationCode(Uri.parse(redirectUrl)); fail("Authorization Code should not be parsable from Access Token response."); } catch (LoginAuthenticationException e) { } }