AccountCache: Rename maybeGet to get

maybeGet is the method that most callers should use. Make this more
obvious by renaming it to get. Also the return type of Optional already
implies that there might not be a result, hence the method name doesn't
need to be explicit about this.

Change-Id: I571fa9989b2629d96f2238d4b8571d669a9bc89d
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-01-30 16:17:26 +01:00
parent 60951298e3
commit 5c676582ad
33 changed files with 47 additions and 47 deletions

View File

@@ -814,7 +814,7 @@ public abstract class AbstractDaemonTest {
} }
protected AccountState getAccountState(Account.Id accountId) { protected AccountState getAccountState(Account.Id accountId) {
Optional<AccountState> accountState = accountCache.maybeGet(accountId); Optional<AccountState> accountState = accountCache.get(accountId);
assertThat(accountState).named("account %s", accountId.get()).isPresent(); assertThat(accountState).named("account %s", accountId.get()).isPresent();
return accountState.get(); return accountState.get();
} }

View File

@@ -160,7 +160,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
Element userlistElement = HtmlDomUtil.find(doc, "userlist"); Element userlistElement = HtmlDomUtil.find(doc, "userlist");
try (ReviewDb db = schema.open()) { try (ReviewDb db = schema.open()) {
for (Account.Id accountId : accounts.firstNIds(100)) { for (Account.Id accountId : accounts.firstNIds(100)) {
Optional<AccountState> accountState = accountCache.maybeGet(accountId); Optional<AccountState> accountState = accountCache.get(accountId);
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
continue; continue;
} }

View File

@@ -29,7 +29,7 @@ public interface AccountCache {
* @return {@code AccountState} instance for the given account ID, if no account with this ID * @return {@code AccountState} instance for the given account ID, if no account with this ID
* exists {@link Optional#empty()} is returned * exists {@link Optional#empty()} is returned
*/ */
Optional<AccountState> maybeGet(Account.Id accountId); Optional<AccountState> get(Account.Id accountId);
/** /**
* Returns an {@code AccountState} instance for the given account ID. If not cached yet the * Returns an {@code AccountState} instance for the given account ID. If not cached yet the
@@ -39,7 +39,7 @@ public interface AccountCache {
* <p>This method should only be used in exceptional cases where it is required to get an account * <p>This method should only be used in exceptional cases where it is required to get an account
* state even if the account is missing. Callers should leave a comment with the method invocation * state even if the account is missing. Callers should leave a comment with the method invocation
* explaining why this method is used. Most callers of {@link AccountCache} should use {@link * explaining why this method is used. Most callers of {@link AccountCache} should use {@link
* #maybeGet(Account.Id)} instead and handle the missing account case explicitly. * #get(Account.Id)} instead and handle the missing account case explicitly.
* *
* @param accountId ID of the account that should be retrieved * @param accountId ID of the account that should be retrieved
* @return {@code AccountState} instance for the given account ID, if no account with this ID * @return {@code AccountState} instance for the given account ID, if no account with this ID

View File

@@ -87,7 +87,7 @@ public class AccountCacheImpl implements AccountCache {
} }
@Override @Override
public Optional<AccountState> maybeGet(Account.Id accountId) { public Optional<AccountState> get(Account.Id accountId) {
try { try {
return byId.get(accountId); return byId.get(accountId);
} catch (ExecutionException e) { } catch (ExecutionException e) {
@@ -103,7 +103,7 @@ public class AccountCacheImpl implements AccountCache {
if (extId == null) { if (extId == null) {
return Optional.empty(); return Optional.empty();
} }
return maybeGet(extId.accountId()); return get(extId.accountId());
} catch (IOException | ConfigInvalidException e) { } catch (IOException | ConfigInvalidException e) {
log.warn("Cannot load AccountState for username " + username, e); log.warn("Cannot load AccountState for username " + username, e);
return null; return null;

View File

@@ -147,7 +147,7 @@ public class AccountManager {
return create(db, who); return create(db, who);
} }
Optional<AccountState> accountState = byIdCache.maybeGet(id.accountId()); Optional<AccountState> accountState = byIdCache.get(id.accountId());
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
log.error( log.error(
String.format( String.format(
@@ -215,7 +215,7 @@ public class AccountManager {
throw new AccountException("Unable to deactivate account " + account.getId(), e); throw new AccountException("Unable to deactivate account " + account.getId(), e);
} }
} }
return byIdCache.maybeGet(account.getId()).map(AccountState::getAccount); return byIdCache.get(account.getId()).map(AccountState::getAccount);
} }
private boolean shouldUpdateActiveStatus(AuthRequest authRequest) { private boolean shouldUpdateActiveStatus(AuthRequest authRequest) {

View File

@@ -69,12 +69,12 @@ public class AccountResolver {
public Account find(String nameOrEmail) throws OrmException, IOException, ConfigInvalidException { public Account find(String nameOrEmail) throws OrmException, IOException, ConfigInvalidException {
Set<Account.Id> r = findAll(nameOrEmail); Set<Account.Id> r = findAll(nameOrEmail);
if (r.size() == 1) { if (r.size() == 1) {
return byId.maybeGet(r.iterator().next()).map(AccountState::getAccount).orElse(null); return byId.get(r.iterator().next()).map(AccountState::getAccount).orElse(null);
} }
Account match = null; Account match = null;
for (Account.Id id : r) { for (Account.Id id : r) {
Optional<Account> account = byId.maybeGet(id).map(AccountState::getAccount); Optional<Account> account = byId.get(id).map(AccountState::getAccount);
if (!account.map(Account::isActive).orElse(false)) { if (!account.map(Account::isActive).orElse(false)) {
continue; continue;
} }
@@ -128,7 +128,7 @@ public class AccountResolver {
public Account findByNameOrEmail(String nameOrEmail) throws OrmException, IOException { public Account findByNameOrEmail(String nameOrEmail) throws OrmException, IOException {
Set<Account.Id> r = findAllByNameOrEmail(nameOrEmail); Set<Account.Id> r = findAllByNameOrEmail(nameOrEmail);
return r.size() == 1 return r.size() == 1
? byId.maybeGet(r.iterator().next()).map(AccountState::getAccount).orElse(null) ? byId.get(r.iterator().next()).map(AccountState::getAccount).orElse(null)
: null; : null;
} }
@@ -152,7 +152,7 @@ public class AccountResolver {
String name = nameOrEmail.substring(0, lt - 1); String name = nameOrEmail.substring(0, lt - 1);
Set<Account.Id> nameMatches = new HashSet<>(); Set<Account.Id> nameMatches = new HashSet<>();
for (Account.Id id : ids) { for (Account.Id id : ids) {
Optional<Account> a = byId.maybeGet(id).map(AccountState::getAccount); Optional<Account> a = byId.get(id).map(AccountState::getAccount);
if (a.isPresent() && name.equals(a.get().getFullName())) { if (a.isPresent() && name.equals(a.get().getFullName())) {
nameMatches.add(id); nameMatches.add(id);
} }

View File

@@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory;
* and properties from the account config file. AccountState maps one-to-one to Account. * and properties from the account config file. AccountState maps one-to-one to Account.
* *
* <p>Most callers should not construct AccountStates directly but rather lookup accounts via the * <p>Most callers should not construct AccountStates directly but rather lookup accounts via the
* account cache (see {@link AccountCache#maybeGet(Account.Id)}). * account cache (see {@link AccountCache#get(Account.Id)}).
*/ */
public class AccountState { public class AccountState {
private static final Logger logger = LoggerFactory.getLogger(AccountState.class); private static final Logger logger = LoggerFactory.getLogger(AccountState.class);

View File

@@ -129,7 +129,7 @@ public class GroupMembers {
.getMembers() .getMembers()
.stream() .stream()
.filter(groupControl::canSeeMember) .filter(groupControl::canSeeMember)
.map(accountCache::maybeGet) .map(accountCache::get)
.flatMap(Streams::stream) .flatMap(Streams::stream)
.map(AccountState::getAccount) .map(AccountState::getAccount)
.collect(toImmutableSet()); .collect(toImmutableSet());

View File

@@ -68,7 +68,7 @@ public class InternalAccountDirectory extends AccountDirectory {
} }
for (AccountInfo info : in) { for (AccountInfo info : in) {
Account.Id id = new Account.Id(info._accountId); Account.Id id = new Account.Id(info._accountId);
Optional<AccountState> state = accountCache.maybeGet(id); Optional<AccountState> state = accountCache.get(id);
if (state.isPresent()) { if (state.isPresent()) {
fill(info, state.get(), options); fill(info, state.get(), options);
} else { } else {

View File

@@ -117,7 +117,7 @@ public class ExternalIdsConsistencyChecker {
private List<ConsistencyProblemInfo> validateExternalId(ExternalId extId) { private List<ConsistencyProblemInfo> validateExternalId(ExternalId extId) {
List<ConsistencyProblemInfo> problems = new ArrayList<>(); List<ConsistencyProblemInfo> problems = new ArrayList<>();
if (!accountCache.maybeGet(extId.accountId()).isPresent()) { if (!accountCache.get(extId.accountId()).isPresent()) {
addError( addError(
String.format( String.format(
"External ID '%s' belongs to account that doesn't exist: %s", "External ID '%s' belongs to account that doesn't exist: %s",

View File

@@ -173,7 +173,7 @@ public class ChangeResource implements RestResource, HasETag {
} }
for (Account.Id accountId : accounts) { for (Account.Id accountId : accounts) {
Optional<AccountState> accountState = accountCache.maybeGet(accountId); Optional<AccountState> accountState = accountCache.get(accountId);
if (accountState.isPresent()) { if (accountState.isPresent()) {
hashAccount(h, accountState.get(), buf); hashAccount(h, accountState.get(), buf);
} else { } else {

View File

@@ -572,7 +572,7 @@ public class EventFactory {
if (id == null) { if (id == null) {
return null; return null;
} }
return accountCache.maybeGet(id).map(a -> asAccountAttribute(a)).orElse(null); return accountCache.get(id).map(a -> asAccountAttribute(a)).orElse(null);
} }
/** /**

View File

@@ -437,7 +437,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
private String getByAccountName() { private String getByAccountName() {
checkNotNull(submitter, "getByAccountName called before submitter populated"); checkNotNull(submitter, "getByAccountName called before submitter populated");
Optional<Account> account = Optional<Account> account =
args.accountCache.maybeGet(submitter.getAccountId()).map(AccountState::getAccount); args.accountCache.get(submitter.getAccountId()).map(AccountState::getAccount);
if (account.isPresent() && account.get().getFullName() != null) { if (account.isPresent() && account.get().getFullName() != null) {
return " by " + account.get().getFullName(); return " by " + account.get().getFullName();
} }
@@ -556,7 +556,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
args.changeMerged.fire( args.changeMerged.fire(
updatedChange, updatedChange,
mergedPatchSet, mergedPatchSet,
args.accountCache.maybeGet(submitter.getAccountId()).orElse(null), args.accountCache.get(submitter.getAccountId()).orElse(null),
args.mergeTip.getCurrentTip().name(), args.mergeTip.getCurrentTip().name(),
ctx.getWhen()); ctx.getWhen());
} }

View File

@@ -202,6 +202,6 @@ class DbGroupMemberAuditListener implements GroupMemberAuditListener {
} }
private Optional<String> getUserName(Account.Id accountId) { private Optional<String> getUserName(Account.Id accountId) {
return accountCache.maybeGet(accountId).map(AccountState::getUserName).orElse(Optional.empty()); return accountCache.get(accountId).map(AccountState::getUserName).orElse(Optional.empty());
} }
} }

View File

@@ -51,7 +51,7 @@ public class AuditLogFormatter {
} }
private static Optional<Account> getAccount(AccountCache accountCache, Account.Id accountId) { private static Optional<Account> getAccount(AccountCache accountCache, Account.Id accountId) {
return accountCache.maybeGet(accountId).map(AccountState::getAccount); return accountCache.get(accountId).map(AccountState::getAccount);
} }
private static Optional<GroupDescription.Basic> getGroup( private static Optional<GroupDescription.Basic> getGroup(

View File

@@ -91,7 +91,7 @@ public class AccountIndexerImpl implements AccountIndexer {
@Override @Override
public void index(Account.Id id) throws IOException { public void index(Account.Id id) throws IOException {
for (Index<Account.Id, AccountState> i : getWriteIndexes()) { for (Index<Account.Id, AccountState> i : getWriteIndexes()) {
Optional<AccountState> accountState = byIdCache.maybeGet(id); Optional<AccountState> accountState = byIdCache.get(id);
if (accountState.isPresent()) { if (accountState.isPresent()) {
i.replace(accountState.get()); i.replace(accountState.get());
} else { } else {

View File

@@ -89,7 +89,7 @@ public class AllAccountsIndexer extends SiteIndexer<Account.Id, AccountState, Ac
() -> { () -> {
try { try {
accountCache.evict(id); accountCache.evict(id);
Optional<AccountState> a = accountCache.maybeGet(id); Optional<AccountState> a = accountCache.get(id);
if (a.isPresent()) { if (a.isPresent()) {
index.replace(a.get()); index.replace(a.get());
} else { } else {

View File

@@ -166,7 +166,7 @@ public class MailProcessor {
return; return;
} }
Account.Id accountId = accountIds.iterator().next(); Account.Id accountId = accountIds.iterator().next();
Optional<AccountState> accountState = accountCache.maybeGet(accountId); Optional<AccountState> accountState = accountCache.get(accountId);
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
log.warn(String.format("Mail: Account %s doesn't exist. Will delete message.", accountId)); log.warn(String.format("Mail: Account %s doesn't exist. Will delete message.", accountId));
return; return;

View File

@@ -349,7 +349,7 @@ public abstract class ChangeEmail extends NotificationEmail {
protected void removeUsersThatIgnoredTheChange() { protected void removeUsersThatIgnoredTheChange() {
for (Map.Entry<Account.Id, Collection<String>> e : stars.asMap().entrySet()) { for (Map.Entry<Account.Id, Collection<String>> e : stars.asMap().entrySet()) {
if (e.getValue().contains(StarredChangesUtil.IGNORE_LABEL)) { if (e.getValue().contains(StarredChangesUtil.IGNORE_LABEL)) {
args.accountCache.maybeGet(e.getKey()).ifPresent(a -> removeUser(a.getAccount())); args.accountCache.get(e.getKey()).ifPresent(a -> removeUser(a.getAccount()));
} }
} }
} }

View File

@@ -123,7 +123,7 @@ public class FromAddressGeneratorProvider implements Provider<FromAddressGenerat
public Address from(Account.Id fromId) { public Address from(Account.Id fromId) {
String senderName; String senderName;
if (fromId != null) { if (fromId != null) {
Optional<Account> a = accountCache.maybeGet(fromId).map(AccountState::getAccount); Optional<Account> a = accountCache.get(fromId).map(AccountState::getAccount);
String fullName = a.map(Account::getFullName).orElse(null); String fullName = a.map(Account::getFullName).orElse(null);
String userEmail = a.map(Account::getPreferredEmail).orElse(null); String userEmail = a.map(Account::getPreferredEmail).orElse(null);
if (canRelay(userEmail)) { if (canRelay(userEmail)) {
@@ -209,7 +209,7 @@ public class FromAddressGeneratorProvider implements Provider<FromAddressGenerat
if (fromId != null) { if (fromId != null) {
String fullName = String fullName =
accountCache.maybeGet(fromId).map(a -> a.getAccount().getFullName()).orElse(null); accountCache.get(fromId).map(a -> a.getAccount().getFullName()).orElse(null);
if (fullName == null || "".equals(fullName)) { if (fullName == null || "".equals(fullName)) {
fullName = anonymousCowardName; fullName = anonymousCowardName;
} }

View File

@@ -122,7 +122,7 @@ public abstract class OutgoingEmail {
Set<Address> smtpRcptToPlaintextOnly = new HashSet<>(); Set<Address> smtpRcptToPlaintextOnly = new HashSet<>();
if (shouldSendMessage()) { if (shouldSendMessage()) {
if (fromId != null) { if (fromId != null) {
Optional<AccountState> fromUser = args.accountCache.maybeGet(fromId); Optional<AccountState> fromUser = args.accountCache.get(fromId);
if (fromUser.isPresent()) { if (fromUser.isPresent()) {
GeneralPreferencesInfo senderPrefs = fromUser.get().getGeneralPreferences(); GeneralPreferencesInfo senderPrefs = fromUser.get().getGeneralPreferences();
if (senderPrefs != null && senderPrefs.getEmailStrategy() == CC_ON_OWN_COMMENTS) { if (senderPrefs != null && senderPrefs.getEmailStrategy() == CC_ON_OWN_COMMENTS) {
@@ -143,7 +143,7 @@ public abstract class OutgoingEmail {
// his email notifications then drop him from recipients' list. // his email notifications then drop him from recipients' list.
// In addition, check if users only want to receive plaintext email. // In addition, check if users only want to receive plaintext email.
for (Account.Id id : rcptTo) { for (Account.Id id : rcptTo) {
Optional<AccountState> thisUser = args.accountCache.maybeGet(id); Optional<AccountState> thisUser = args.accountCache.get(id);
if (thisUser.isPresent()) { if (thisUser.isPresent()) {
Account thisUserAccount = thisUser.get().getAccount(); Account thisUserAccount = thisUser.get().getAccount();
GeneralPreferencesInfo prefs = thisUser.get().getGeneralPreferences(); GeneralPreferencesInfo prefs = thisUser.get().getGeneralPreferences();
@@ -254,7 +254,7 @@ public abstract class OutgoingEmail {
protected String getFromLine() { protected String getFromLine() {
StringBuilder f = new StringBuilder(); StringBuilder f = new StringBuilder();
Optional<Account> account = args.accountCache.maybeGet(fromId).map(AccountState::getAccount); Optional<Account> account = args.accountCache.get(fromId).map(AccountState::getAccount);
if (account.isPresent()) { if (account.isPresent()) {
String name = account.get().getFullName(); String name = account.get().getFullName();
String email = account.get().getPreferredEmail(); String email = account.get().getPreferredEmail();
@@ -336,7 +336,7 @@ public abstract class OutgoingEmail {
return args.gerritPersonIdent.getName(); return args.gerritPersonIdent.getName();
} }
Optional<Account> account = args.accountCache.maybeGet(accountId).map(AccountState::getAccount); Optional<Account> account = args.accountCache.get(accountId).map(AccountState::getAccount);
String name = null; String name = null;
if (account.isPresent()) { if (account.isPresent()) {
name = account.get().getFullName(); name = account.get().getFullName();
@@ -358,7 +358,7 @@ public abstract class OutgoingEmail {
* @return name/email of account, or Anonymous Coward if unset. * @return name/email of account, or Anonymous Coward if unset.
*/ */
public String getNameEmailFor(Account.Id accountId) { public String getNameEmailFor(Account.Id accountId) {
Optional<Account> account = args.accountCache.maybeGet(accountId).map(AccountState::getAccount); Optional<Account> account = args.accountCache.get(accountId).map(AccountState::getAccount);
if (account.isPresent()) { if (account.isPresent()) {
String name = account.get().getFullName(); String name = account.get().getFullName();
String email = account.get().getPreferredEmail(); String email = account.get().getPreferredEmail();
@@ -381,7 +381,7 @@ public abstract class OutgoingEmail {
* @return name/email of account, username, or null if unset. * @return name/email of account, username, or null if unset.
*/ */
public String getUserNameEmailFor(Account.Id accountId) { public String getUserNameEmailFor(Account.Id accountId) {
Optional<AccountState> accountState = args.accountCache.maybeGet(accountId); Optional<AccountState> accountState = args.accountCache.get(accountId);
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
return null; return null;
} }
@@ -518,7 +518,7 @@ public abstract class OutgoingEmail {
} }
private Address toAddress(Account.Id id) { private Address toAddress(Account.Id id) {
Optional<Account> accountState = args.accountCache.maybeGet(id).map(AccountState::getAccount); Optional<Account> accountState = args.accountCache.get(id).map(AccountState::getAccount);
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
return null; return null;
} }

View File

@@ -132,7 +132,7 @@ public class ChangeNoteUtil {
} }
public PersonIdent newIdent(Account.Id authorId, Date when, PersonIdent serverIdent) { public PersonIdent newIdent(Account.Id authorId, Date when, PersonIdent serverIdent) {
Optional<Account> author = accountCache.maybeGet(authorId).map(AccountState::getAccount); Optional<Account> author = accountCache.get(authorId).map(AccountState::getAccount);
return new PersonIdent( return new PersonIdent(
author.map(Account::getName).orElseGet(() -> Account.getName(authorId)), author.map(Account::getName).orElseGet(() -> Account.getName(authorId)),
authorId.get() + "@" + serverId, authorId.get() + "@" + serverId,

View File

@@ -56,7 +56,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
Account.Id id = rsrc.getUser().getAccountId(); Account.Id id = rsrc.getUser().getAccountId();
return accountCache return accountCache
.maybeGet(id) .get(id)
.map(AccountState::getDiffPreferences) .map(AccountState::getDiffPreferences)
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))); .orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
} }

View File

@@ -56,7 +56,7 @@ public class GetEditPreferences implements RestReadView<AccountResource> {
Account.Id id = rsrc.getUser().getAccountId(); Account.Id id = rsrc.getUser().getAccountId();
return accountCache return accountCache
.maybeGet(id) .get(id)
.map(AccountState::getEditPreferences) .map(AccountState::getEditPreferences)
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))); .orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
} }

View File

@@ -54,7 +54,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
Account.Id id = rsrc.getUser().getAccountId(); Account.Id id = rsrc.getUser().getAccountId();
return accountCache return accountCache
.maybeGet(id) .get(id)
.map(AccountState::getGeneralPreferences) .map(AccountState::getGeneralPreferences)
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))); .orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
} }

View File

@@ -207,7 +207,7 @@ public class PostReviewersOp implements BatchUpdateOp {
List<AccountState> reviewers = List<AccountState> reviewers =
addedReviewers addedReviewers
.stream() .stream()
.map(r -> accountCache.maybeGet(r.getAccountId())) .map(r -> accountCache.get(r.getAccountId()))
.flatMap(Streams::stream) .flatMap(Streams::stream)
.collect(toList()); .collect(toList());
reviewerAdded.fire(rsrc.getChange(), patchSet, reviewers, ctx.getAccount(), ctx.getWhen()); reviewerAdded.fire(rsrc.getChange(), patchSet, reviewers, ctx.getAccount(), ctx.getWhen());

View File

@@ -197,7 +197,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
AuthRequest req = AuthRequest.forUser(user); AuthRequest req = AuthRequest.forUser(user);
req.setSkipAuthentication(true); req.setSkipAuthentication(true);
return accountCache return accountCache
.maybeGet(accountManager.authenticate(req).getAccountId()) .get(accountManager.authenticate(req).getAccountId())
.map(AccountState::getAccount); .map(AccountState::getAccount);
} catch (AccountException e) { } catch (AccountException e) {
return Optional.empty(); return Optional.empty();

View File

@@ -142,7 +142,7 @@ public class SetMembersCommand extends SshCommand {
.stream() .stream()
.map( .map(
accountId -> { accountId -> {
Optional<AccountState> accountState = accountCache.maybeGet(accountId); Optional<AccountState> accountState = accountCache.get(accountId);
if (!accountState.isPresent()) { if (!accountState.isPresent()) {
return "n/a"; return "n/a";
} }

View File

@@ -43,7 +43,7 @@ public class FakeAccountCache implements AccountCache {
} }
@Override @Override
public synchronized Optional<AccountState> maybeGet(Account.Id accountId) { public synchronized Optional<AccountState> get(Account.Id accountId) {
return Optional.ofNullable(byId.get(accountId)); return Optional.ofNullable(byId.get(accountId));
} }

View File

@@ -1682,7 +1682,7 @@ public class AccountIT extends AbstractDaemonTest {
assertThat(repo.exactRef(userRef)).isNull(); assertThat(repo.exactRef(userRef)).isNull();
} }
assertThat(accountCache.maybeGet(admin.id)).isEmpty(); assertThat(accountCache.get(admin.id)).isEmpty();
assertThat(accountQueryProvider.get().byDefault(admin.id.toString())).isEmpty(); assertThat(accountQueryProvider.get().byDefault(admin.id.toString())).isEmpty();
} }

View File

@@ -369,7 +369,7 @@ public class FromAddressGeneratorProviderTest {
private Account.Id user(String name, String email) { private Account.Id user(String name, String email) {
final AccountState s = makeUser(name, email); final AccountState s = makeUser(name, email);
expect(accountCache.maybeGet(eq(s.getAccount().getId()))).andReturn(Optional.of(s)); expect(accountCache.get(eq(s.getAccount().getId()))).andReturn(Optional.of(s));
return s.getAccount().getId(); return s.getAccount().getId();
} }