1818import org .junit .Assert ;
1919import org .junit .Test ;
2020
21+ import org .ocpsoft .rewrite .context .EvaluationContext ;
22+ import org .ocpsoft .rewrite .event .Rewrite ;
2123import org .ocpsoft .rewrite .mock .MockEvaluationContext ;
2224import org .ocpsoft .rewrite .test .MockRewrite ;
2325
@@ -40,4 +42,48 @@ public void testNotTrueIsFalse()
4042 Condition condition = Not .any (new True ());
4143 Assert .assertFalse (condition .evaluate (new MockRewrite (), new MockEvaluationContext ()));
4244 }
45+
46+ @ Test
47+ public void testNotCountOdd ()
48+ {
49+ Condition assertCountOdd = new Condition ()
50+ {
51+ @ Override
52+ public boolean evaluate (Rewrite event , EvaluationContext context )
53+ {
54+ Assert .assertEquals (1 , Conditions .getNegationCount (context ));
55+ Assert .assertTrue (Conditions .isNegated (context ));
56+ return true ;
57+ }
58+ };
59+ Condition condition = Not .any (assertCountOdd );
60+ Assert .assertFalse (condition .evaluate (new MockRewrite (), new MockEvaluationContext ()));
61+ }
62+
63+ @ Test
64+ public void testNotCountEvent ()
65+ {
66+ Condition assertCountOdd = new Condition ()
67+ {
68+ @ Override
69+ public boolean evaluate (Rewrite event , EvaluationContext context )
70+ {
71+ Assert .assertEquals (3 , Conditions .getNegationCount (context ));
72+ Assert .assertTrue (Conditions .isNegated (context ));
73+ return true ;
74+ }
75+ };
76+ Condition assertCountEven = new Condition ()
77+ {
78+ @ Override
79+ public boolean evaluate (Rewrite event , EvaluationContext context )
80+ {
81+ Assert .assertEquals (4 , Conditions .getNegationCount (context ));
82+ Assert .assertFalse (Conditions .isNegated (context ));
83+ return true ;
84+ }
85+ };
86+ Condition condition = Not .any (Not .any (Not .any (And .all (assertCountOdd , Not .any (assertCountEven )))));
87+ Assert .assertTrue (condition .evaluate (new MockRewrite (), new MockEvaluationContext ()));
88+ }
4389}
0 commit comments