LCOV - code coverage report
Current view: top level - server/fixes/testing - GitEditSubject.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 31 34 91.2 %
Date: 2022-11-19 15:00:39 Functions: 9 10 90.0 %

          Line data    Source code
       1             : // Copyright (C) 2019 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.fixes.testing;
      16             : 
      17             : import static com.google.common.truth.Truth.assertAbout;
      18             : import static com.google.gerrit.truth.ListSubject.elements;
      19             : 
      20             : import com.google.common.truth.FailureMetadata;
      21             : import com.google.common.truth.Subject;
      22             : import com.google.gerrit.jgit.diff.ReplaceEdit;
      23             : import com.google.gerrit.truth.ListSubject;
      24             : import org.eclipse.jgit.diff.Edit;
      25             : 
      26             : public class GitEditSubject extends Subject {
      27             : 
      28             :   public static GitEditSubject assertThat(Edit edit) {
      29           1 :     return assertAbout(gitEdits()).that(edit);
      30             :   }
      31             : 
      32             :   public static Subject.Factory<GitEditSubject, Edit> gitEdits() {
      33           1 :     return GitEditSubject::new;
      34             :   }
      35             : 
      36             :   private final Edit edit;
      37             : 
      38             :   private GitEditSubject(FailureMetadata failureMetadata, Edit edit) {
      39           1 :     super(failureMetadata, edit);
      40           1 :     this.edit = edit;
      41           1 :   }
      42             : 
      43             :   public void hasRegions(int beginA, int endA, int beginB, int endB) {
      44           1 :     isNotNull();
      45           1 :     check("beginA").that(edit.getBeginA()).isEqualTo(beginA);
      46           1 :     check("endA").that(edit.getEndA()).isEqualTo(endA);
      47           1 :     check("beginB").that(edit.getBeginB()).isEqualTo(beginB);
      48           1 :     check("endB").that(edit.getEndB()).isEqualTo(endB);
      49           1 :   }
      50             : 
      51             :   public void hasType(Edit.Type type) {
      52           1 :     isNotNull();
      53           1 :     check("getType").that(edit.getType()).isEqualTo(type);
      54           1 :   }
      55             : 
      56             :   public void isInsert(int insertPos, int beginB, int insertedLength) {
      57           1 :     isNotNull();
      58           1 :     hasType(Edit.Type.INSERT);
      59           1 :     hasRegions(insertPos, insertPos, beginB, beginB + insertedLength);
      60           1 :   }
      61             : 
      62             :   public void isDelete(int deletePos, int deletedLength, int posB) {
      63           1 :     isNotNull();
      64           1 :     hasType(Edit.Type.DELETE);
      65           1 :     hasRegions(deletePos, deletePos + deletedLength, posB, posB);
      66           1 :   }
      67             : 
      68             :   public void isReplace(int originalPos, int originalLength, int newPos, int newLength) {
      69           1 :     isNotNull();
      70           1 :     hasType(Edit.Type.REPLACE);
      71           1 :     hasRegions(originalPos, originalPos + originalLength, newPos, newPos + newLength);
      72           1 :   }
      73             : 
      74             :   public void isEmpty() {
      75           0 :     isNotNull();
      76           0 :     hasType(Edit.Type.EMPTY);
      77           0 :   }
      78             : 
      79             :   public ListSubject<GitEditSubject, Edit> internalEdits() {
      80           1 :     isNotNull();
      81           1 :     isInstanceOf(ReplaceEdit.class);
      82           1 :     return check("internalEdits")
      83           1 :         .about(elements())
      84           1 :         .thatCustom(((ReplaceEdit) edit).getInternalEdits(), gitEdits());
      85             :   }
      86             : }

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