All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gerrit.acceptance.testsuite.account.TestAccountCreation Maven / Gradle / Ivy

There is a newer version: 3.11.0
Show newest version
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.acceptance.testsuite.account;

import static com.google.common.base.Preconditions.checkState;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
import com.google.gerrit.entities.Account;
import java.util.Optional;
import java.util.Set;

@AutoValue
public abstract class TestAccountCreation {
  public abstract Optional fullname();

  public abstract Optional httpPassword();

  public abstract Optional preferredEmail();

  public abstract Optional username();

  public abstract Optional status();

  public abstract Optional active();

  public abstract ImmutableSet secondaryEmails();

  abstract ThrowingFunction accountCreator();

  public static Builder builder(
      ThrowingFunction accountCreator,
      boolean arePasswordsAllowed) {
    TestAccountCreation.Builder builder =
        new AutoValue_TestAccountCreation.Builder().accountCreator(accountCreator);
    if (arePasswordsAllowed) {
      builder.httpPassword("http-pass");
    }
    return builder;
  }

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder fullname(String fullname);

    @CanIgnoreReturnValue
    public Builder clearFullname() {
      return fullname("");
    }

    public abstract Builder httpPassword(String httpPassword);

    @CanIgnoreReturnValue
    public Builder clearHttpPassword() {
      return httpPassword("");
    }

    public abstract Builder preferredEmail(String preferredEmail);

    @CanIgnoreReturnValue
    public Builder clearPreferredEmail() {
      return preferredEmail("");
    }

    public abstract Builder username(String username);

    @CanIgnoreReturnValue
    public Builder clearUsername() {
      return username("");
    }

    public abstract Builder status(String status);

    @CanIgnoreReturnValue
    public Builder clearStatus() {
      return status("");
    }

    abstract Builder active(boolean active);

    @CanIgnoreReturnValue
    public Builder active() {
      return active(true);
    }

    @CanIgnoreReturnValue
    public Builder inactive() {
      return active(false);
    }

    public abstract Builder secondaryEmails(Set secondaryEmails);

    abstract ImmutableSet.Builder secondaryEmailsBuilder();

    @CanIgnoreReturnValue
    public Builder addSecondaryEmail(String secondaryEmail) {
      secondaryEmailsBuilder().add(secondaryEmail);
      return this;
    }

    abstract Builder accountCreator(
        ThrowingFunction accountCreator);

    abstract TestAccountCreation autoBuild();

    @CanIgnoreReturnValue
    public Account.Id create() {
      TestAccountCreation accountCreation = autoBuild();
      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);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy