LCOV - code coverage report
Current view: top level - server/extensions/events - AgreementSignup.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 6 15 40.0 %
Date: 2022-11-19 15:00:39 Functions: 2 6 33.3 %

          Line data    Source code
       1             : // Copyright (C) 2015 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.extensions.events;
      16             : 
      17             : import com.google.gerrit.extensions.common.AccountInfo;
      18             : import com.google.gerrit.extensions.events.AgreementSignupListener;
      19             : import com.google.gerrit.server.account.AccountState;
      20             : import com.google.gerrit.server.plugincontext.PluginSetContext;
      21             : import com.google.inject.Inject;
      22             : import com.google.inject.Singleton;
      23             : 
      24             : /** Helper class to fire an event when a user has signed a contributor agreement. */
      25             : @Singleton
      26             : public class AgreementSignup {
      27             :   private final PluginSetContext<AgreementSignupListener> listeners;
      28             :   private final EventUtil util;
      29             : 
      30             :   @Inject
      31         148 :   AgreementSignup(PluginSetContext<AgreementSignupListener> listeners, EventUtil util) {
      32         148 :     this.listeners = listeners;
      33         148 :     this.util = util;
      34         148 :   }
      35             : 
      36             :   public void fire(AccountState accountState, String agreementName) {
      37           1 :     if (listeners.isEmpty()) {
      38           1 :       return;
      39             :     }
      40           0 :     Event event = new Event(util.accountInfo(accountState), agreementName);
      41           0 :     listeners.runEach(l -> l.onAgreementSignup(event));
      42           0 :   }
      43             : 
      44             :   /** Event to be fired when a user has signed a contributor agreement. */
      45             :   private static class Event extends AbstractNoNotifyEvent
      46             :       implements AgreementSignupListener.Event {
      47             :     private final AccountInfo account;
      48             :     private final String agreementName;
      49             : 
      50           0 :     Event(AccountInfo account, String agreementName) {
      51           0 :       this.account = account;
      52           0 :       this.agreementName = agreementName;
      53           0 :     }
      54             : 
      55             :     @Override
      56             :     public AccountInfo getAccount() {
      57           0 :       return account;
      58             :     }
      59             : 
      60             :     @Override
      61             :     public String getAgreementName() {
      62           0 :       return agreementName;
      63             :     }
      64             :   }
      65             : }

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