1 | |
package org.truth0; |
2 | |
|
3 | |
import org.truth0.subjects.Subject; |
4 | |
import org.truth0.subjects.SubjectFactory; |
5 | |
|
6 | |
import com.google.common.annotations.GwtCompatible; |
7 | |
import com.google.common.annotations.GwtIncompatible; |
8 | |
|
9 | |
@GwtCompatible |
10 | |
public class AbstractVerb { |
11 | |
|
12 | |
private final FailureStrategy failureStrategy; |
13 | |
|
14 | 48 | public AbstractVerb(FailureStrategy failureStrategy) { |
15 | 48 | this.failureStrategy = failureStrategy; |
16 | 48 | } |
17 | |
|
18 | |
protected FailureStrategy getFailureStrategy() { |
19 | 323 | return failureStrategy; |
20 | |
} |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public void fail() { |
26 | 1 | failureStrategy.fail(""); |
27 | 1 | } |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public void fail(String message) { |
33 | 2 | failureStrategy.fail(message); |
34 | 2 | } |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public <S extends Subject<S,T>, T, SF extends SubjectFactory<S, T>> |
45 | |
DelegatedVerb<S, T> about(SF factory) { |
46 | 3 | return new DelegatedVerb<S, T>(getFailureStrategy(), factory); |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public static class DelegatedVerb<S extends Subject<S,T>, T> |
53 | |
extends AbstractVerb { |
54 | |
|
55 | |
private final SubjectFactory<S, T> factory; |
56 | |
|
57 | |
public DelegatedVerb(FailureStrategy fs, SubjectFactory<S, T> factory) { |
58 | 3 | super(fs); |
59 | 3 | this.factory = factory; |
60 | 3 | } |
61 | |
|
62 | |
public S that(T target) { |
63 | 3 | return factory.getSubject(getFailureStrategy(), target); |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
@GwtIncompatible("org.truth0.IteratingVerb") |
68 | |
public <T> IteratingVerb<T> in(Iterable<T> data) { |
69 | 4 | return new IteratingVerb<T>(data, getFailureStrategy()); |
70 | |
} |
71 | |
|
72 | |
} |
73 | |
|