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

          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.testsuite.project;
      16             : 
      17             : import static java.util.Objects.requireNonNull;
      18             : 
      19             : import com.google.auto.value.AutoValue;
      20             : import com.google.common.collect.ImmutableSet;
      21             : import com.google.common.collect.Sets;
      22             : import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
      23             : import com.google.gerrit.entities.AccountGroup;
      24             : import com.google.gerrit.entities.Project;
      25             : import com.google.gerrit.extensions.client.SubmitType;
      26             : import java.util.Optional;
      27             : import java.util.Set;
      28             : import org.eclipse.jgit.lib.Constants;
      29             : 
      30             : @AutoValue
      31          35 : public abstract class TestProjectCreation {
      32             : 
      33             :   public abstract Optional<String> name();
      34             : 
      35             :   public abstract Optional<Project.NameKey> parent();
      36             : 
      37             :   public abstract ImmutableSet<String> branches();
      38             : 
      39             :   public abstract Optional<Boolean> createEmptyCommit();
      40             : 
      41             :   public abstract Optional<Boolean> permissionOnly();
      42             : 
      43             :   public abstract Optional<SubmitType> submitType();
      44             : 
      45             :   public abstract ImmutableSet<AccountGroup.UUID> owners();
      46             : 
      47             :   abstract ThrowingFunction<TestProjectCreation, Project.NameKey> projectCreator();
      48             : 
      49             :   public static Builder builder(
      50             :       ThrowingFunction<TestProjectCreation, Project.NameKey> projectCreator) {
      51          35 :     return new AutoValue_TestProjectCreation.Builder()
      52          35 :         .branches(Constants.R_HEADS + Constants.MASTER)
      53          35 :         .projectCreator(projectCreator);
      54             :   }
      55             : 
      56             :   @AutoValue.Builder
      57          35 :   public abstract static class Builder {
      58             :     public abstract TestProjectCreation.Builder name(String name);
      59             : 
      60             :     public abstract TestProjectCreation.Builder parent(Project.NameKey parent);
      61             : 
      62             :     public abstract TestProjectCreation.Builder submitType(SubmitType submitType);
      63             : 
      64             :     /**
      65             :      * Branches which should be created in the repository (with an empty root commit). The
      66             :      * "refs/heads/" prefix of the branch name can be omitted. The specified branches are ignored if
      67             :      * {@link #noEmptyCommit()} is used.
      68             :      */
      69             :     public TestProjectCreation.Builder branches(String branch1, String... otherBranches) {
      70          35 :       return branches(Sets.union(ImmutableSet.of(branch1), ImmutableSet.copyOf(otherBranches)));
      71             :     }
      72             : 
      73             :     abstract TestProjectCreation.Builder branches(Set<String> branches);
      74             : 
      75             :     public abstract TestProjectCreation.Builder createEmptyCommit(boolean value);
      76             : 
      77             :     public abstract TestProjectCreation.Builder permissionOnly(boolean value);
      78             : 
      79             :     /** Skips the empty commit on creation. This means that project's branches will not exist. */
      80             :     public TestProjectCreation.Builder noEmptyCommit() {
      81           2 :       return createEmptyCommit(false);
      82             :     }
      83             : 
      84             :     public TestProjectCreation.Builder addOwner(AccountGroup.UUID owner) {
      85           1 :       ownersBuilder().add(requireNonNull(owner, "owner"));
      86           1 :       return this;
      87             :     }
      88             : 
      89             :     abstract ImmutableSet.Builder<AccountGroup.UUID> ownersBuilder();
      90             : 
      91             :     abstract TestProjectCreation.Builder projectCreator(
      92             :         ThrowingFunction<TestProjectCreation, Project.NameKey> projectCreator);
      93             : 
      94             :     abstract TestProjectCreation autoBuild();
      95             : 
      96             :     /**
      97             :      * Executes the project creation as specified.
      98             :      *
      99             :      * @return the name of the created project
     100             :      */
     101             :     public Project.NameKey create() {
     102          35 :       TestProjectCreation creation = autoBuild();
     103          35 :       return creation.projectCreator().applyAndThrowSilently(creation);
     104             :     }
     105             :   }
     106             : }

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