From 500f94ce6780e96e503d6e5d9d46b5d537813717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Mon, 27 Feb 2012 15:42:42 +0100 Subject: Add DelayedOperation class. A DelayedOperation represents an asynchronious operation. --- .../java/com/orbekk/util/DelayedOperationTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 same/src/test/java/com/orbekk/util/DelayedOperationTest.java (limited to 'same/src/test/java/com/orbekk/util/DelayedOperationTest.java') 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 operation = new DelayedOperation("NotFinished"); + assertFalse(operation.isDone()); + } + + @Test public void completedOperationReturns() { + DelayedOperation operation = new DelayedOperation("Test"); + operation.complete(DelayedOperation.Status.createOk()); + assertTrue(operation.isDone()); + assertEquals(DelayedOperation.Status.createOk(), operation.getStatus()); + } + + @Test public void concurrentTest() throws Exception { + final DelayedOperation operation = + new DelayedOperation("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()); + } +} -- cgit v1.2.3