Coverage Report - org.truth0.subjects.SubjectUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
SubjectUtils
85%
12/14
91%
11/12
2.667
 
 1  
 /*
 2  
  * Copyright (c) 2011 David Saff
 3  
  * Copyright (c) 2011 Christian Gruber
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.truth0.subjects;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Arrays;
 21  
 import java.util.Collections;
 22  
 import java.util.List;
 23  
 
 24  
 
 25  
 /**
 26  
  * Utility methods used in Subject<T> implementors.
 27  
  *
 28  
  * @author Christian Gruber (cgruber@israfil.net)
 29  
  */
 30  0
 final class SubjectUtils {
 31  
 
 32  
   static <T> List<T> accumulate(T only) {
 33  0
     return new ArrayList<T>(Collections.singleton(only));
 34  
   }
 35  
   static <T> List<T> accumulate(T first, T second, T ... rest) {
 36  
     // rest should never be deliberately null, so assume that the caller passed null
 37  
     // in the third position but intended it to be the third element in the array of values.
 38  
     // Javac makes the opposite inference, so handle that here.
 39  22
     List<T> items = new ArrayList<T>(2 + ((rest == null) ? 1 : rest.length));
 40  22
     items.add(first);
 41  22
     items.add(second);
 42  22
     if (rest == null) {
 43  2
       items.add(null);
 44  
     } else {
 45  20
       items.addAll(Arrays.asList(rest));
 46  
     }
 47  22
     return items;
 48  
   }
 49  
 
 50  
   static <T> int countOf(T t, Iterable<T> items) {
 51  6
     int count = 0;
 52  6
     for (T item : items) {
 53  12
       if (t == null ? (item == null) : t.equals(item)) {
 54  9
         count++;
 55  
       }
 56  
     }
 57  6
     return count;
 58  
   }
 59  
 
 60  
 }