LCOV - code coverage report
Current view: top level - prettify/common/testing - SparseFileContentSubject.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 18 18 100.0 %
Date: 2022-11-19 15:00:39 Functions: 6 6 100.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.prettify.common.testing;
      16             : 
      17             : import static com.google.common.truth.Truth.assertAbout;
      18             : 
      19             : import com.google.common.truth.FailureMetadata;
      20             : import com.google.common.truth.IntegerSubject;
      21             : import com.google.common.truth.MapSubject;
      22             : import com.google.common.truth.Subject;
      23             : import com.google.gerrit.prettify.common.SparseFileContent;
      24             : import java.util.HashMap;
      25             : import java.util.Map;
      26             : 
      27             : public class SparseFileContentSubject extends Subject {
      28             :   public static SparseFileContentSubject assertThat(SparseFileContent sparseFileContent) {
      29           1 :     return assertAbout(sparseFileContent()).that(sparseFileContent);
      30             :   }
      31             : 
      32             :   private final SparseFileContent sparseFileContent;
      33             : 
      34             :   private SparseFileContentSubject(FailureMetadata metadata, SparseFileContent actual) {
      35           1 :     super(metadata, actual);
      36           1 :     this.sparseFileContent = actual;
      37           1 :   }
      38             : 
      39             :   private static Subject.Factory<SparseFileContentSubject, SparseFileContent> sparseFileContent() {
      40           1 :     return SparseFileContentSubject::new;
      41             :   }
      42             : 
      43             :   public IntegerSubject getSize() {
      44           1 :     isNotNull();
      45           1 :     return check("size()").that(sparseFileContent.getSize());
      46             :   }
      47             : 
      48             :   public IntegerSubject getRangesCount() {
      49           1 :     isNotNull();
      50           1 :     return check("rangesCount()").that(sparseFileContent.getRangesCount());
      51             :   }
      52             : 
      53             :   public MapSubject lines() {
      54           1 :     isNotNull();
      55           1 :     Map<Integer, String> lines = new HashMap<>();
      56           1 :     SparseFileContent.Accessor accessor = sparseFileContent.createAccessor();
      57           1 :     int size = accessor.getSize();
      58           1 :     int idx = accessor.first();
      59           1 :     while (idx < size) {
      60           1 :       lines.put(idx, accessor.get(idx));
      61           1 :       idx = accessor.next(idx);
      62             :     }
      63           1 :     return check("lines()").that(lines);
      64             :   }
      65             : }

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