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 static com.google.common.collect.MoreCollectors.onlyElement; 18 : 19 : import com.google.gerrit.entities.RobotComment; 20 : import com.google.gerrit.server.CommentsUtil; 21 : import com.google.gerrit.server.notedb.ChangeNotes; 22 : import com.google.inject.Inject; 23 : import com.google.inject.assistedinject.Assisted; 24 : 25 : /** 26 : * The implementation of {@link PerRobotCommentOperations}. 27 : * 28 : * <p>There is only one implementation of {@link PerRobotCommentOperations}. Nevertheless, we keep 29 : * the separation between interface and implementation to enhance clarity. 30 : */ 31 : public class PerRobotCommentOperationsImpl implements PerRobotCommentOperations { 32 : private final CommentsUtil commentsUtil; 33 : 34 : private final ChangeNotes changeNotes; 35 : private final String commentUuid; 36 : 37 : public interface Factory { 38 : PerRobotCommentOperationsImpl create(ChangeNotes changeNotes, String commentUuid); 39 : } 40 : 41 : @Inject 42 : public PerRobotCommentOperationsImpl( 43 1 : CommentsUtil commentsUtil, @Assisted ChangeNotes changeNotes, @Assisted String commentUuid) { 44 1 : this.commentsUtil = commentsUtil; 45 1 : this.changeNotes = changeNotes; 46 1 : this.commentUuid = commentUuid; 47 1 : } 48 : 49 : @Override 50 : public TestRobotComment get() { 51 1 : RobotComment comment = 52 1 : commentsUtil.robotCommentsByChange(changeNotes).stream() 53 1 : .filter(foundComment -> foundComment.key.uuid.equals(commentUuid)) 54 1 : .collect(onlyElement()); 55 1 : return toTestRobotComment(comment); 56 : } 57 : 58 : static TestRobotComment toTestRobotComment(RobotComment robotComment) { 59 1 : return TestRobotComment.builder() 60 1 : .uuid(robotComment.key.uuid) 61 1 : .parentUuid(robotComment.parentUuid) 62 1 : .build(); 63 : } 64 : }