Skip to content
Snippets Groups Projects
Commit 0cd7d63b authored by Christian Wulf's avatar Christian Wulf
Browse files

fixes #221

parent ed99b620
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,9 @@
*/
package teetime.framework;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
......@@ -106,13 +108,19 @@ public final class Execution<T extends Configuration> {
* @since 2.0
*/
public void waitForTermination() {
int numExceptions = 0;
configurationContext.waitForConfigurationToTerminate();
for (Entry<Thread, List<Exception>> entry : configuration.getFactory().getThreadExceptionsMap().entrySet()) {
numExceptions += entry.getValue().size();
Map<Thread, List<Exception>> threadExceptionsMap = configuration.getFactory().getThreadExceptionsMap();
Iterator<Entry<Thread, List<Exception>>> iterator = threadExceptionsMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<Thread, List<Exception>> entry = iterator.next();
if (entry.getValue().isEmpty()) {
iterator.remove();
}
}
if (numExceptions != 0) {
throw new ExecutionException(configuration.getFactory().getThreadExceptionsMap());
if (!threadExceptionsMap.isEmpty()) {
throw new ExecutionException(threadExceptionsMap);
}
}
......
......@@ -15,6 +15,14 @@
*/
package teetime.framework.exceptionHandling;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static teetime.testutil.AssertHelper.assertInstanceOf;
import java.util.List;
import java.util.Map.Entry;
import org.junit.Test;
import teetime.framework.Execution;
......@@ -22,9 +30,20 @@ import teetime.framework.ExecutionException;
public class ExceptionHandlingTest {
@Test(expected = ExecutionException.class)
@Test
public void testException() {
new Execution<ExceptionPassingTestConfig>(new ExceptionPassingTestConfig()).executeBlocking();
Execution<ExceptionPassingTestConfig> execution = new Execution<ExceptionPassingTestConfig>(new ExceptionPassingTestConfig());
try {
execution.executeBlocking();
} catch (ExecutionException e) {
Entry<Thread, List<Exception>> entry = e.getThrownExceptions().entrySet().iterator().next();
List<Exception> exceptions = entry.getValue();
IllegalStateException exception = assertInstanceOf(IllegalStateException.class, exceptions.get(0));
assertThat(exception.getMessage(), is(equalTo("Correct exception")));
assertThat(exceptions.size(), is(1));
assertThat(e.getThrownExceptions().size(), is(1));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment