AuthenticationRequest implements Parcelable { public Uri toUri() { Uri.Builder uriBuilder = new Uri.Builder(); uriBuilder.scheme(ACCOUNTS_SCHEME) .authority(ACCOUNTS_AUTHORITY) .appendPath(ACCOUNTS_PATH) .appendQueryParameter(QueryParams.CLIENT_ID, mClientId) .appendQueryParameter(QueryParams.RESPONSE_TYPE, mResponseType) .appendQueryParameter(QueryParams.REDIRECT_URI, mRedirectUri) .appendQueryParameter(QueryParams.SHOW_DIALOG, String.valueOf(mShowDialog)) .appendQueryParameter(QueryParams.UTM_SOURCE, SPOTIFY_SDK) .appendQueryParameter(QueryParams.UTM_MEDIUM, ANDROID_SDK) .appendQueryParameter(QueryParams.UTM_CAMPAIGN, getCampaign()); if (mScopes != null && mScopes.length > 0) { uriBuilder.appendQueryParameter(QueryParams.SCOPE, scopesToString()); } if (mState != null) { uriBuilder.appendQueryParameter(QueryParams.STATE, mState); } if (mCustomParams.size() > 0) { for (Map.Entry<String, String> entry : mCustomParams.entrySet()) { uriBuilder.appendQueryParameter(entry.getKey(), entry.getValue()); } } return uriBuilder.build(); } AuthenticationRequest(Parcel source); private  AuthenticationRequest(String clientId,
                                  AuthenticationResponse.Type responseType,
                                  String redirectUri,
                                  String state,
                                  String[] scopes,
                                  boolean showDialog,
                                  Map<String, String> customParams,
                                  String campaign); String getClientId(); String getResponseType(); String getRedirectUri(); String getState(); String[] getScopes(); String getCustomParam(String key); String getCampaign(); Uri toUri(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Parcelable.Creator<AuthenticationRequest> CREATOR; }
@Test public void shouldBuildCorrectUri() { AuthenticationRequest authenticationRequest = new AuthenticationRequest.Builder(mClientId, mResponseType, mRedirectUri).build(); Uri.Builder uriBuilder = getBaseAuthUri(mClientId, mResponseType.toString(), mRedirectUri, mDefaultCampaign); Uri uri = uriBuilder.build(); assertEquals(uri, authenticationRequest.toUri()); }
@Test public void shouldNotSetNullScopes() { AuthenticationRequest authenticationRequest = new AuthenticationRequest.Builder(mClientId, mResponseType, mRedirectUri) .setScopes(null) .build(); Uri.Builder uriBuilder = getBaseAuthUri(mClientId, mResponseType.toString(), mRedirectUri, mDefaultCampaign); Uri uri = uriBuilder.build(); assertEquals(uri, authenticationRequest.toUri()); }
@Test public void shouldNotSetEmptyScopes() { AuthenticationRequest authenticationRequest = new AuthenticationRequest.Builder(mClientId, mResponseType, mRedirectUri) .setScopes(new String[]{}) .build(); Uri.Builder uriBuilder = getBaseAuthUri(mClientId, mResponseType.toString(), mRedirectUri, mDefaultCampaign); Uri uri = uriBuilder.build(); assertEquals(uri, authenticationRequest.toUri()); }
@Test public void shouldNotSetNullState() { AuthenticationRequest authenticationRequest = new AuthenticationRequest.Builder(mClientId, mResponseType, mRedirectUri) .setState(null) .build(); Uri.Builder uriBuilder = getBaseAuthUri(mClientId, mResponseType.toString(), mRedirectUri, mDefaultCampaign); Uri uri = uriBuilder.build(); assertEquals(uri, authenticationRequest.toUri()); }
@Test public void shouldSetCustomParams() { String customKey1 = "custom_key_1"; String customValue1 = "custom_value_1"; String customKey2 = "custom_key_2"; String customValue2 = "custom_value_2"; AuthenticationRequest authenticationRequest = new AuthenticationRequest.Builder(mClientId, mResponseType, mRedirectUri) .setCustomParam(customKey1, customValue1) .setCustomParam(customKey2, customValue2) .build(); Uri.Builder uriBuilder = getBaseAuthUri(mClientId, mResponseType.toString(), mRedirectUri, mDefaultCampaign); uriBuilder.appendQueryParameter(customKey1, customValue1); uriBuilder.appendQueryParameter(customKey2, customValue2); Uri uri = uriBuilder.build(); assertEquals(uri, authenticationRequest.toUri()); }