diff options
author | Paul Westbrook <pwestbro@google.com> | 2010-02-26 18:21:15 -0800 |
---|---|---|
committer | Paul Westbrook <pwestbro@google.com> | 2010-02-26 18:24:29 -0800 |
commit | 69120a73d0f7a1862d51e0a95ebd5e507fee8cd2 (patch) | |
tree | 32d52fcfaf9b039c80ee29a689101f5337dfc2a6 /test-runner | |
parent | 59dc9ecec6e4f53a1a2934b08c7f779d2b0a0d9a (diff) | |
download | frameworks_base-69120a73d0f7a1862d51e0a95ebd5e507fee8cd2.zip frameworks_base-69120a73d0f7a1862d51e0a95ebd5e507fee8cd2.tar.gz frameworks_base-69120a73d0f7a1862d51e0a95ebd5e507fee8cd2.tar.bz2 |
Bug 2306842
Since MockAccountManager was passing null to the AccountManager
constructor, unit tests where the AccountManager attempts to call
the AccountManagerService were crashing.
Now the getAccountsByTypeAndFeatures and blockingGetAuthToken
(which are the calls that the Gmail unit tests call) call a small
stub
At some point, all of the other AccountManager calls should be stubbed
out
Diffstat (limited to 'test-runner')
-rw-r--r-- | test-runner/src/android/test/IsolatedContext.java | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/test-runner/src/android/test/IsolatedContext.java b/test-runner/src/android/test/IsolatedContext.java index 485e45c..f093598 100644 --- a/test-runner/src/android/test/IsolatedContext.java +++ b/test-runner/src/android/test/IsolatedContext.java @@ -3,7 +3,11 @@ package android.test; import com.google.android.collect.Lists; import android.accounts.AccountManager; +import android.accounts.AccountManagerCallback; +import android.accounts.AccountManagerFuture; +import android.accounts.AuthenticatorException; import android.accounts.OnAccountsUpdateListener; +import android.accounts.OperationCanceledException; import android.accounts.Account; import android.content.ContextWrapper; import android.content.ContentResolver; @@ -16,8 +20,13 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Handler; -import java.util.List; import java.io.File; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.List; + /** * A mock context which prevents its users from talking to the rest of the device while @@ -105,7 +114,58 @@ public class IsolatedContext extends ContextWrapper { public Account[] getAccounts() { return new Account[]{}; } + + public AccountManagerFuture<Account[]> getAccountsByTypeAndFeatures( + final String type, final String[] features, + AccountManagerCallback<Account[]> callback, Handler handler) { + return new MockAccountManagerFuture<Account[]>(new Account[0]); + } + + public String blockingGetAuthToken(Account account, String authTokenType, + boolean notifyAuthFailure) + throws OperationCanceledException, IOException, AuthenticatorException { + return null; + } + + + /** + * A very simple AccountManagerFuture class + * that returns what ever was passed in + */ + private class MockAccountManagerFuture<T> + implements AccountManagerFuture<T> { + + T mResult; + + public MockAccountManagerFuture(T result) { + mResult = result; + } + + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + public boolean isCancelled() { + return false; + } + + public boolean isDone() { + return true; + } + + public T getResult() + throws OperationCanceledException, IOException, AuthenticatorException { + return mResult; + } + + public T getResult(long timeout, TimeUnit unit) + throws OperationCanceledException, IOException, AuthenticatorException { + return getResult(); + } + } + } + @Override public File getFilesDir() { return new File("/dev/null"); |