LCOV - code coverage report
Current view: top level - server/util - OneOffRequestContext.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 7 7 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          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.util;
      16             : 
      17             : import com.google.gerrit.entities.Account;
      18             : import com.google.gerrit.server.IdentifiedUser;
      19             : import com.google.gerrit.server.InternalUser;
      20             : import com.google.inject.Inject;
      21             : import com.google.inject.Singleton;
      22             : 
      23             : /**
      24             :  * Helper to create one-off request contexts.
      25             :  *
      26             :  * <p>The user in the request context is {@link InternalUser} or the {@link IdentifiedUser}
      27             :  * associated to the userId passed as parameter.
      28             :  */
      29             : @Singleton
      30             : public class OneOffRequestContext {
      31             :   private final InternalUser.Factory userFactory;
      32             :   private final ThreadLocalRequestContext requestContext;
      33             :   private final IdentifiedUser.GenericFactory identifiedUserFactory;
      34             : 
      35             :   @Inject
      36             :   OneOffRequestContext(
      37             :       InternalUser.Factory userFactory,
      38             :       ThreadLocalRequestContext requestContext,
      39         152 :       IdentifiedUser.GenericFactory identifiedUserFactory) {
      40         152 :     this.userFactory = userFactory;
      41         152 :     this.requestContext = requestContext;
      42         152 :     this.identifiedUserFactory = identifiedUserFactory;
      43         152 :   }
      44             : 
      45             :   public ManualRequestContext open() {
      46          41 :     return new ManualRequestContext(userFactory.create(), requestContext);
      47             :   }
      48             : 
      49             :   public ManualRequestContext openAs(Account.Id userId) {
      50           9 :     return new ManualRequestContext(identifiedUserFactory.create(userId), requestContext);
      51             :   }
      52             : }

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