Android Open Source - klarna-on-demand-android Url Helper Test






From Project

Back to project page klarna-on-demand-android.

License

The source code is released under:

Apache License

If you think the Android project klarna-on-demand-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.klarna.ondemand;
//  w  w w . ja  va 2s. com
import junit.framework.TestCase;
import java.util.Locale;

public class UrlHelperTest extends TestCase {

    String token = "my_token";

    @Override
    public void setUp() throws java.lang.Exception {
        Context.setApiKey("test_skadoo");
    }

    //region .registrationUrl
    public void testRegistrationUrl_ShouldReturnPlaygroundUrl_WhenTokenIsForPlayground() {
        assertTrue(UrlHelper.registrationUrl().startsWith("https://inapp.playground.klarna.com/registration/new"));
    }

    public void testRegistrationUrl_ShouldReturnProductionUrl_WhenTokenIsForProduction() {
        Context.setApiKey("skadoo");
        assertTrue(UrlHelper.registrationUrl().startsWith("https://inapp.klarna.com/registration/new"));
    }

    public void testRegistrationUrl_ShouldReturnUrlWithSwedishLocale_WhenLocaleIsSwedish() {
        Locale.setDefault(new Locale("sv"));

        assertTrue(UrlHelper.registrationUrl().contains("locale=sv"));

        Locale.setDefault(Locale.ENGLISH);
    }
    //endregion

    //region .PreferencesUrlWithToken
    public void testPreferencesUrlWithToken_ShouldReturnPlaygroundUrl_WhenTokenIsForPlayground() {
        String expectedPrefix = "https://inapp.playground.klarna.com/users/" + token + "/preferences";
        assertTrue(UrlHelper.preferencesUrl(token).startsWith(expectedPrefix));
    }

    public void testPreferencesUrlWithToken_ShouldReturnProductionUrl_WhenTokenIsForProduction() {
        Context.setApiKey("skadoo");
        String expectedPrefix = "https://inapp.klarna.com/users/" + token + "/preferences";
        assertTrue(UrlHelper.preferencesUrl(token).startsWith(expectedPrefix));
    }

    public void testPreferencesUrlWithToken_ShouldReturnUrlWithSwedishLocale_WhenLocaleIsSwedish() {
        Locale.setDefault(new Locale("sv"));

        assertTrue(UrlHelper.preferencesUrl(token).contains("locale=sv"));

        Locale.setDefault(Locale.ENGLISH);
    }
    //endregion
}




Java Source Code List

com.klarna.example.ApplicationTest.java
com.klarna.example.MainActivity.java
com.klarna.ondemand.ContextTest.java
com.klarna.ondemand.Context.java
com.klarna.ondemand.RegistrationActivity.java
com.klarna.ondemand.UrlHelperTest.java
com.klarna.ondemand.UrlHelper.java
com.klarna.ondemand.WebViewActivity.java
com.klarna.ondemand.package-info.java