14
14
import static com .jnape .palatable .lambda .io .IO .io ;
15
15
import static org .hamcrest .Matchers .equalTo ;
16
16
17
- public class StateTMatcher <S , M extends MonadRec <?, M >, A , MA extends MonadRec < A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec < Tuple2 < A , S >, M > > extends TypeSafeMatcher <StateT <S , M , A >> {
17
+ public class StateTMatcher <S , M extends MonadRec <?, M >, A > extends TypeSafeMatcher <StateT <S , M , A >> {
18
18
private final S initialState ;
19
19
20
- private final Either <Matcher <? super MTS >, These <Matcher <? super MA > , Matcher <? super MS >>> matcher ;
20
+ private final Either <Matcher <? super MonadRec < Tuple2 < A , S >, M >>, These <Matcher <? super MonadRec < A , M >> , Matcher <? super MonadRec < S , M > >>> matcher ;
21
21
22
- private StateTMatcher (S initialState , These <Matcher <? super MA > , Matcher <? super MS >> matchers ) {
22
+ private StateTMatcher (S initialState , These <Matcher <? super MonadRec < A , M >> , Matcher <? super MonadRec < S , M > >> matchers ) {
23
23
this .initialState = initialState ;
24
24
this .matcher = right (matchers );
25
25
}
26
26
27
- private StateTMatcher (S initialState , Matcher <? super MTS > matcher ) {
27
+ private StateTMatcher (S initialState , Matcher <? super MonadRec < Tuple2 < A , S >, M > > matcher ) {
28
28
this .initialState = initialState ;
29
29
this .matcher = left (matcher );
30
30
}
@@ -44,9 +44,9 @@ public void describeTo(Description description) {
44
44
theseMatchers -> theseMatchers .match (a -> io (() -> a .describeTo (description .appendText ("Value matching " ))),
45
45
b -> io (() -> b .describeTo (description .appendText ("State matching " ))),
46
46
ab -> io (() -> {
47
- description .appendText ("Value matching: " );
47
+ description .appendText ("Value run matching: " );
48
48
ab ._1 ().describeTo (description );
49
- description .appendText (" and state matching: " );
49
+ description .appendText (", then state run matching: " );
50
50
ab ._2 ().describeTo (description );
51
51
})))
52
52
.unsafePerformIO ();
@@ -69,46 +69,60 @@ protected void describeMismatchSafely(StateT<S, M, A> item, Description mismatch
69
69
b .describeMismatch (ran .fmap (Tuple2 ::_2 ), mismatchDescription );
70
70
}),
71
71
ab -> io (() -> {
72
- mismatchDescription .appendText ("value matching: " );
72
+ mismatchDescription .appendText ("value run matching: " );
73
73
ab ._1 ().describeMismatch (ran .fmap (Tuple2 ::_1 ), mismatchDescription );
74
- mismatchDescription .appendText (" and state matching: " );
74
+ mismatchDescription .appendText (", then state run matching: " );
75
75
ab ._2 ().describeMismatch (ran .fmap (Tuple2 ::_2 ), mismatchDescription );
76
76
})))
77
77
.unsafePerformIO ();
78
78
}
79
79
80
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec < Tuple2 <A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenRunWith (S initialState , Matcher <? super MTS > bothMatcher ) {
81
- return new StateTMatcher <>(initialState , bothMatcher );
80
+ public static <S , M extends MonadRec <?, M >, A , MAS extends MonadRec <Tuple2 <A , S >, M >> StateTMatcher <S , M , A > whenRunWith (S initialState , Matcher <? super MAS > bothMatcher ) {
81
+ return new StateTMatcher <S , M , A >(initialState , extendMatcher ( bothMatcher ) );
82
82
}
83
83
84
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec < A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec <Tuple2 <A , S >, M >> StateTMatcher < S , M , A , MA , MS , MTS > whenRun ( S initialState , MTS both ) {
84
+ public static <S , M extends MonadRec <?, M >, A > StateTMatcher < S , M , A > whenRun ( S initialState , MonadRec <Tuple2 <A , S >, M > both ) {
85
85
return whenRunWith (initialState , equalTo (both ));
86
86
}
87
87
88
- // Note: This constructor will run both matchers, which can run effects twice
89
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec <S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenRunWith (S initialState , Matcher <? super MA > valueMatcher , Matcher <? super MS > stateMatcher ) {
90
- return new StateTMatcher <>(initialState , These .both (valueMatcher , stateMatcher ));
88
+ // Note: This constructor will run both matchers, which will run effects twice
89
+ public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec <S , M >> StateTMatcher <S , M , A > whenRunWithBoth (S initialState , Matcher <? super MA > valueMatcher , Matcher <? super MS > stateMatcher ) {
90
+ return new StateTMatcher <S , M , A >(initialState , These .both (extendMatcher ( valueMatcher ), extendMatcher ( stateMatcher ) ));
91
91
}
92
92
93
- // Note: This constructor will run both matchers, which can run effects twice
93
+ // Note: This constructor will run both matchers, which will run effects twice
94
94
@ SuppressWarnings ("unused" )
95
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec <S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenRun (S initialState , MA value , MS state ) {
96
- return whenRunWith (initialState , equalTo (value ), equalTo (state ));
95
+ public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec <S , M >> StateTMatcher <S , M , A > whenRunBoth (S initialState , MonadRec < A , M > value , MonadRec < S , M > state ) {
96
+ return whenRunWithBoth (initialState , equalTo (value ), equalTo (state ));
97
97
}
98
98
99
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec < A , M >, MS extends MonadRec <S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenExecutedWith (S initialState , Matcher <? super MS > stateMatcher ) {
100
- return new StateTMatcher <>(initialState , These .b (stateMatcher ));
99
+ public static <S , M extends MonadRec <?, M >, A , MS extends MonadRec <S , M >> StateTMatcher <S , M , A > whenExecutedWith (S initialState , Matcher <? super MS > stateMatcher ) {
100
+ return new StateTMatcher <S , M , A >(initialState , These .b (extendMatcher ( stateMatcher ) ));
101
101
}
102
102
103
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec < A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenExecuted (S initialState , MS state ) {
103
+ public static <S , M extends MonadRec <?, M >, A > StateTMatcher <S , M , A > whenExecuted (S initialState , MonadRec < S , M > state ) {
104
104
return whenExecutedWith (initialState , equalTo (state ));
105
105
}
106
106
107
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenEvaluatedWith (S initialState , Matcher <? super MA > valueMatcher ) {
108
- return new StateTMatcher <>(initialState , These .a (valueMatcher ));
107
+ public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec <A , M >> StateTMatcher <S , M , A > whenEvaluatedWith (S initialState , Matcher <? super MA > valueMatcher ) {
108
+ return new StateTMatcher <S , M , A >(initialState , These .a (extendMatcher ( valueMatcher ) ));
109
109
}
110
110
111
- public static <S , M extends MonadRec <?, M >, A , MA extends MonadRec < A , M >, MS extends MonadRec < S , M >, MTS extends MonadRec < Tuple2 < A , S >, M >> StateTMatcher <S , M , A , MA , MS , MTS > whenEvaluated (S initialState , MA value ) {
111
+ public static <S , M extends MonadRec <?, M >, A > StateTMatcher <S , M , A > whenEvaluated (S initialState , MonadRec < A , M > value ) {
112
112
return whenEvaluatedWith (initialState , equalTo (value ));
113
113
}
114
+
115
+ private static <X , M extends MonadRec <?, M >, MX extends MonadRec <X , M >> Matcher <MonadRec <X , M >> extendMatcher (Matcher <? super MX > matcher ) {
116
+ return new TypeSafeMatcher <MonadRec <X , M >>() {
117
+ @ Override
118
+ protected boolean matchesSafely (MonadRec <X , M > item ) {
119
+ return matcher .matches (item );
120
+ }
121
+
122
+ @ Override
123
+ public void describeTo (Description description ) {
124
+ matcher .describeTo (description );
125
+ }
126
+ };
127
+ }
114
128
}
0 commit comments