@@ -287,4 +287,48 @@ public void iteratee() {
287287 final List <Object > result = $ .map (stooges , $ .iteratee ("age" ));
288288 assertEquals ("[25, 21, 23]" , result .toString ());
289289 }
290+
291+ @ Test
292+ public void setTimeout () throws Exception {
293+ final Integer [] counter = new Integer [] {0 };
294+ Function <Void > incr = new Function <Void >() { public Void apply () {
295+ counter [0 ]++; return null ; } };
296+ $ .setTimeout (incr , 0 );
297+ Thread .sleep (40 );
298+ assertEquals (1 , counter [0 ].intValue ());
299+ }
300+
301+ @ Test
302+ public void clearTimeout () throws Exception {
303+ final Integer [] counter = new Integer [] {0 };
304+ Function <Void > incr = new Function <Void >() { public Void apply () {
305+ counter [0 ]++; return null ; } };
306+ java .util .concurrent .ScheduledFuture future = $ .setTimeout (incr , 10 );
307+ $ .clearTimeout (future );
308+ $ .clearTimeout (null );
309+ Thread .sleep (40 );
310+ assertEquals (0 , counter [0 ].intValue ());
311+ }
312+
313+ @ Test
314+ public void setInterval () throws Exception {
315+ final Integer [] counter = new Integer [] {0 };
316+ Function <Void > incr = new Function <Void >() { public Void apply () {
317+ counter [0 ]++; return null ; } };
318+ $ .setInterval (incr , 10 );
319+ Thread .sleep (45 );
320+ assertEquals (4 , counter [0 ].intValue ());
321+ }
322+
323+ @ Test
324+ public void clearInterval () throws Exception {
325+ final Integer [] counter = new Integer [] {0 };
326+ Function <Void > incr = new Function <Void >() { public Void apply () {
327+ counter [0 ]++; return null ; } };
328+ java .util .concurrent .ScheduledFuture future = $ .setInterval (incr , 10 );
329+ $ .clearInterval (future );
330+ $ .clearInterval (null );
331+ Thread .sleep (40 );
332+ assertEquals (0 , counter [0 ].intValue ());
333+ }
290334}
0 commit comments