LCOV - code coverage report
Current view: top level - server/api/changes - RevisionReviewerApiImpl.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 12 18 66.7 %
Date: 2022-11-19 15:00:39 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2017 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.api.changes;
      16             : 
      17             : import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
      18             : 
      19             : import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
      20             : import com.google.gerrit.extensions.api.changes.RevisionReviewerApi;
      21             : import com.google.gerrit.extensions.restapi.RestApiException;
      22             : import com.google.gerrit.server.change.ReviewerResource;
      23             : import com.google.gerrit.server.change.VoteResource;
      24             : import com.google.gerrit.server.restapi.change.DeleteVote;
      25             : import com.google.gerrit.server.restapi.change.Votes;
      26             : import com.google.inject.Inject;
      27             : import com.google.inject.assistedinject.Assisted;
      28             : import java.util.Map;
      29             : 
      30             : public class RevisionReviewerApiImpl implements RevisionReviewerApi {
      31             :   interface Factory {
      32             :     RevisionReviewerApiImpl create(ReviewerResource r);
      33             :   }
      34             : 
      35             :   private final ReviewerResource reviewer;
      36             :   private final Votes.List listVotes;
      37             :   private final DeleteVote deleteVote;
      38             : 
      39             :   @Inject
      40             :   RevisionReviewerApiImpl(
      41           4 :       Votes.List listVotes, DeleteVote deleteVote, @Assisted ReviewerResource reviewer) {
      42           4 :     this.listVotes = listVotes;
      43           4 :     this.deleteVote = deleteVote;
      44           4 :     this.reviewer = reviewer;
      45           4 :   }
      46             : 
      47             :   @Override
      48             :   public Map<String, Short> votes() throws RestApiException {
      49             :     try {
      50           3 :       return listVotes.apply(reviewer).value();
      51           0 :     } catch (Exception e) {
      52           0 :       throw asRestApiException("Cannot list votes", e);
      53             :     }
      54             :   }
      55             : 
      56             :   @Override
      57             :   public void deleteVote(String label) throws RestApiException {
      58             :     try {
      59           3 :       deleteVote.apply(new VoteResource(reviewer, label), null);
      60           0 :     } catch (Exception e) {
      61           0 :       throw asRestApiException("Cannot delete vote", e);
      62           3 :     }
      63           3 :   }
      64             : 
      65             :   @Override
      66             :   public void deleteVote(DeleteVoteInput input) throws RestApiException {
      67             :     try {
      68           1 :       deleteVote.apply(new VoteResource(reviewer, input.label), input);
      69           0 :     } catch (Exception e) {
      70           0 :       throw asRestApiException("Cannot delete vote", e);
      71           1 :     }
      72           1 :   }
      73             : }

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