Line data Source code
1 : // Copyright (C) 2021 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.server.approval.testing; 16 : 17 : import com.google.gerrit.entities.Account; 18 : import com.google.gerrit.entities.PatchSet; 19 : import com.google.gerrit.entities.PatchSetApproval; 20 : import com.google.gerrit.entities.PatchSetApproval.UUID; 21 : import com.google.gerrit.server.approval.PatchSetApprovalUuidGenerator; 22 : import java.time.Instant; 23 : import javax.inject.Singleton; 24 : 25 : /** 26 : * Implementation of {@link PatchSetApprovalUuidGenerator} that returns predictable {@link UUID}. 27 : */ 28 : @Singleton 29 1 : public class TestPatchSetApprovalUuidGenerator implements PatchSetApprovalUuidGenerator { 30 : 31 1 : private int invocationCount = 0; 32 : 33 : @Override 34 : public UUID get( 35 : PatchSet.Id patchSetId, Account.Id accountId, String label, short value, Instant granted) { 36 1 : invocationCount++; 37 1 : return PatchSetApproval.uuid( 38 1 : String.format( 39 : "%s_%s_%s_%s_%s_%s", 40 1 : patchSetId.changeId().get(), 41 1 : patchSetId.get(), 42 1 : accountId.get(), 43 : label, 44 1 : value, 45 1 : invocationCount) 46 1 : .replace("-", "_") 47 1 : .toLowerCase()); 48 : } 49 : }