Created
April 27, 2011 15:37
-
-
Save dfox/944494 to your computer and use it in GitHub Desktop.
A unit test for a contrived asynchronous example class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.TimeUnit; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class AsynchronousTaskTest implements Callback { | |
private CountDownLatch latch; | |
public void completed() { | |
latch.countDown(); | |
} | |
@Test | |
public void testTask() throws InterruptedException { | |
latch = new CountDownLatch(1); | |
AsynchronousTask task = new AsynchronousTask(this); | |
task.start(); | |
latch.await(10, TimeUnit.SECONDS); | |
Assert.assertEquals(42, task.getResult()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment