From e8b5688ab118ef395aafd53f0f694a5587fa08b5 Mon Sep 17 00:00:00 2001
From: Nelson Tavares de Sousa <ntd@informatik.uni-kiel.de>
Date: Fri, 30 Jan 2015 15:59:15 +0100
Subject: [PATCH] first simple test

---
 .../java/teetime/framework/ExceptionHandling.java  | 13 +++++++++----
 .../framework/ExceptionTestConfiguration.java      |  8 ++++++++
 .../java/teetime/framework/ExceptionTestStage.java | 14 ++++++++++++++
 .../framework/exceptionHandling/TestListener.java  | 12 +++++++++---
 4 files changed, 40 insertions(+), 7 deletions(-)
 create mode 100644 src/test/java/teetime/framework/ExceptionTestConfiguration.java
 create mode 100644 src/test/java/teetime/framework/ExceptionTestStage.java

diff --git a/src/test/java/teetime/framework/ExceptionHandling.java b/src/test/java/teetime/framework/ExceptionHandling.java
index 78589966..b7398676 100644
--- a/src/test/java/teetime/framework/ExceptionHandling.java
+++ b/src/test/java/teetime/framework/ExceptionHandling.java
@@ -1,14 +1,19 @@
 package teetime.framework;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
 
+import teetime.framework.exceptionHandling.TestListener;
+
 public class ExceptionHandling {
 
 	@Test
-	public void test() {
-		fail("Not yet implemented");
+	public void exceptionPassingAndTermination() {
+		TestListener listener = new TestListener();
+		Analysis analysis = new Analysis(new ExceptionTestConfiguration(), listener);
+		analysis.init();
+		analysis.start();
+		assertEquals(TestListener.exceptionInvoked, 2);
 	}
-
 }
diff --git a/src/test/java/teetime/framework/ExceptionTestConfiguration.java b/src/test/java/teetime/framework/ExceptionTestConfiguration.java
new file mode 100644
index 00000000..5b6c4ade
--- /dev/null
+++ b/src/test/java/teetime/framework/ExceptionTestConfiguration.java
@@ -0,0 +1,8 @@
+package teetime.framework;
+
+public class ExceptionTestConfiguration extends AnalysisConfiguration {
+
+	public ExceptionTestConfiguration() {
+		this.addThreadableStage(new ExceptionTestStage());
+	}
+}
diff --git a/src/test/java/teetime/framework/ExceptionTestStage.java b/src/test/java/teetime/framework/ExceptionTestStage.java
new file mode 100644
index 00000000..c6aa4e64
--- /dev/null
+++ b/src/test/java/teetime/framework/ExceptionTestStage.java
@@ -0,0 +1,14 @@
+package teetime.framework;
+
+public class ExceptionTestStage extends AbstractProducerStage {
+
+	public int loops = 0;
+
+	@Override
+	protected void execute() {
+		if (loops % 1000 == 0) {
+			throw new IllegalStateException("1000 loops");
+		}
+		loops++;
+	}
+}
diff --git a/src/test/java/teetime/framework/exceptionHandling/TestListener.java b/src/test/java/teetime/framework/exceptionHandling/TestListener.java
index d7f598bf..34d04031 100644
--- a/src/test/java/teetime/framework/exceptionHandling/TestListener.java
+++ b/src/test/java/teetime/framework/exceptionHandling/TestListener.java
@@ -4,10 +4,16 @@ import teetime.framework.Stage;
 
 public class TestListener extends StageExceptionListener {
 
+	public static int exceptionInvoked = 0;
+
 	@Override
-	public FurtherExecution onStageException(Exception e, Stage throwingStage) {
-		// TODO Auto-generated method stub
-		return null;
+	public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
+		exceptionInvoked++;
+		if (exceptionInvoked == 2) {
+			return FurtherExecution.TERMINATE;
+		} else {
+			return FurtherExecution.CONTINUE;
+		}
 	}
 
 }
-- 
GitLab