| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.truth0.subjects; |
| 18 | |
|
| 19 | |
import org.truth0.FailureStrategy; |
| 20 | |
|
| 21 | |
import com.google.common.annotations.GwtCompatible; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
@GwtCompatible |
| 30 | |
public class StringSubject extends Subject<StringSubject, String> { |
| 31 | |
public StringSubject(FailureStrategy failureStrategy, String string) { |
| 32 | 185 | super(failureStrategy, string); |
| 33 | 185 | } |
| 34 | |
|
| 35 | |
public void contains(String string) { |
| 36 | 143 | if (getSubject() == null) { |
| 37 | 2 | if (string != null) { |
| 38 | 1 | fail("contains", string); |
| 39 | |
} |
| 40 | 141 | } else if (!getSubject().contains(string)) { |
| 41 | 5 | fail("contains", string); |
| 42 | |
} |
| 43 | 141 | } |
| 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 | |
} |