TestAccountCreation: Support specifying secondary emails
Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: I67c8bee7110ed6512615f78c5ba17c234a066c25
This commit is contained in:
		@@ -83,6 +83,11 @@ public class AccountOperationsImpl implements AccountOperations {
 | 
				
			|||||||
    accountCreation.username().ifPresent(u -> setUsername(builder, accountId, u, httpPassword));
 | 
					    accountCreation.username().ifPresent(u -> setUsername(builder, accountId, u, httpPassword));
 | 
				
			||||||
    accountCreation.status().ifPresent(builder::setStatus);
 | 
					    accountCreation.status().ifPresent(builder::setStatus);
 | 
				
			||||||
    accountCreation.active().ifPresent(builder::setActive);
 | 
					    accountCreation.active().ifPresent(builder::setActive);
 | 
				
			||||||
 | 
					    accountCreation
 | 
				
			||||||
 | 
					        .secondaryEmails()
 | 
				
			||||||
 | 
					        .forEach(
 | 
				
			||||||
 | 
					            secondaryEmail ->
 | 
				
			||||||
 | 
					                builder.addExternalId(ExternalId.createEmail(accountId, secondaryEmail)));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static InternalAccountUpdate.Builder setPreferredEmail(
 | 
					  private static InternalAccountUpdate.Builder setPreferredEmail(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.acceptance.testsuite.account;
 | 
					package com.google.gerrit.acceptance.testsuite.account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static com.google.common.base.Preconditions.checkState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.auto.value.AutoValue;
 | 
					import com.google.auto.value.AutoValue;
 | 
				
			||||||
 | 
					import com.google.common.collect.ImmutableSet;
 | 
				
			||||||
import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
 | 
					import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
 | 
				
			||||||
import com.google.gerrit.entities.Account;
 | 
					import com.google.gerrit.entities.Account;
 | 
				
			||||||
import java.util.Optional;
 | 
					import java.util.Optional;
 | 
				
			||||||
@@ -33,6 +36,8 @@ public abstract class TestAccountCreation {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  public abstract Optional<Boolean> active();
 | 
					  public abstract Optional<Boolean> active();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public abstract ImmutableSet<String> secondaryEmails();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  abstract ThrowingFunction<TestAccountCreation, Account.Id> accountCreator();
 | 
					  abstract ThrowingFunction<TestAccountCreation, Account.Id> accountCreator();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static Builder builder(ThrowingFunction<TestAccountCreation, Account.Id> accountCreator) {
 | 
					  public static Builder builder(ThrowingFunction<TestAccountCreation, Account.Id> accountCreator) {
 | 
				
			||||||
@@ -83,14 +88,29 @@ public abstract class TestAccountCreation {
 | 
				
			|||||||
      return active(false);
 | 
					      return active(false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public abstract Builder secondaryEmails(ImmutableSet<String> secondaryEmails);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    abstract ImmutableSet.Builder<String> secondaryEmailsBuilder();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Builder addSecondaryEmail(String secondaryEmail) {
 | 
				
			||||||
 | 
					      secondaryEmailsBuilder().add(secondaryEmail);
 | 
				
			||||||
 | 
					      return this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    abstract Builder accountCreator(
 | 
					    abstract Builder accountCreator(
 | 
				
			||||||
        ThrowingFunction<TestAccountCreation, Account.Id> accountCreator);
 | 
					        ThrowingFunction<TestAccountCreation, Account.Id> accountCreator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    abstract TestAccountCreation autoBuild();
 | 
					    abstract TestAccountCreation autoBuild();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Account.Id create() {
 | 
					    public Account.Id create() {
 | 
				
			||||||
      TestAccountCreation accountUpdate = autoBuild();
 | 
					      TestAccountCreation accountCreation = autoBuild();
 | 
				
			||||||
      return accountUpdate.accountCreator().applyAndThrowSilently(accountUpdate);
 | 
					      if (accountCreation.preferredEmail().isPresent()) {
 | 
				
			||||||
 | 
					        checkState(
 | 
				
			||||||
 | 
					            !accountCreation.secondaryEmails().contains(accountCreation.preferredEmail().get()),
 | 
				
			||||||
 | 
					            "preferred email %s cannot be secondary email at the same time",
 | 
				
			||||||
 | 
					            accountCreation.preferredEmail().get());
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      return accountCreation.accountCreator().applyAndThrowSilently(accountCreation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user