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 | 0 | super(failureStrategy, string); |
33 | 0 | } |
34 | |
|
35 | |
public void contains(String string) { |
36 | 0 | if (getSubject() == null) { |
37 | 0 | if (string != null) { |
38 | 0 | fail("contains", string); |
39 | |
} |
40 | 0 | } else if (!getSubject().contains(string)) { |
41 | 0 | fail("contains", string); |
42 | |
} |
43 | 0 | } |
44 | |
|
45 | |
public void startsWith(String string) { |
46 | 0 | if (getSubject() == null) { |
47 | 0 | if (string != null) { |
48 | 0 | fail("starts with", string); |
49 | |
} |
50 | 0 | } else if (!getSubject().startsWith(string)) { |
51 | 0 | fail("starts with", string); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
public void endsWith(String string) { |
56 | 0 | if (getSubject() == null) { |
57 | 0 | if (string != null) { |
58 | 0 | fail("ends with", string); |
59 | |
} |
60 | 0 | } else if (!getSubject().endsWith(string)) { |
61 | 0 | fail("ends with", string); |
62 | |
} |
63 | 0 | } |
64 | |
|
65 | 0 | public static final SubjectFactory<StringSubject, String> STRING = |
66 | 0 | new SubjectFactory<StringSubject, String>() { |
67 | |
@Override public StringSubject getSubject(FailureStrategy fs, String target) { |
68 | 0 | return new StringSubject(fs, target); |
69 | |
} |
70 | |
}; |
71 | |
|
72 | |
} |