From ad82595aebedf065788f9ed351d8183e122479b6 Mon Sep 17 00:00:00 2001
From: Nils Christian Ehmke <nils@rhocas.de>
Date: Fri, 27 Feb 2015 12:01:06 +0100
Subject: [PATCH] Added further JUnit tests

---
 .../teetime/stage/InstanceOfFilterTest.java   | 95 +++++++++++++++++++
 .../teetime/stage/string/ToLowerCaseTest.java | 58 +++++++++++
 2 files changed, 153 insertions(+)
 create mode 100644 src/test/java/teetime/stage/InstanceOfFilterTest.java
 create mode 100644 src/test/java/teetime/stage/string/ToLowerCaseTest.java

diff --git a/src/test/java/teetime/stage/InstanceOfFilterTest.java b/src/test/java/teetime/stage/InstanceOfFilterTest.java
new file mode 100644
index 00000000..efbe1f4a
--- /dev/null
+++ b/src/test/java/teetime/stage/InstanceOfFilterTest.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package teetime.stage;
+
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+import static org.hamcrest.collection.IsEmptyCollection.empty;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static teetime.framework.test.StageTester.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Nils Christian Ehmke
+ */
+public class InstanceOfFilterTest {
+
+	private InstanceOfFilter<Object, Clazz> filter;
+
+	@Before
+	public void initializeFilter() {
+		filter = new InstanceOfFilter<Object, Clazz>(Clazz.class);
+	}
+
+	@Test
+	public void filterShouldForwardCorrectTypes() {
+		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
+		final Object clazz = new Clazz();
+
+		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, contains(clazz));
+	}
+
+	@Test
+	public void filterShouldForwardSubTypes() {
+		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
+		final Object clazz = new SubClazz();
+
+		test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, contains(clazz));
+	}
+
+	@Test
+	public void filterShouldDropInvalidTypes() {
+		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
+		final Object object = new Object();
+
+		test(filter).and().send(object).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, is(empty()));
+	}
+
+	@Test
+	public void filterShouldWorkWithMultipleInput() {
+		final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
+		final List<Object> input = new ArrayList<Object>();
+
+		input.add(new Object());
+		input.add(new Clazz());
+		input.add(new Object());
+		input.add(new SubClazz());
+		input.add(new Object());
+
+		test(filter).and().send(input).to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, hasSize(2));
+	}
+
+	private static class Clazz {
+	}
+
+	private static class SubClazz extends Clazz {
+	}
+
+}
diff --git a/src/test/java/teetime/stage/string/ToLowerCaseTest.java b/src/test/java/teetime/stage/string/ToLowerCaseTest.java
new file mode 100644
index 00000000..c1bde929
--- /dev/null
+++ b/src/test/java/teetime/stage/string/ToLowerCaseTest.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package teetime.stage.string;
+
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.assertThat;
+import static teetime.framework.test.StageTester.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Nils Christian Ehmke
+ */
+public class ToLowerCaseTest {
+
+	private ToLowerCase filter;
+
+	@Before
+	public void initializeFilter() {
+		filter = new ToLowerCase();
+	}
+
+	@Test
+	public void toLowerCaseShouldWork() {
+		List<String> results = new ArrayList<String>();
+
+		test(filter).and().send("Hello World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, contains("hello world"));
+	}
+
+	@Test
+	public void toLowerCaseShouldRemoveNonWordCharacters() {
+		List<String> results = new ArrayList<String>();
+
+		test(filter).and().send("Hello 1 2 3 World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
+
+		assertThat(results, contains("hello    world"));
+	}
+
+}
-- 
GitLab