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 com.google.auto.value.AutoValue; 18 : import com.google.common.collect.ImmutableSet; 19 : import com.google.common.collect.Sets; 20 : import com.google.gerrit.acceptance.testsuite.ThrowingConsumer; 21 : import java.util.Optional; 22 : import java.util.Set; 23 : import java.util.function.Function; 24 : 25 : @AutoValue 26 3 : public abstract class TestAccountUpdate { 27 : public abstract Optional<String> fullname(); 28 : 29 : public abstract Optional<String> httpPassword(); 30 : 31 : public abstract Optional<String> preferredEmail(); 32 : 33 : public abstract Optional<String> username(); 34 : 35 : public abstract Optional<String> status(); 36 : 37 : public abstract Optional<Boolean> active(); 38 : 39 : public abstract Function<ImmutableSet<String>, Set<String>> secondaryEmailsModification(); 40 : 41 : abstract ThrowingConsumer<TestAccountUpdate> accountUpdater(); 42 : 43 : public static Builder builder(ThrowingConsumer<TestAccountUpdate> accountUpdater) { 44 3 : return new AutoValue_TestAccountUpdate.Builder() 45 3 : .accountUpdater(accountUpdater) 46 3 : .secondaryEmailsModification(in -> in) 47 3 : .httpPassword("http-pass"); 48 : } 49 : 50 : @AutoValue.Builder 51 3 : 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 0 : return active(true); 86 : } 87 : 88 : public Builder inactive() { 89 2 : return active(false); 90 : } 91 : 92 : abstract Builder secondaryEmailsModification( 93 : Function<ImmutableSet<String>, Set<String>> secondaryEmailsModification); 94 : 95 : abstract Function<ImmutableSet<String>, Set<String>> secondaryEmailsModification(); 96 : 97 : public Builder clearSecondaryEmails() { 98 0 : return secondaryEmailsModification(originalSecondaryEmail -> ImmutableSet.of()); 99 : } 100 : 101 : public Builder addSecondaryEmail(String secondaryEmail) { 102 0 : Function<ImmutableSet<String>, Set<String>> secondaryEmailsModification = 103 0 : secondaryEmailsModification(); 104 0 : secondaryEmailsModification( 105 : originalSecondaryEmails -> 106 0 : Sets.union( 107 0 : secondaryEmailsModification.apply(originalSecondaryEmails), 108 0 : ImmutableSet.of(secondaryEmail))); 109 0 : return this; 110 : } 111 : 112 : public Builder removeSecondaryEmail(String secondaryEmail) { 113 0 : Function<ImmutableSet<String>, Set<String>> previousModification = 114 0 : secondaryEmailsModification(); 115 0 : secondaryEmailsModification( 116 : originalSecondaryEmails -> 117 0 : Sets.difference( 118 0 : previousModification.apply(originalSecondaryEmails), 119 0 : ImmutableSet.of(secondaryEmail))); 120 0 : return this; 121 : } 122 : 123 : abstract Builder accountUpdater(ThrowingConsumer<TestAccountUpdate> accountUpdater); 124 : 125 : abstract TestAccountUpdate autoBuild(); 126 : 127 : public void update() { 128 3 : TestAccountUpdate accountUpdate = autoBuild(); 129 3 : accountUpdate.accountUpdater().acceptAndThrowSilently(accountUpdate); 130 3 : } 131 : } 132 : }