LCOV - code coverage report
Current view: top level - acceptance/testsuite/change - PerDraftCommentOperationsImpl.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 10 10 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          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             : import static com.google.gerrit.acceptance.testsuite.change.PerCommentOperationsImpl.toTestComment;
      19             : 
      20             : import com.google.gerrit.entities.HumanComment;
      21             : import com.google.gerrit.server.CommentsUtil;
      22             : import com.google.gerrit.server.notedb.ChangeNotes;
      23             : import com.google.inject.Inject;
      24             : import com.google.inject.assistedinject.Assisted;
      25             : 
      26             : /**
      27             :  * The implementation of {@link PerDraftCommentOperationsImpl}.
      28             :  *
      29             :  * <p>There is only one implementation of {@link PerDraftCommentOperations}. Nevertheless, we keep
      30             :  * the separation between interface and implementation to enhance clarity.
      31             :  */
      32             : public class PerDraftCommentOperationsImpl implements PerDraftCommentOperations {
      33             :   private final CommentsUtil commentsUtil;
      34             : 
      35             :   private final ChangeNotes changeNotes;
      36             :   private final String commentUuid;
      37             : 
      38             :   public interface Factory {
      39             :     PerDraftCommentOperationsImpl create(ChangeNotes changeNotes, String commentUuid);
      40             :   }
      41             : 
      42             :   @Inject
      43             :   public PerDraftCommentOperationsImpl(
      44           2 :       CommentsUtil commentsUtil, @Assisted ChangeNotes changeNotes, @Assisted String commentUuid) {
      45           2 :     this.commentsUtil = commentsUtil;
      46           2 :     this.changeNotes = changeNotes;
      47           2 :     this.commentUuid = commentUuid;
      48           2 :   }
      49             : 
      50             :   @Override
      51             :   public TestHumanComment get() {
      52           2 :     HumanComment comment =
      53           2 :         commentsUtil.draftByChange(changeNotes).stream()
      54           2 :             .filter(foundComment -> foundComment.key.uuid.equals(commentUuid))
      55           2 :             .collect(onlyElement());
      56           2 :     return toTestComment(comment);
      57             :   }
      58             : }

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