package com.codecheck123.dumb_bdd;

import java.util.concurrent.Executors;

import com.codecheck123.dumb_bdd.report.ConsoleReporter;
import com.codecheck123.dumb_bdd.report.Reporter;

public class When extends AbstractBDD {

	private final Given given;
	private final String when;
	private AssertionError assErr;
	
	When(Given given, String bddExpression){
		this.given = given;
		this.when = bddExpression;
	}
	
	public void then(final String then, ExpressionRunner runner){
		try{
			evaluateExpression(then, runner);
		}catch(AssertionError e){
			assErr = e;
			throw e;
		}finally{
			Executors.newCachedThreadPool().execute(
					new Runnable() {
						public void run() {
							String userStory = given.getUserStory().getStory();
							Reporter reporter = new ConsoleReporter(userStory,given.getAll(),when,then,assErr);
							reporter.write();
						}
					}
			);
		}
	}
}
@@ -50,87 +50,98 @@
 til.
-concurrent.Executors;%0A%0Aimport com.codecheck123.dumb_bdd.report.ConsoleReporter;
+List;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0A
 %0Aimp
@@ -183,16 +183,20 @@
 t.Report
+Runn
 er;%0A%0Apub
@@ -326,50 +326,477 @@
 r;%0A%09
-%0A%09When(Given given, String bddExpression)%7B
+private static final ExecutorService es = Executors.newCachedThreadPool();%0A%0A%09/**%0A%09 * Throws NullPointerException if parameters given or bddExpression is Null %0A%09 * @param given%0A%09 * @param bddExpression%0A%09 */%0A%09When(Given given, String bddExpression)%7B%0A%09%09if(given == null)%7B%0A%09%09%09throw new NullPointerException(%22Given may not be NULL%22);%0A%09%09%7D%0A%09%09if(bddExpression == null %7C%7C bddExpression.isEmpty())%7B%0A%09%09%09throw new NullPointerException(%22BddExpression may not be NULL or Empty%22);%0A%09%09%7D
 %0A%09%09t
@@ -846,17 +846,16 @@
 ion;%0A%09%7D%0A
-%09
 %0A%09public
@@ -910,16 +910,113 @@
 unner)%7B%0A
+%09%09String story = given.getUserStory().getStory();%0A%09%09List%3CString%3E allGiven = given.getAllGiven();%0A
 %09%09try%7B%0A%09
@@ -1125,39 +1125,10 @@
 %0A%09%09%09
-Executors.newCachedThreadPool()
+es
 .exe
@@ -1141,241 +1141,61 @@
 %09%09%09%09
-%09
 new R
-unnable() %7B%0A%09%09%09%09%09%09public void run() %7B%0A%09%09%09%09%09%09%09String userStory = given.getUserStory().getStory();%0A%09%09%09%09%09%09%09Reporter reporter = new ConsoleReporter(userStory,given.getAll(),
+eportRunner(story, allGiven, 
 when,
+ 
 then,
+ 
 assErr)
-;%0A%09%09%09%09%09%09%09reporter.write();%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D
 %0A%09%09%09

clean up of then method and some javadoc