summaryrefslogtreecommitdiff
path: root/same/src/test/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-27 15:42:42 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-27 15:42:42 +0100
commit500f94ce6780e96e503d6e5d9d46b5d537813717 (patch)
tree5d71d53c4356c40d5563cddcb5be48fd38e7ee6b /same/src/test/java/com
parenta8560de9c330285db0d7cf31398daad1090038b4 (diff)
Add DelayedOperation<T> class.
A DelayedOperation represents an asynchronious operation.
Diffstat (limited to 'same/src/test/java/com')
-rw-r--r--same/src/test/java/com/orbekk/util/DelayedOperationTest.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/same/src/test/java/com/orbekk/util/DelayedOperationTest.java b/same/src/test/java/com/orbekk/util/DelayedOperationTest.java
new file mode 100644
index 0000000..b15830f
--- /dev/null
+++ b/same/src/test/java/com/orbekk/util/DelayedOperationTest.java
@@ -0,0 +1,35 @@
+package com.orbekk.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DelayedOperationTest {
+ @Test public void initialOperationStatus() {
+ DelayedOperation<String> operation = new DelayedOperation<String>("NotFinished");
+ assertFalse(operation.isDone());
+ }
+
+ @Test public void completedOperationReturns() {
+ DelayedOperation<String> operation = new DelayedOperation<String>("Test");
+ operation.complete(DelayedOperation.Status.createOk());
+ assertTrue(operation.isDone());
+ assertEquals(DelayedOperation.Status.createOk(), operation.getStatus());
+ }
+
+ @Test public void concurrentTest() throws Exception {
+ final DelayedOperation<String> operation =
+ new DelayedOperation<String>("ConcurrentTest");
+
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ operation.waitFor();
+ }
+ });
+ t.start();
+ operation.complete(DelayedOperation.Status.createError("Fail."));
+ t.join();
+ assertTrue(operation.isDone());
+ }
+}