LCOV - code coverage report
Current view: top level - acceptance - ChangeIndexedCounter.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 17 76.5 %
Date: 2022-11-19 15:00:39 Functions: 5 7 71.4 %

          Line data    Source code
       1             : // Copyright (C) 2018 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;
      16             : 
      17             : import static com.google.common.truth.Truth.assertThat;
      18             : 
      19             : import com.google.common.util.concurrent.AtomicLongMap;
      20             : import com.google.gerrit.extensions.common.ChangeInfo;
      21             : import com.google.gerrit.extensions.events.ChangeIndexedListener;
      22             : 
      23           3 : public class ChangeIndexedCounter implements ChangeIndexedListener {
      24           3 :   private final AtomicLongMap<Integer> countsByChange = AtomicLongMap.create();
      25             : 
      26             :   @Override
      27             :   public void onChangeIndexed(String projectName, int id) {
      28           3 :     countsByChange.incrementAndGet(id);
      29           3 :   }
      30             : 
      31             :   @Override
      32             :   public void onChangeDeleted(int id) {
      33           0 :     countsByChange.incrementAndGet(id);
      34           0 :   }
      35             : 
      36             :   public void clear() {
      37           3 :     countsByChange.clear();
      38           3 :   }
      39             : 
      40             :   public long getCount(ChangeInfo info) {
      41           1 :     return countsByChange.get(info._number);
      42             :   }
      43             : 
      44             :   public void assertReindexOf(ChangeInfo info) {
      45           0 :     assertReindexOf(info, 1);
      46           0 :   }
      47             : 
      48             :   public void assertReindexOf(ChangeInfo info, long expectedCount) {
      49           2 :     if (expectedCount == 0) {
      50           1 :       assertThat(countsByChange.asMap()).isEmpty();
      51           1 :       return;
      52             :     }
      53           1 :     assertThat(countsByChange.asMap()).containsExactly(info._number, expectedCount);
      54           1 :     clear();
      55           1 :   }
      56             : }

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