Last active
October 17, 2018 08:54
-
-
Save koifish082/9d4cd04a99f4d74f27290b7337d7b09c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.co.sample.presentation.navigation; | |
import android.net.Uri; | |
import java.io.UnsupportedEncodingException; | |
import java.net.URLEncoder; | |
import jp.co.sample.BuildConfig; | |
import jp.co.sample.data.repositories.UserInfo; | |
public class WebViewUrlBuilder { | |
private final String URL_PARAM_VALUE_CATEGORY_ID_TOW = "2"; | |
private final String URL_PARAM_VALUE_CATEGORY_ID_ONE = "1"; | |
private final String URL_PARAM_CATEGORY_ID = "categoryID"; | |
private final String URL_PARAM_USER_ID = "userID"; | |
public String buildLendingWebViewUrl(String userId, UserInfo userInfo) { | |
String workID = userInfo.getStatus().isContracted() ? | |
URL_PARAM_VALUE_CATEGORY_ID_TWO : | |
URL_PARAM_VALUE_CATEGORY_ID_ONE; | |
String memberPageUrl = BuildConfig.MEMBER_PAGE_URL; | |
Uri.Builder builder = Uri.parse(memberPageUrl).buildUpon() | |
.appendQueryParameter(URL_PARAM_CATEGORY_ID, workID) | |
.appendQueryParameter(URL_PARAM_USERID, userID); | |
String requestUrl = builder.build().toString(); | |
return BuildConfig.WEB_BASE_URL + "sign_in?return_to=" + getURLEncStr(requestUrl); | |
} | |
private String getURLEncStr(String str){ | |
if(str == null) return null; | |
try { | |
return URLEncoder.encode(str , "UTF-8"); | |
} catch (UnsupportedEncodingException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.co.sample.presentation.navigation; | |
import org.junit.Before; | |
import org.junit.Test; | |
import jp.co.sample.BuildConfig; | |
import jp.co.sample.data.entities.user.Status; | |
import jp.co.sample.data.repositories.UserInfo; | |
import timber.log.Timber; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.*; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.when; | |
public class WebViewUrlBuilderTest { | |
private WebViewUrlBuilder mBuilder; | |
@Before | |
public void setUp() throws Exception { | |
mBuilder = new WebViewUrlBuilder(); | |
} | |
@Test | |
public void buildLendingWebViewUrl() { | |
Status status = mock(Status.class); | |
UserInfo userInfo = new UserInfo(); | |
userInfo.setStatus(status); | |
when(userInfo.getStatus().isContracted()).thenReturn(true); | |
String url = mBuilder.buildLendingWebViewUrl("A11111111", userInfo); | |
assertThat(url, is(BuildConfig.WEB_BASE_URL + "sign_in?return_to=" + BuildConfig.MEMBER_PAGE_URL + "?categoryID=2&userId=A11111111")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment