Coverage Report - org.truth0.subjects.StringSubject
 
Classes in this File Line Coverage Branch Coverage Complexity
StringSubject
100%
21/21
100%
18/18
2.8
StringSubject$1
100%
2/2
N/A
2.8
 
 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 org.truth0.FailureStrategy;
 20  
 
 21  
 import com.google.common.annotations.GwtCompatible;
 22  
 
 23  
 /**
 24  
  * Propositions for String subjects
 25  
  *
 26  
  * @author David Saff
 27  
  * @author Christian Gruber (cgruber@israfil.net)
 28  
  */
 29  
 @GwtCompatible
 30  
 public class StringSubject extends Subject<StringSubject, String> {
 31  
   public StringSubject(FailureStrategy failureStrategy, String string) {
 32  153
     super(failureStrategy, string);
 33  153
   }
 34  
 
 35  
   public void contains(String string) {
 36  111
     if (getSubject() == null) {
 37  2
       if (string != null) {
 38  1
         fail("contains", string);
 39  
       }
 40  109
     } else if (!getSubject().contains(string)) {
 41  5
       fail("contains", string);
 42  
     }
 43  109
   }
 44  
 
 45  
   public void startsWith(String string) {
 46  6
     if (getSubject() == null) {
 47  2
       if (string != null) {
 48  1
         fail("starts with", string);
 49  
       }
 50  4
     } else if (!getSubject().startsWith(string)) {
 51  1
       fail("starts with", string);
 52  
     }
 53  4
   }
 54  
 
 55  
   public void endsWith(String string) {
 56  6
     if (getSubject() == null) {
 57  2
       if (string != null) {
 58  1
         fail("ends with", string);
 59  
       }
 60  4
     } else if (!getSubject().endsWith(string)) {
 61  1
       fail("ends with", string);
 62  
     }
 63  4
   }
 64  
 
 65  1
   public static final SubjectFactory<StringSubject, String> STRING =
 66  3
       new SubjectFactory<StringSubject, String>() {
 67  
         @Override public StringSubject getSubject(FailureStrategy fs, String target) {
 68  2
           return new StringSubject(fs, target);
 69  
         }
 70  
       };
 71  
 
 72  
 }