LCOV - code coverage report
Current view: top level - acceptance/testsuite/change - TestPatchsetCreation.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 8 10 80.0 %
Date: 2022-11-19 15:00:39 Functions: 9 10 90.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 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.change;
      16             : 
      17             : import com.google.auto.value.AutoValue;
      18             : import com.google.common.collect.ImmutableList;
      19             : import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
      20             : import com.google.gerrit.entities.PatchSet;
      21             : import com.google.gerrit.server.edit.tree.TreeModification;
      22             : import java.util.Optional;
      23             : 
      24             : /** Initial attributes of the patchset. If not provided, arbitrary values will be used. */
      25             : @AutoValue
      26           5 : public abstract class TestPatchsetCreation {
      27             : 
      28             :   public abstract Optional<String> commitMessage();
      29             : 
      30             :   public abstract ImmutableList<TreeModification> treeModifications();
      31             : 
      32             :   public abstract Optional<ImmutableList<TestCommitIdentifier>> parents();
      33             : 
      34             :   abstract ThrowingFunction<TestPatchsetCreation, PatchSet.Id> patchsetCreator();
      35             : 
      36             :   public static TestPatchsetCreation.Builder builder(
      37             :       ThrowingFunction<TestPatchsetCreation, PatchSet.Id> patchsetCreator) {
      38           5 :     return new AutoValue_TestPatchsetCreation.Builder().patchsetCreator(patchsetCreator);
      39             :   }
      40             : 
      41             :   @AutoValue.Builder
      42           5 :   public abstract static class Builder {
      43             : 
      44             :     public abstract Builder commitMessage(String commitMessage);
      45             : 
      46             :     /** Modified file of the patchset. The file content is specified via the returned builder. */
      47             :     public FileContentBuilder<Builder> file(String filePath) {
      48           5 :       return new FileContentBuilder<>(this, filePath, 0, treeModificationsBuilder()::add);
      49             :     }
      50             : 
      51             :     /** Modified file of the patchset. The file content is specified via the returned builder. */
      52             :     public FileContentBuilder<Builder> file(String filePath, int newGitFileMode) {
      53           0 :       return new FileContentBuilder<>(
      54           0 :           this, filePath, newGitFileMode, treeModificationsBuilder()::add);
      55             :     }
      56             : 
      57             :     abstract ImmutableList.Builder<TreeModification> treeModificationsBuilder();
      58             : 
      59             :     /**
      60             :      * Parent commit of the change. The commit can be specified via various means in the returned
      61             :      * builder.
      62             :      *
      63             :      * <p>This method will just change the parent but not influence the contents of the patchset
      64             :      * commit.
      65             :      *
      66             :      * <p>It's possible to switch from a change representing a merge commit to a change not being a
      67             :      * merge commit with this method.
      68             :      */
      69             :     public ParentBuilder<Builder> parent() {
      70           3 :       return new ParentBuilder<>(parent -> parents(ImmutableList.of(parent)));
      71             :     }
      72             : 
      73             :     /**
      74             :      * Parent commits of the change. Each parent commit can be specified via various means in the
      75             :      * returned builder. The order of the parents matters and is preserved (first parent commit in
      76             :      * fluent change -> first parent of the change).
      77             :      *
      78             :      * <p>This method will just change the parents but not influence the contents of the patchset
      79             :      * commit.
      80             :      *
      81             :      * <p>It's possible to switch from a change representing a non-merge commit to a change which is
      82             :      * a merge commit with this method.
      83             :      */
      84             :     public ParentBuilder<MultipleParentBuilder<Builder>> parents() {
      85           2 :       return new ParentBuilder<>(parent -> new MultipleParentBuilder<>(this::parents, parent));
      86             :     }
      87             : 
      88             :     abstract Builder parents(ImmutableList<TestCommitIdentifier> value);
      89             : 
      90             :     abstract TestPatchsetCreation.Builder patchsetCreator(
      91             :         ThrowingFunction<TestPatchsetCreation, PatchSet.Id> patchsetCreator);
      92             : 
      93             :     abstract TestPatchsetCreation autoBuild();
      94             : 
      95             :     /**
      96             :      * Creates the patchset.
      97             :      *
      98             :      * @return the {@code PatchSet.Id} of the created patchset
      99             :      */
     100             :     public PatchSet.Id create() {
     101           5 :       TestPatchsetCreation patchsetCreation = autoBuild();
     102           5 :       return patchsetCreation.patchsetCreator().applyAndThrowSilently(patchsetCreation);
     103             :     }
     104             :   }
     105             : }

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