- Revision
- 678
- Author
- sirenian
- Date
- 2007-01-25 07:37:07 -0600 (Thu, 25 Jan 2007)
Log Message
[EK] Fixed example behaviours.
Modified Paths
- trunk/core/src/java/org/jbehave/core/mock/UsingMatchers.java
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/util/ThreadedQueueBehaviour.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java
Added Paths
Diff
Modified: trunk/core/src/java/org/jbehave/core/mock/UsingMatchers.java (677 => 678)
--- trunk/core/src/java/org/jbehave/core/mock/UsingMatchers.java 2007-01-24 18:31:21 UTC (rev 677) +++ trunk/core/src/java/org/jbehave/core/mock/UsingMatchers.java 2007-01-25 13:37:07 UTC (rev 678) @@ -121,6 +121,10 @@ }; } + public CustomMatcher is(Object expectedArg) { + return sameInstanceAs(expectedArg); + } + public CustomMatcher sameInstanceAs(final Object expectedArg) { return new CustomMatcher("same instance as <" + expectedArg + ">") { public boolean matches(Object arg) {
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/util/ThreadedQueueBehaviour.java (677 => 678)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/util/ThreadedQueueBehaviour.java 2007-01-24 18:31:21 UTC (rev 677) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/util/ThreadedQueueBehaviour.java 2007-01-25 13:37:07 UTC (rev 678) @@ -1,7 +1,11 @@ package com.sirenian.hellbound.util; -import org.jbehave.core.Block; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + import org.jbehave.core.minimock.UsingMiniMock; +import org.jbehave.core.mock.Mock; +import org.jbehave.core.threaded.QueuedObjectHolder; public class ThreadedQueueBehaviour extends UsingMiniMock { @@ -13,22 +17,28 @@ // Can't think how to test this. } - public void shouldRethrowCaughtExceptionsInCallingThreadThenTerminate() throws Exception { - final ThreadedQueue queue = new ThreadedQueue("test queue") { + public void shouldPassCaughtExceptionsToHandler() throws Exception { + final QueuedObjectHolder exceptionHolder = new QueuedObjectHolder(); + final RuntimeException exception = new RuntimeException("An exception occurred"); + + Mock handler = mock(ErrorHandler.class); + handler.expects("handle").will(new InvocationHandler() { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + exceptionHolder.set(args[0]); + return null; + } + }); + + ThreadedQueue queue = new ThreadedQueue("test queue", (ErrorHandler) handler) { protected void perform(Runnable action) { action.run(); } }; - Exception exception = runAndCatch(Throwable.class, new Block() { - public void run() throws Exception { - queue.queue(new Runnable(){ public void run() { - - throw new RuntimeException("An exception occurred"); - }}); - } - }); - - ensureThat(exception, isNotNull()); + queue.queue(new Runnable(){ public void run() { + throw exception; + }}); + + ensureThat(exceptionHolder.get(), is(exception)); } }
Added: trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ErrorHandler.java (0 => 678)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ErrorHandler.java (rev 0) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ErrorHandler.java 2007-01-25 13:37:07 UTC (rev 678) @@ -0,0 +1,11 @@ +package com.sirenian.hellbound.util; + +public interface ErrorHandler { + + ErrorHandler NULL = new ErrorHandler() { + public void handle(Throwable t) {} + }; + + void handle(Throwable t); + +}
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java (677 => 678)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java 2007-01-24 18:31:21 UTC (rev 677) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java 2007-01-25 13:37:07 UTC (rev 678) @@ -22,6 +22,10 @@ private final String queueName; protected ThreadedQueue(String queueName) { + this(queueName, ErrorHandler.NULL); + } + + protected ThreadedQueue(String queueName, final ErrorHandler handler) { this.queueName = queueName; Runnable runnable = new Runnable() { public void run() { @@ -32,7 +36,7 @@ runAllInList(afterEmptyEventList); waitForNextRequest(); } catch (Throwable t) { - throwable = t; + handler.handle(t); } } @@ -41,9 +45,6 @@ }; Logger.debug(this, "Starting thread for " + queueName); new Thread(runnable, queueName).start(); - if (throwable != null) { - throw new RuntimeException(throwable); - } } public void stop() { @@ -74,6 +75,9 @@ protected abstract void perform(Runnable action); protected void queue(Runnable runnable) { + if (throwable != null) { + throw new RuntimeException("Throwable received in queue: " + throwable); + } synchronized(eventList) { eventList.add(runnable); eventList.notifyAll();
To unsubscribe from this list please visit:
