@Test public void testGetAccount() { when(mAccountManager.getAccountsByType(TEST_ACCOUNT_TYPE)) .thenReturn(new Account[]{mAccount}); when(mSharedPreferences.getString(PREF_SELECTED_ACCOUNT, "")).thenReturn(TEST_ACCOUNT_NAME); Account selectedAccount = mAccountController.getCurrentAccount(); assertEquals(selectedAccount, mAccount); }
public @Nullable Account getCurrentAccount() { Account[] accounts; try { accounts = mAccountManager.getAccountsByType(mAccountType); } catch (SecurityException e) { TbaLogger.w("Can't get current local account, no permission", e); return null; } String selectedAccount = getSelectedAccount(); for (Account account : accounts) { if (account.name.equals(selectedAccount)) return account; } return null; }
AccountController { public @Nullable Account getCurrentAccount() { Account[] accounts; try { accounts = mAccountManager.getAccountsByType(mAccountType); } catch (SecurityException e) { TbaLogger.w("Can't get current local account, no permission", e); return null; } String selectedAccount = getSelectedAccount(); for (Account account : accounts) { if (account.name.equals(selectedAccount)) return account; } return null; } }
AccountController { public @Nullable Account getCurrentAccount() { Account[] accounts; try { accounts = mAccountManager.getAccountsByType(mAccountType); } catch (SecurityException e) { TbaLogger.w("Can't get current local account, no permission", e); return null; } String selectedAccount = getSelectedAccount(); for (Account account : accounts) { if (account.name.equals(selectedAccount)) return account; } return null; } @Inject  AccountController(
            SharedPreferences preferences,
            AccountManager accountManager,
            AppConfig appConfig,
            String accountType); }
AccountController { public @Nullable Account getCurrentAccount() { Account[] accounts; try { accounts = mAccountManager.getAccountsByType(mAccountType); } catch (SecurityException e) { TbaLogger.w("Can't get current local account, no permission", e); return null; } String selectedAccount = getSelectedAccount(); for (Account account : accounts) { if (account.name.equals(selectedAccount)) return account; } return null; } @Inject  AccountController(
            SharedPreferences preferences,
            AccountManager accountManager,
            AppConfig appConfig,
            String accountType); void setMyTbaEnabled(boolean enabled); boolean isMyTbaEnabled(); void setSelectedAccount(String account); String getSelectedAccount(); boolean isAccountSelected(); @Nullable Account getCurrentAccount(); void onAccountConnect(Context context, User user); String getWebClientId(); }
AccountController { public @Nullable Account getCurrentAccount() { Account[] accounts; try { accounts = mAccountManager.getAccountsByType(mAccountType); } catch (SecurityException e) { TbaLogger.w("Can't get current local account, no permission", e); return null; } String selectedAccount = getSelectedAccount(); for (Account account : accounts) { if (account.name.equals(selectedAccount)) return account; } return null; } @Inject  AccountController(
            SharedPreferences preferences,
            AccountManager accountManager,
            AppConfig appConfig,
            String accountType); void setMyTbaEnabled(boolean enabled); boolean isMyTbaEnabled(); void setSelectedAccount(String account); String getSelectedAccount(); boolean isAccountSelected(); @Nullable Account getCurrentAccount(); void onAccountConnect(Context context, User user); String getWebClientId();  }