本文整理匯總了Java中com.twitter.sdk.android.core.Callback.failure方法的典型用法代碼示例。如果您正苦於以下問題:Java Callback.failure方法的具體用法?Java Callback.failure怎麽用?Java Callback.failure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.twitter.sdk.android.core.Callback
的用法示例。
在下文中一共展示了Callback.failure方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testExecuteRequest_successWithEmailRequestFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
public void testExecuteRequest_successWithEmailRequestFailure() throws Exception {
final DigitsSessionResponse response = TestConstants.DIGITS_USER;
final Result<DigitsSessionResponse> result = new Result(response, null);
controller = new DummyPinCodeController(resultReceiver, sendButton, phoneEditText,
sessionManager, digitsClient, REQUEST_ID, USER_ID, PHONE_WITH_COUNTRY_CODE, errors,
new ActivityClassManagerImp(), digitsEventCollector, true,
digitsEventDetailsBuilder);
final DigitsCallback<DigitsSessionResponse> callback = executeRequest();
callback.success(result);
verify(controller.getAccountService()).verifyAccount(callbackArgumentCaptor.capture());
final Callback<VerifyAccountResponse> emailRequestCallback = callbackArgumentCaptor
.getValue();
emailRequestCallback.failure(TestConstants.ANY_EXCEPTION);
verify(digitsEventCollector).twoFactorPinVerificationException(any(DigitsException.class));
verify(phoneEditText).setError(null);
verify(sendButton).showError();
}
示例2: testExecuteRequest_successWithEmailRequestFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
public void testExecuteRequest_successWithEmailRequestFailure() throws Exception {
final DigitsSessionResponse response = TestConstants.DIGITS_USER;
final Result<DigitsSessionResponse> result = new Result(response, null);
controller = new DummyLoginCodeController(resultReceiver, sendButton, resendButton,
callMeButton, phoneEditText, sessionManager, digitsClient, REQUEST_ID, USER_ID,
PHONE_WITH_COUNTRY_CODE, errors, new ActivityClassManagerImp(),
digitsEventCollector, true, timerTextView, digitsEventDetailsBuilder);
final DigitsCallback<DigitsSessionResponse> callback = executeRequest();
callback.success(result);
verify(controller.getAccountService()).verifyAccount(callbackArgumentCaptor.capture());
final Callback<VerifyAccountResponse> emailRequestCallback = callbackArgumentCaptor
.getValue();
emailRequestCallback.failure(TestConstants.ANY_EXCEPTION);
verify(digitsEventCollector).loginException(any(DigitsException.class));
verify(phoneEditText).setError(null);
verify(callMeButton).showError();
verify(resendButton).showError();
verify(sendButton).showError();
}
示例3: testLoginFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testLoginFailure() {
LoginOrSignupComposer loginOrSignupComposer = new LoginOrSignupComposer(context,
digitsClient, sessionManager, PHONE_WITH_COUNTRY_CODE, Verification.sms, true,
resultReceiver, activityClassManager, digitsEventDetailsBuilder){
@Override
public void success(final Intent intent){
assertTrue(false);
}
@Override
public void failure(DigitsException digitsException) {
assertEquals(TwitterApiErrorConstants.USER_IS_NOT_SDK_USER,
digitsException.getErrorCode());
}
};
loginOrSignupComposer.start();
//Simulate Auth failure
verify(digitsClient).authDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback loginCallback = callbackCaptor.getValue();
loginCallback.failure(userIsNotSdkUserException);
}
示例4: handleOnActivityResult
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
/**
* Called when {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
* is called to complete the authorization flow.
*
* @param requestCode the request code used for SSO
* @param resultCode the result code returned by the SSO activity
* @param data the result data returned by the SSO activity
*/
public boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) {
if (this.requestCode != requestCode) {
return false;
}
final Callback<TwitterSession> callback = getCallback();
if (callback != null) {
if (resultCode == Activity.RESULT_OK) {
final String token = data.getStringExtra(EXTRA_TOKEN);
final String tokenSecret = data.getStringExtra(EXTRA_TOKEN_SECRET);
final String screenName = data.getStringExtra(EXTRA_SCREEN_NAME);
final long userId = data.getLongExtra(EXTRA_USER_ID, 0L);
callback.success(new Result<>(new TwitterSession(
new TwitterAuthToken(token, tokenSecret), userId, screenName), null));
} else if (data != null && data.hasExtra(EXTRA_AUTH_ERROR)) {
callback.failure(
(TwitterAuthException) data.getSerializableExtra(EXTRA_AUTH_ERROR));
} else {
callback.failure(new TwitterAuthException("Authorize failed."));
}
}
return true;
}
示例5: testSignupSuccess
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testSignupSuccess() {
LoginOrSignupComposer loginOrSignupComposer = new LoginOrSignupComposer(context,
digitsClient, sessionManager, PHONE_WITH_COUNTRY_CODE, Verification.sms, true,
resultReceiver, activityClassManager, digitsEventDetailsBuilder){
@Override
public void success(final Intent intent){
assertExpectedSignupIntent(intent);
}
@Override
public void failure(DigitsException digitsException) {
assertTrue(false);
}
};
loginOrSignupComposer.start();
//Simulate Auth failure
verify(digitsClient).authDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback loginCallback = callbackCaptor.getValue();
loginCallback.failure(couldNotAuthenticateException);
//Simulate Signup success
verify(digitsClient).registerDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback signupCallback = callbackCaptor.getValue();
signupCallback.success(new Result(deviceRegistrationResponse, null));
}
示例6: testLoginGuestAuthFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testLoginGuestAuthFailure() {
LoginOrSignupComposer loginOrSignupComposer = new LoginOrSignupComposer(context,
digitsClient, sessionManager, PHONE_WITH_COUNTRY_CODE, Verification.sms, true,
resultReceiver, activityClassManager, digitsEventDetailsBuilder){
@Override
public void success(final Intent intent){
assertTrue(false);
}
@Override
public void failure(DigitsException digitsException) {
assertEquals(TwitterApiConstants.Errors.GUEST_AUTH_ERROR_CODE,
digitsException.getErrorCode());
}
};
loginOrSignupComposer.start();
//Simulate Auth failure
verify(digitsClient).authDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback loginCallback = callbackCaptor.getValue();
loginCallback.failure(guestAuthException);
verify(sessionManager).clearSession(TwitterSession.LOGGED_OUT_USER_ID);
}
示例7: testSignupFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testSignupFailure() {
LoginOrSignupComposer loginOrSignupComposer = new LoginOrSignupComposer(context,
digitsClient, sessionManager, PHONE_WITH_COUNTRY_CODE, Verification.sms, true,
resultReceiver, activityClassManager, digitsEventDetailsBuilder){
@Override
public void success(final Intent intent){
assertTrue(false);
}
@Override
public void failure(DigitsException digitsException) {
assertEquals(TwitterApiErrorConstants.DEVICE_REGISTRATION_RATE_EXCEEDED,
digitsException.getErrorCode());
}
};
loginOrSignupComposer.start();
//Simulate Auth failure
verify(digitsClient).authDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback loginCallback = callbackCaptor.getValue();
loginCallback.failure(couldNotAuthenticateException);
//Simulate Signup failure
verify(digitsClient).registerDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback signupCallback = callbackCaptor.getValue();
signupCallback.failure(registrationRateExceededException);
}
示例8: testSignupGuestAuthFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testSignupGuestAuthFailure() {
LoginOrSignupComposer loginOrSignupComposer = new LoginOrSignupComposer(context,
digitsClient, sessionManager, PHONE_WITH_COUNTRY_CODE, Verification.sms, true,
resultReceiver, activityClassManager, digitsEventDetailsBuilder){
@Override
public void success(final Intent intent){
assertTrue(false);
}
@Override
public void failure(DigitsException digitsException) {
assertEquals(TwitterApiConstants.Errors.GUEST_AUTH_ERROR_CODE,
digitsException.getErrorCode());
}
};
loginOrSignupComposer.start();
//Simulate Auth failure
verify(digitsClient).authDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback loginCallback = callbackCaptor.getValue();
loginCallback.failure(couldNotAuthenticateException);
//Simulate Signup failure
verify(digitsClient).registerDevice(anyString(), any(Verification.class),
callbackCaptor.capture());
final Callback signupCallback = callbackCaptor.getValue();
signupCallback.failure(guestAuthException);
verify(sessionManager).clearSession(TwitterSession.LOGGED_OUT_USER_ID);
}
示例9: loadNext
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
/**
* Checks the capacity and sets requestInFlight before calling timeline.next.
*/
void loadNext(Long minPosition, Callback<TimelineResult<T>> cb) {
if (withinMaxCapacity()) {
if (timelineStateHolder.startTimelineRequest()) {
timeline.next(minPosition, cb);
} else {
cb.failure(new TwitterException("Request already in flight"));
}
} else {
cb.failure(new TwitterException("Max capacity reached"));
}
}
示例10: loadPrevious
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
/**
* Checks the capacity and sets requestInFlight before calling timeline.previous.
*/
void loadPrevious(Long maxPosition, Callback<TimelineResult<T>> cb) {
if (withinMaxCapacity()) {
if (timelineStateHolder.startTimelineRequest()) {
timeline.previous(maxPosition, cb);
} else {
cb.failure(new TwitterException("Request already in flight"));
}
} else {
cb.failure(new TwitterException("Max capacity reached"));
}
}
示例11: getUserSession
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
void getUserSession(final Callback<TwitterSession> cb) {
final TwitterSession session = userSessionManagers.getActiveSession();
if (session == null) {
cb.failure(new TwitterAuthException("User authorization required"));
} else {
cb.success(new Result<>(session, null));
}
}
示例12: testCallbackWrapperFailure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testCallbackWrapperFailure() {
final Callback<OAuthResponse> authResponseCallback = mock(Callback.class);
final Callback<ResponseBody> callbackWrapper = service.getCallbackWrapper(authResponseCallback);
final TwitterException mockException = mock(TwitterException.class);
callbackWrapper.failure(mockException);
verify(authResponseCallback).failure(eq(mockException));
}
示例13: testNewRequestTempTokenCallback_failure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testNewRequestTempTokenCallback_failure() {
final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback();
final TwitterException mockException = mock(TwitterException.class);
callback.failure(mockException);
verifyOnCompleteWithError("Failed to get request token");
}
示例14: testNewAccessTokenCallback_failure
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
@Test
public void testNewAccessTokenCallback_failure() {
final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback();
final TwitterException mockException = mock(TwitterException.class);
callback.failure(mockException);
verifyOnCompleteWithError("Failed to get access token");
}
示例15: getCallbackWrapper
import com.twitter.sdk.android.core.Callback; //導入方法依賴的package包/類
Callback<ResponseBody> getCallbackWrapper(final Callback<OAuthResponse> callback) {
return new Callback<ResponseBody>() {
@Override
public void success(Result<ResponseBody> result) {
//Try to get response body
BufferedReader reader = null;
final StringBuilder sb = new StringBuilder();
try {
try {
reader = new BufferedReader(
new InputStreamReader(result.data.byteStream()));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} finally {
if (reader != null) {
reader.close();
}
}
final String responseAsStr = sb.toString();
final OAuthResponse authResponse = parseAuthResponse(responseAsStr);
if (authResponse == null) {
callback.failure(new TwitterAuthException(
"Failed to parse auth response: " + responseAsStr));
} else {
callback.success(new Result<>(authResponse, null));
}
} catch (IOException e) {
callback.failure(new TwitterAuthException(e.getMessage(), e));
}
}
@Override
public void failure(TwitterException exception) {
callback.failure(exception);
}
};
}