title: Testing amazon SWF workflow
body: <p>I am trying to write tests for my SWF workflow, but stuck with a problem, which I am guessing is because of the asynchronous code or Settable objects in my workflow. </p>
  
  <p>My code looks like</p>
  
  <pre><code>@Asynchronous public Promise doSomething(final Object object,Promise success) {
  
      final Settable&lt;Throwable&gt; exception = new Settable&lt;Throwable&gt;();
      final Settable&lt;Boolean&gt; result = new Settable&lt;Boolean&gt;();
  
      new TryCatch() {
  
          @Override
          protected void doTry() throws Throwable {
  
                  Promise&lt;Boolean&gt; waitFor = activitiesClient.doClientWork(object);
                  result.chain(waitFor);
                  setState(exception, null, waitFor);
          }
  
          @Override
          protected void doCatch(Throwable t) throws Throwable {
  
              result.set(false);
              setState(exception, t, Promise.Void());
          }
      };
  
      handleException(object, "Failed", exception);
      return result;  
  }
  </code></pre>
  
  <p>When I run my test, the control never enters tryCatch and goes straight to handleException(..) line. I am guessing I am missing something about the Settable maybe?</p>
  
  <p>As suggested on other forums, I tried both approaches 'WorkflowTest' as well as 'AsyncScope' but still can't get over similar problem while writing unit test for this workflow.</p>
  
  <p>Please help.</p>
  
  <p>My test code looks like </p>
  
  <pre><code>@InjectMocks
  CustomWorkflow workflow = new CustomWorkflowImpl();
  
  @Mock
  MyActivitiesClient activitiesClient;
  
  @Test
  public void testSomething() throws Throwable {
  
      AsyncScope scope = new AsyncScope() {
  
          protected void doAsync() {
  
          workflow.doSomething(processTransaction);
          }
      };
      scope.eventLoop();
  
      // assert
      verify(activitiesClient, times(1)).doClientWork(processTransaction);
  }
  </code></pre>
  
  <p>However I get an exception message 'java.lang.IllegalStateException: not ready' on handleException line. </p>
  
  <p>Please note I am using @InjectMocks to instantiate workflow object and I am guessing I don't need aspectweaver.jar in the classpath for this? Hope thats correct. </p>