UrlHelper { static String registrationUrl(android.content.Context applicationContext, RegistrationSettings settings) { Uri.Builder builder = new Uri.Builder(); builder.scheme("https") .authority(getAuthority()) .appendPath("registration") .appendPath("new") .appendQueryParameter("api_key", Context.getApiKey()) .appendQueryParameter("locale", Context.getLanguage(applicationContext)) .appendQueryParameter("public_key", CryptoFactory.getInstance(applicationContext).getPublicKeyBase64Str()); if(settings != null) { if (!HelperMethods.isBlank(settings.getPrefillPhoneNumber())) { builder.appendQueryParameter("prefill_phone_number", settings.getPrefillPhoneNumber()); } if (!HelperMethods.isBlank(settings.getConfirmedUserDataId())) { builder.appendQueryParameter("confirmed_user_data_id", settings.getConfirmedUserDataId()); } } return builder.build().toString(); }    }
@Test public void registrationUrl_ShouldEncodeUrlParameters() { when(cryptoMock.getPublicKeyBase64Str()).thenReturn("my+publicKey"); assertThat(UrlHelper.registrationUrl(context, null)).contains("public_key=my%2BpublicKey"); }
@Test public void registrationUrl_ShouldIncludeConfirmedUserDataIdWhenSupplied() { assertThat(UrlHelper.registrationUrl(context, new RegistrationSettings(null, "abcd"))).contains("confirmed_user_data_id=abcd"); }
@Test public void registrationUrl_ShouldIncludePrefillPhoneNumberWhenSupplied() { assertThat(UrlHelper.registrationUrl(context, new RegistrationSettings("12345678", null))).contains("prefill_phone_number=12345678"); }
@Test public void registrationUrl_ShouldReturnPlaygroundUrl_WhenTokenIsForPlayground() { assertThat(UrlHelper.registrationUrl(context, null)).startsWith("https: }
@Test public void registrationUrl_ShouldReturnProductionUrl_WhenTokenIsForProduction() { when(Context.getApiKey()).thenReturn("skadoo"); assertThat(UrlHelper.registrationUrl(context, null)).startsWith("https: }
@Test public void registrationUrl_ShouldReturnUrlWithTheDefaultLocale() { when(Context.getLanguage(context)).thenReturn("my_locale"); assertThat(UrlHelper.registrationUrl(context, null)).contains("locale=my_locale"); }
@Test public void registrationUrl_ShouldIncludeThePublicKeyInTheRegistrationUrl() { assertThat(UrlHelper.registrationUrl(context, null)).contains("public_key=my_publicKey"); }