LCOV - code coverage report
Current view: top level - extensions/common/testing - CommitInfoSubject.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 16 20 80.0 %
Date: 2022-11-19 15:00:39 Functions: 10 12 83.3 %

          Line data    Source code
       1             : // Copyright (C) 2017 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.extensions.common.testing;
      16             : 
      17             : import static com.google.common.truth.Truth.assertAbout;
      18             : import static com.google.gerrit.extensions.common.testing.GitPersonSubject.gitPersons;
      19             : import static com.google.gerrit.truth.ListSubject.elements;
      20             : 
      21             : import com.google.common.truth.Correspondence;
      22             : import com.google.common.truth.FailureMetadata;
      23             : import com.google.common.truth.IterableSubject;
      24             : import com.google.common.truth.StringSubject;
      25             : import com.google.common.truth.Subject;
      26             : import com.google.gerrit.extensions.common.CommitInfo;
      27             : import com.google.gerrit.truth.ListSubject;
      28             : import com.google.gerrit.truth.NullAwareCorrespondence;
      29             : 
      30             : public class CommitInfoSubject extends Subject {
      31             : 
      32             :   public static CommitInfoSubject assertThat(CommitInfo commitInfo) {
      33           2 :     return assertAbout(commits()).that(commitInfo);
      34             :   }
      35             : 
      36             :   public static Subject.Factory<CommitInfoSubject, CommitInfo> commits() {
      37           5 :     return CommitInfoSubject::new;
      38             :   }
      39             : 
      40             :   private final CommitInfo commitInfo;
      41             : 
      42             :   private CommitInfoSubject(FailureMetadata failureMetadata, CommitInfo commitInfo) {
      43           5 :     super(failureMetadata, commitInfo);
      44           5 :     this.commitInfo = commitInfo;
      45           5 :   }
      46             : 
      47             :   public StringSubject commit() {
      48           4 :     isNotNull();
      49           4 :     return check("commit").that(commitInfo.commit);
      50             :   }
      51             : 
      52             :   public ListSubject<CommitInfoSubject, CommitInfo> parents() {
      53           3 :     isNotNull();
      54           3 :     return check("parents").about(elements()).thatCustom(commitInfo.parents, commits());
      55             :   }
      56             : 
      57             :   public GitPersonSubject committer() {
      58           2 :     isNotNull();
      59           2 :     return check("committer").about(gitPersons()).that(commitInfo.committer);
      60             :   }
      61             : 
      62             :   public GitPersonSubject author() {
      63           1 :     isNotNull();
      64           1 :     return check("author").about(gitPersons()).that(commitInfo.author);
      65             :   }
      66             : 
      67             :   public StringSubject message() {
      68           2 :     isNotNull();
      69           2 :     return check("message").that(commitInfo.message);
      70             :   }
      71             : 
      72             :   public IterableSubject webLinks() {
      73           0 :     isNotNull();
      74           0 :     return check("webLinks").that(commitInfo.webLinks);
      75             :   }
      76             : 
      77             :   public IterableSubject resolveConflictsWebLinks() {
      78           0 :     isNotNull();
      79           0 :     return check("resolveConflictsWebLinks").that(commitInfo.resolveConflictsWebLinks);
      80             :   }
      81             : 
      82             :   public static Correspondence<CommitInfo, String> hasCommit() {
      83           1 :     return NullAwareCorrespondence.transforming(commitInfo -> commitInfo.commit, "hasCommit");
      84             :   }
      85             : }

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