AccountsUpdate: Make non-abstract methods final
These methods not being final leading to confusing behavior when using
mocks in tests.
Release-Notes: skip
Google-Bug-Id: b/333350069
Change-Id: I296837fba0fd46e6022d87d7fe753c66515b7e0b
diff --git a/java/com/google/gerrit/server/account/AccountsUpdate.java b/java/com/google/gerrit/server/account/AccountsUpdate.java
index 5951a73..7cebea7 100644
--- a/java/com/google/gerrit/server/account/AccountsUpdate.java
+++ b/java/com/google/gerrit/server/account/AccountsUpdate.java
@@ -20,6 +20,7 @@
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gerrit.entities.Account;
@@ -145,7 +146,7 @@
* would only contain the account ID).
*/
@CanIgnoreReturnValue
- public AccountState insert(
+ public final AccountState insert(
String message, Account.Id accountId, Consumer<AccountDelta.Builder> init)
throws IOException, ConfigInvalidException {
return insert(message, accountId, AccountsUpdate.fromConsumer(init));
@@ -171,7 +172,7 @@
* instead, i.e. the update does not depend on the current account state.
*/
@CanIgnoreReturnValue
- public Optional<AccountState> update(
+ public final Optional<AccountState> update(
String message, Account.Id accountId, Consumer<AccountDelta.Builder> update)
throws IOException, ConfigInvalidException {
return update(message, accountId, AccountsUpdate.fromConsumer(update));
@@ -193,7 +194,7 @@
* @throws ConfigInvalidException if any of the account fields has an invalid value
*/
@CanIgnoreReturnValue
- public Optional<AccountState> update(
+ public final Optional<AccountState> update(
String message, Account.Id accountId, ConfigureDeltaFromState configureDeltaFromState)
throws IOException, ConfigInvalidException {
return updateBatch(
@@ -212,7 +213,7 @@
* together have this property) will always prevent the entire batch from being executed.
*/
@CanIgnoreReturnValue
- public ImmutableList<Optional<AccountState>> updateBatch(List<UpdateArguments> updates)
+ public final ImmutableList<Optional<AccountState>> updateBatch(List<UpdateArguments> updates)
throws IOException, ConfigInvalidException {
checkArgument(
updates.stream().map(u -> u.accountId.get()).distinct().count() == updates.size(),
@@ -231,7 +232,8 @@
public abstract void delete(String message, Account.Id accountId)
throws IOException, ConfigInvalidException;
- protected abstract ImmutableList<Optional<AccountState>> executeUpdates(
+ @VisibleForTesting // productionVisibility: protected
+ public abstract ImmutableList<Optional<AccountState>> executeUpdates(
List<UpdateArguments> updates) throws ConfigInvalidException, IOException;
private static PersonIdent createPersonIdent(
diff --git a/java/com/google/gerrit/server/account/storage/notedb/AccountsUpdateNoteDbImpl.java b/java/com/google/gerrit/server/account/storage/notedb/AccountsUpdateNoteDbImpl.java
index ad3681d..27a43ba 100644
--- a/java/com/google/gerrit/server/account/storage/notedb/AccountsUpdateNoteDbImpl.java
+++ b/java/com/google/gerrit/server/account/storage/notedb/AccountsUpdateNoteDbImpl.java
@@ -380,7 +380,8 @@
}
@Override
- protected ImmutableList<Optional<AccountState>> executeUpdates(List<UpdateArguments> updates)
+ @VisibleForTesting
+ public ImmutableList<Optional<AccountState>> executeUpdates(List<UpdateArguments> updates)
throws ConfigInvalidException, IOException {
return execute(updates.stream().map(this::createExecutableUpdate).collect(toImmutableList()));
}