aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/unit/net
diff options
context:
space:
mode:
authorAdam Domurad <[email protected]>2013-04-25 10:28:08 -0400
committerAdam Domurad <[email protected]>2013-04-25 10:28:08 -0400
commit03d8ad8d96243ec9499f0b974750b6ea64f7b41f (patch)
tree034c115089287d77ccdd57d9e90183b1f71558ba /tests/netx/unit/net
parentea6aec77a785846cb557916b688978714bf78426 (diff)
Unit tests for AsyncCall test extension
Diffstat (limited to 'tests/netx/unit/net')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/AsyncCallTest.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/AsyncCallTest.java b/tests/netx/unit/net/sourceforge/jnlp/AsyncCallTest.java
new file mode 100644
index 0000000..eb6903b
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/AsyncCallTest.java
@@ -0,0 +1,93 @@
+package net.sourceforge.jnlp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Callable;
+
+import org.junit.Test;
+
+public class AsyncCallTest {
+
+ @Test
+ public void timeOutTest() {
+ final boolean[] wasInterrupted = { false };
+
+ AsyncCall<Void> call = AsyncCall.startWithTimeOut(new Callable<Void>() {
+ @Override
+ public synchronized Void call() {
+ try {
+ wait();
+ } catch (InterruptedException ie) {
+ // Received on time-out
+ wasInterrupted[0] = true;
+ }
+ return null;
+ }
+ }, 100 /* 100 millisecond time-out */);
+
+ boolean completedNormally = false;
+
+ try {
+ call.join();
+ completedNormally = true;
+ } catch (Exception e) {
+ ServerAccess.logErrorReprint(e.toString());
+ assertTrue(e instanceof AsyncCall.TimeOutException);
+ }
+
+ assertFalse(completedNormally);
+ assertTrue(wasInterrupted[0]);
+ }
+
+ @Test
+ public void normalReturnTest() {
+ AsyncCall<Integer> call = AsyncCall.startWithTimeOut(new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ return 1;
+ }
+ });
+
+ Integer result = null;
+ boolean completedNormally = false;
+
+ try {
+ result = call.join();
+ completedNormally = true;
+ } catch (Exception e) {
+ ServerAccess.logErrorReprint(e.toString());
+ }
+
+ assertTrue(completedNormally);
+ assertEquals(Integer.valueOf(1), result);
+ }
+
+ @Test
+ public void thrownExceptionTest() {
+
+ @SuppressWarnings("serial")
+ class TestException extends RuntimeException {
+ }
+
+ AsyncCall<Void> call = AsyncCall.startWithTimeOut(new Callable<Void>() {
+ @Override
+ public Void call() {
+ throw new TestException();
+ }
+ });
+
+ boolean completedNormally = false;
+
+ try {
+ call.join();
+ completedNormally = true;
+ } catch (Exception e) {
+ ServerAccess.logErrorReprint(e.toString());
+ assertTrue(e instanceof TestException);
+ }
+
+ assertFalse(completedNormally);
+ }
+} \ No newline at end of file