LCOV - code coverage report
Current view: top level - extensions/common/testing - RangeSubject.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 17 88.2 %
Date: 2022-11-19 15:00:39 Functions: 9 9 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2016 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             : 
      20             : import com.google.common.truth.FailureMetadata;
      21             : import com.google.common.truth.IntegerSubject;
      22             : import com.google.common.truth.Subject;
      23             : import com.google.gerrit.extensions.client.Comment;
      24             : 
      25             : public class RangeSubject extends Subject {
      26             : 
      27             :   public static RangeSubject assertThat(Comment.Range range) {
      28           1 :     return assertAbout(ranges()).that(range);
      29             :   }
      30             : 
      31             :   public static Subject.Factory<RangeSubject, Comment.Range> ranges() {
      32           4 :     return RangeSubject::new;
      33             :   }
      34             : 
      35             :   private final Comment.Range range;
      36             : 
      37             :   private RangeSubject(FailureMetadata failureMetadata, Comment.Range range) {
      38           4 :     super(failureMetadata, range);
      39           4 :     this.range = range;
      40           4 :   }
      41             : 
      42             :   public IntegerSubject startLine() {
      43           2 :     return check("startLine").that(range.startLine);
      44             :   }
      45             : 
      46             :   public IntegerSubject startCharacter() {
      47           2 :     return check("startCharacter").that(range.startCharacter);
      48             :   }
      49             : 
      50             :   public IntegerSubject endLine() {
      51           2 :     return check("endLine").that(range.endLine);
      52             :   }
      53             : 
      54             :   public IntegerSubject endCharacter() {
      55           2 :     return check("endCharacter").that(range.endCharacter);
      56             :   }
      57             : 
      58             :   public void isValid() {
      59           1 :     isNotNull();
      60           1 :     if (!range.isValid()) {
      61           0 :       failWithActual(simpleFact("expected to be valid"));
      62             :     }
      63           1 :   }
      64             : 
      65             :   public void isInvalid() {
      66           1 :     isNotNull();
      67           1 :     if (range.isValid()) {
      68           0 :       failWithActual(simpleFact("expected to be invalid"));
      69             :     }
      70           1 :   }
      71             : }

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