UserManager { public Account createUser(String siteUrl, String username, String password) { Account result; if (TextUtils.isEmpty(username) && TextUtils.isEmpty(password)) { result = createGuestUser(siteUrl); } else { result = createNormalUser(siteUrl, username, password); } return result; } UserManager(AccountManager accountManager, Resources resources, PreferencesRepository preferencesRepository, Context ctx); CacheDatabase getDatabaseForCurrent(); void refreshAccounts(); int countOfAcounts(); boolean hasAccounts(); Account getAccountForUser(String siteUrl, String username); boolean userExists(String siteUrl, String username); Account createUser(String siteUrl, String username, String password); LiveData<Account> getActiveAccount(); LiveData<List<Account>> getAccounts(); String getSiteUrl(Account account); String getUsername(Account account); String getPassword(Account account); Cookie sessionCookie(); void setSessionCookie(Cookie cookie); String sessionToken(); void setSessionToken(String token); void setChunkSize(Account account, int chunkSize); int getChunkSize(Account account); boolean isGuest(Account account); void setActiveAccount(Account activeAccount); void setActiveAccount(String activeAccount); void replaceAccount(@NonNull Account account, @NonNull String url, String username, String password); void removeAccount(Account account); String validateUrl(String url);  }
@Test public void createUser_withoutCredentials_createsGuestAccount() { ArgumentCaptor<Account> accountCaptor = ArgumentCaptor.forClass(Account.class); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); userManager.createUser(SITE_URL, null, null); verify(accountManager).addAccountExplicitly(accountCaptor.capture(), eq(null), bundleCaptor.capture()); Account account = accountCaptor.getValue(); Bundle bundle = bundleCaptor.getValue(); assertThat(account).hasName(ACCOUNT_NAME); assertThat(account).hasType(ACCOUNT_TYPE); assertThat(bundle).hasSize(3); assertThat(bundle).hasKey(UserManager.KEY_IS_GUEST); assertThat(bundle.getString(UserManager.KEY_IS_GUEST)).isEqualTo(Boolean.toString(true)); assertThat(bundle).hasKey(UserManager.KEY_SITE_URL); assertThat(bundle.getString(UserManager.KEY_SITE_URL)).isEqualTo(SITE_URL); assertThat(bundle).hasKey(UserManager.KEY_USERNAME); assertThat(bundle.getString(UserManager.KEY_USERNAME)).isEqualTo(UserManager.GUEST_ACCOUNT_NAME); }
@Test public void createUser_withCredentials_createsNormalAccount() { ArgumentCaptor<Account> accountCaptor = ArgumentCaptor.forClass(Account.class); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); userManager.createUser(SITE_URL, USERNAME, PASSWORD); verify(accountManager).addAccountExplicitly(accountCaptor.capture(), eq(PASSWORD), bundleCaptor.capture()); Account account = accountCaptor.getValue(); Bundle bundle = bundleCaptor.getValue(); assertThat(account).hasName(ACCOUNT_NAME); assertThat(account).hasType(ACCOUNT_TYPE); assertThat(bundle).hasSize(3); assertThat(bundle).hasKey(UserManager.KEY_IS_GUEST); assertThat(bundle.getString(UserManager.KEY_IS_GUEST)).isEqualTo(Boolean.toString(false)); assertThat(bundle).hasKey(UserManager.KEY_SITE_URL); assertThat(bundle.getString(UserManager.KEY_SITE_URL)).isEqualTo(SITE_URL); assertThat(bundle).hasKey(UserManager.KEY_USERNAME); assertThat(bundle.getString(UserManager.KEY_USERNAME)).isEqualTo(USERNAME); }