本文整理匯總了Java中org.robolectric.Robolectric.getShadowApplication方法的典型用法代碼示例。如果您正苦於以下問題:Java Robolectric.getShadowApplication方法的具體用法?Java Robolectric.getShadowApplication怎麽用?Java Robolectric.getShadowApplication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.Robolectric
的用法示例。
在下文中一共展示了Robolectric.getShadowApplication方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetTokenCallbackWithIntent
import org.robolectric.Robolectric; //導入方法依賴的package包/類
/**
* Tests the behavior of {@link HttpNegotiateAuthenticator.GetTokenCallback} when the result it
* receives contains an intent rather than a token directly.
*/
@Test
public void testGetTokenCallbackWithIntent() {
String type = "Dummy_Account";
HttpNegotiateAuthenticator authenticator = createWithoutNative(type);
RequestData requestData = new RequestData();
requestData.nativeResultObject = 42;
requestData.authTokenType = "foo";
requestData.account = new Account("a", type);
requestData.accountManager = sMockAccountManager;
Bundle b = new Bundle();
b.putParcelable(AccountManager.KEY_INTENT, new Intent());
authenticator.new GetTokenCallback(requestData).run(makeFuture(b));
verifyZeroInteractions(sMockAccountManager);
// Verify that the broadcast receiver is registered
Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
ShadowApplication shadowApplication = Robolectric.getShadowApplication();
List<BroadcastReceiver> receivers = shadowApplication.getReceiversForIntent(intent);
assertThat("There is one registered broadcast receiver", receivers.size(), equalTo(1));
// Send the intent to the receiver.
BroadcastReceiver receiver = receivers.get(0);
receiver.onReceive(Robolectric.getShadowApplication().getApplicationContext(), intent);
// Verify that the auth token is properly requested from the account manager.
verify(sMockAccountManager).getAuthToken(
eq(new Account("a", type)),
eq("foo"),
isNull(Bundle.class),
eq(true),
any(HttpNegotiateAuthenticator.GetTokenCallback.class),
any(Handler.class));
}