LCOV - code coverage report
Current view: top level - acceptance/testsuite/account - TestAccountCreation.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 20 75.0 %
Date: 2022-11-19 15:00:39 Functions: 7 12 58.3 %

          Line data    Source code
       1             : // Copyright (C) 2018 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.acceptance.testsuite.account;
      16             : 
      17             : import static com.google.common.base.Preconditions.checkState;
      18             : 
      19             : import com.google.auto.value.AutoValue;
      20             : import com.google.common.collect.ImmutableSet;
      21             : import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
      22             : import com.google.gerrit.entities.Account;
      23             : import java.util.Optional;
      24             : import java.util.Set;
      25             : 
      26             : @AutoValue
      27          11 : public abstract class TestAccountCreation {
      28             :   public abstract Optional<String> fullname();
      29             : 
      30             :   public abstract Optional<String> httpPassword();
      31             : 
      32             :   public abstract Optional<String> preferredEmail();
      33             : 
      34             :   public abstract Optional<String> username();
      35             : 
      36             :   public abstract Optional<String> status();
      37             : 
      38             :   public abstract Optional<Boolean> active();
      39             : 
      40             :   public abstract ImmutableSet<String> secondaryEmails();
      41             : 
      42             :   abstract ThrowingFunction<TestAccountCreation, Account.Id> accountCreator();
      43             : 
      44             :   public static Builder builder(ThrowingFunction<TestAccountCreation, Account.Id> accountCreator) {
      45          11 :     return new AutoValue_TestAccountCreation.Builder()
      46          11 :         .accountCreator(accountCreator)
      47          11 :         .httpPassword("http-pass");
      48             :   }
      49             : 
      50             :   @AutoValue.Builder
      51          11 :   public abstract static class Builder {
      52             :     public abstract Builder fullname(String fullname);
      53             : 
      54             :     public Builder clearFullname() {
      55           0 :       return fullname("");
      56             :     }
      57             : 
      58             :     public abstract Builder httpPassword(String httpPassword);
      59             : 
      60             :     public Builder clearHttpPassword() {
      61           0 :       return httpPassword("");
      62             :     }
      63             : 
      64             :     public abstract Builder preferredEmail(String preferredEmail);
      65             : 
      66             :     public Builder clearPreferredEmail() {
      67           0 :       return preferredEmail("");
      68             :     }
      69             : 
      70             :     public abstract Builder username(String username);
      71             : 
      72             :     public Builder clearUsername() {
      73           0 :       return username("");
      74             :     }
      75             : 
      76             :     public abstract Builder status(String status);
      77             : 
      78             :     public Builder clearStatus() {
      79           0 :       return status("");
      80             :     }
      81             : 
      82             :     abstract Builder active(boolean active);
      83             : 
      84             :     public Builder active() {
      85           1 :       return active(true);
      86             :     }
      87             : 
      88             :     public Builder inactive() {
      89           2 :       return active(false);
      90             :     }
      91             : 
      92             :     public abstract Builder secondaryEmails(Set<String> secondaryEmails);
      93             : 
      94             :     abstract ImmutableSet.Builder<String> secondaryEmailsBuilder();
      95             : 
      96             :     public Builder addSecondaryEmail(String secondaryEmail) {
      97           1 :       secondaryEmailsBuilder().add(secondaryEmail);
      98           1 :       return this;
      99             :     }
     100             : 
     101             :     abstract Builder accountCreator(
     102             :         ThrowingFunction<TestAccountCreation, Account.Id> accountCreator);
     103             : 
     104             :     abstract TestAccountCreation autoBuild();
     105             : 
     106             :     public Account.Id create() {
     107          11 :       TestAccountCreation accountCreation = autoBuild();
     108          11 :       if (accountCreation.preferredEmail().isPresent()) {
     109           4 :         checkState(
     110           4 :             !accountCreation.secondaryEmails().contains(accountCreation.preferredEmail().get()),
     111             :             "preferred email %s cannot be secondary email at the same time",
     112           4 :             accountCreation.preferredEmail().get());
     113             :       }
     114          11 :       return accountCreation.accountCreator().applyAndThrowSilently(accountCreation);
     115             :     }
     116             :   }
     117             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750