LCOV - code coverage report
Current view: top level - acceptance/testsuite/change - PerCommentOperationsImpl.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 16 16 100.0 %
Date: 2022-11-19 15:00:39 Functions: 4 4 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             : 
      19             : import com.google.gerrit.entities.HumanComment;
      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 PerCommentOperations}.
      27             :  *
      28             :  * <p>There is only one implementation of {@link PerCommentOperations}. Nevertheless, we keep the
      29             :  * separation between interface and implementation to enhance clarity.
      30             :  */
      31             : public class PerCommentOperationsImpl implements PerCommentOperations {
      32             :   private final CommentsUtil commentsUtil;
      33             : 
      34             :   private final ChangeNotes changeNotes;
      35             :   private final String commentUuid;
      36             : 
      37             :   public interface Factory {
      38             :     PerCommentOperationsImpl create(ChangeNotes changeNotes, String commentUuid);
      39             :   }
      40             : 
      41             :   @Inject
      42             :   public PerCommentOperationsImpl(
      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 TestHumanComment get() {
      51           1 :     HumanComment comment =
      52           1 :         commentsUtil.publishedHumanCommentsByChange(changeNotes).stream()
      53           1 :             .filter(foundComment -> foundComment.key.uuid.equals(commentUuid))
      54           1 :             .collect(onlyElement());
      55           1 :     return toTestComment(comment);
      56             :   }
      57             : 
      58             :   static TestHumanComment toTestComment(HumanComment comment) {
      59           2 :     return TestHumanComment.builder()
      60           2 :         .uuid(comment.key.uuid)
      61           2 :         .parentUuid(comment.parentUuid)
      62           2 :         .tag(comment.tag)
      63           2 :         .unresolved(comment.unresolved)
      64           2 :         .build();
      65             :   }
      66             : }

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