LCOV - code coverage report
Current view: top level - extensions/common/testing - ContentEntrySubject.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 24 27 88.9 %
Date: 2022-11-19 15:00:39 Functions: 10 11 90.9 %

          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.Fact.simpleFact;
      18             : import static com.google.common.truth.Truth.assertAbout;
      19             : import static com.google.gerrit.truth.ListSubject.elements;
      20             : 
      21             : import com.google.common.truth.FailureMetadata;
      22             : import com.google.common.truth.IntegerSubject;
      23             : import com.google.common.truth.IterableSubject;
      24             : import com.google.common.truth.StandardSubjectBuilder;
      25             : import com.google.common.truth.StringSubject;
      26             : import com.google.common.truth.Subject;
      27             : import com.google.gerrit.extensions.common.DiffInfo.ContentEntry;
      28             : import com.google.gerrit.truth.ListSubject;
      29             : 
      30             : public class ContentEntrySubject extends Subject {
      31             : 
      32             :   public static ContentEntrySubject assertThat(ContentEntry contentEntry) {
      33           0 :     return assertAbout(contentEntries()).that(contentEntry);
      34             :   }
      35             : 
      36             :   public static Subject.Factory<ContentEntrySubject, ContentEntry> contentEntries() {
      37           4 :     return ContentEntrySubject::new;
      38             :   }
      39             : 
      40             :   private final ContentEntry contentEntry;
      41             : 
      42             :   private ContentEntrySubject(FailureMetadata failureMetadata, ContentEntry contentEntry) {
      43           4 :     super(failureMetadata, contentEntry);
      44           4 :     this.contentEntry = contentEntry;
      45           4 :   }
      46             : 
      47             :   public void isDueToRebase() {
      48           2 :     isNotNull();
      49           2 :     if (contentEntry.dueToRebase == null || !contentEntry.dueToRebase) {
      50           0 :       failWithActual(simpleFact("expected entry to be marked 'dueToRebase'"));
      51             :     }
      52           2 :   }
      53             : 
      54             :   public void isNotDueToRebase() {
      55           2 :     isNotNull();
      56           2 :     if (contentEntry.dueToRebase != null && contentEntry.dueToRebase) {
      57           0 :       failWithActual(simpleFact("expected entry not to be marked 'dueToRebase'"));
      58             :     }
      59           2 :   }
      60             : 
      61             :   public ListSubject<StringSubject, String> commonLines() {
      62           4 :     isNotNull();
      63           4 :     return check("commonLines()")
      64           4 :         .about(elements())
      65           4 :         .that(contentEntry.ab, StandardSubjectBuilder::that);
      66             :   }
      67             : 
      68             :   public ListSubject<StringSubject, String> linesOfA() {
      69           4 :     isNotNull();
      70           4 :     return check("linesOfA()").about(elements()).that(contentEntry.a, StandardSubjectBuilder::that);
      71             :   }
      72             : 
      73             :   public ListSubject<StringSubject, String> linesOfB() {
      74           4 :     isNotNull();
      75           4 :     return check("linesOfB()").about(elements()).that(contentEntry.b, StandardSubjectBuilder::that);
      76             :   }
      77             : 
      78             :   public IterableSubject intralineEditsOfA() {
      79           1 :     isNotNull();
      80           1 :     return check("intralineEditsOfA()").that(contentEntry.editA);
      81             :   }
      82             : 
      83             :   public IterableSubject intralineEditsOfB() {
      84           1 :     isNotNull();
      85           1 :     return check("intralineEditsOfB()").that(contentEntry.editB);
      86             :   }
      87             : 
      88             :   public IntegerSubject numberOfSkippedLines() {
      89           2 :     isNotNull();
      90           2 :     return check("numberOfSkippedLines()").that(contentEntry.skip);
      91             :   }
      92             : }

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