| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 package com.google.dart.fling; | |
| 6 | |
| 7 import com.google.dart.fling.MessageLoop; | |
| 8 | |
| 9 import junit.framework.Assert; | |
| 10 | |
| 11 import org.junit.Test; | |
| 12 | |
| 13 import java.io.IOException; | |
| 14 | |
| 15 | |
| 16 public class MessageLoopTest { | |
| 17 private static void stopIn(final MessageLoop loop, int millis) { | |
| 18 loop.postTask(new Runnable() { | |
| 19 @Override public void run() { | |
| 20 loop.stop(); | |
| 21 } | |
| 22 }, millis); | |
| 23 } | |
| 24 | |
| 25 private static class TestTask implements Runnable { | |
| 26 private int runCount; | |
| 27 | |
| 28 @Override public void run() { | |
| 29 runCount++; | |
| 30 } | |
| 31 | |
| 32 public boolean didRun() { | |
| 33 return runCount > 0; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 @Test public void willItRunImmediateTasks() throws IOException { | |
| 38 final TestTask a = new TestTask(); | |
| 39 final TestTask b = new TestTask(); | |
| 40 | |
| 41 final MessageLoop loop = MessageLoop.create(); | |
| 42 loop.postTask(a); | |
| 43 loop.postTask(b); | |
| 44 stopIn(loop, 0); | |
| 45 loop.run(); | |
| 46 Assert.assertTrue(a.didRun()); | |
| 47 Assert.assertTrue(b.didRun()); | |
| 48 } | |
| 49 } | |
| OLD | NEW |