Hi Bor-yeh,
If there's no public (or protected) constructor, you can't directly mock it.
With a bit of refactoring, though, you could still use Android Mock in most cases. Instead of calling the AccountManager directly, you can create your own class with the same methods as AccountManager, and mock that.
E.g.
public class AccountManagerDelegate {
private AccountManager realManager;
public AccountManagerDelegate(Context context) {
realManager = AccountManager.get(context);
}
public void clearPassword(Account account) {
realManager.clearPassword(account);
}
// etc...
}
Replace all calls to AccountManager in your code with calls to AccountManagerDelegate. Then, you can mock AccountManagerDelegate in your tests. It should be a straightforward 1 to 1 replacement.
Hopefully that should get you going. Let me know if you have any troubles.
Thanks,
Steve
(Small print notice):
This refactoring is not a perfectly generic solution, since if you need to pass an AccountManager object into code that you can't modify, then you can't make this refactoring. (For example, if you tried this with the Account class (create AccountDelegate), it wouldn't work well, because AccountManager.setPassword(Account, String) wouldn't accept an AccountDelegate. Fortunately, Account is mockable, so you don't need this pattern for Account.)
If all you do is retrieve an AccountManager object and then invoke methods on it, this is one of the easiest approaches.