Line data Source code
1 : // Copyright (C) 2020 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.change; 16 : 17 : import com.google.gerrit.entities.Change; 18 : import com.google.gerrit.entities.PatchSet; 19 : import java.util.function.Function; 20 : import org.eclipse.jgit.lib.ObjectId; 21 : 22 : /** Builder to simplify parent specification of a change. */ 23 : public class ParentBuilder<T> { 24 : private final Function<TestCommitIdentifier, T> parentToBuilderAdder; 25 : 26 5 : public ParentBuilder(Function<TestCommitIdentifier, T> parentToBuilderAdder) { 27 5 : this.parentToBuilderAdder = parentToBuilderAdder; 28 5 : } 29 : 30 : /** Use the commit identified by the specified SHA-1. */ 31 : public T commit(ObjectId commitSha1) { 32 1 : return parentToBuilderAdder.apply(TestCommitIdentifier.ofCommitSha1(commitSha1)); 33 : } 34 : 35 : /** 36 : * Use the commit which is at the tip of the specified branch. Short branch names (without 37 : * refs/heads) are automatically expanded. 38 : */ 39 : public T tipOfBranch(String branchName) { 40 2 : return parentToBuilderAdder.apply(TestCommitIdentifier.ofBranch(branchName)); 41 : } 42 : 43 : /** Use the current patchset commit of the indicated change. */ 44 : public T change(Change.Id changeId) { 45 4 : return parentToBuilderAdder.apply(TestCommitIdentifier.ofChangeId(changeId)); 46 : } 47 : 48 : /** Use the commit identified by the specified patchset. */ 49 : public T patchset(PatchSet.Id patchsetId) { 50 3 : return parentToBuilderAdder.apply(TestCommitIdentifier.ofPatchsetId(patchsetId)); 51 : } 52 : }