aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKetan Padegaonkar2011-01-24 22:30:56 -0500
committerKetan Padegaonkar2011-01-24 22:31:11 -0500
commit3ee6280f716a2a59f1d56e4cb42ec0908ce6a0dc (patch)
tree8df29452882e0d71935a53563c187b5de61c7fe1
parent8650b1bb1ef168be9b0bc846dadaca20ae872376 (diff)
downloadorg.eclipse.swtbot-3ee6280f716a2a59f1d56e4cb42ec0908ce6a0dc.tar.gz
org.eclipse.swtbot-3ee6280f716a2a59f1d56e4cb42ec0908ce6a0dc.tar.xz
org.eclipse.swtbot-3ee6280f716a2a59f1d56e4cb42ec0908ce6a0dc.zip
Improve test coverage by adding some more tests for matchers.
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AllOfTest.java41
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AnyOfTest.java42
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/MyMatcher.java34
3 files changed, 117 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AllOfTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AllOfTest.java
new file mode 100644
index 00000000..aee90ab4
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AllOfTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Ketan Padegaonkar and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.matchers;
+
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
+ *
+ */
+public class AllOfTest {
+ @Test
+ public void testShouldAnswerTrueIfAllMatcherMatches() throws Exception {
+ MyMatcher matcher1 = new MyMatcher(true);
+ MyMatcher matcher2 = new MyMatcher(true);
+ assertTrue(allOf(matcher1, matcher2).matches(null));
+ assertTrue(matcher1.matched);
+ assertTrue(matcher2.matched);
+ }
+
+ @Test
+ public void testShouldAnswerFalseIfAnyMatchersDoesNotMatch() throws Exception {
+ MyMatcher matcher1 = new MyMatcher(true);
+ MyMatcher matcher2 = new MyMatcher(false);
+ assertFalse(allOf(matcher1, matcher2).matches(null));
+ assertTrue(matcher1.matched);
+ assertTrue(matcher2.matched);
+ }
+}
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AnyOfTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AnyOfTest.java
new file mode 100644
index 00000000..7e21b692
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/AnyOfTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Ketan Padegaonkar and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.matchers;
+
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.anyOf;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
+ */
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class AnyOfTest {
+
+ @Test
+ public void testShouldAnswerTrueIfAnyMatcherMatches() throws Exception {
+ MyMatcher matcher1 = new MyMatcher(true);
+ MyMatcher matcher2 = new MyMatcher(false);
+ assertTrue(anyOf(matcher1, matcher2).matches(null));
+ assertTrue(matcher1.matched);
+ assertFalse(matcher2.matched);
+ }
+
+ @Test
+ public void testShouldAnswerFalseIfNoMatchersMatche() throws Exception {
+ MyMatcher matcher1 = new MyMatcher(false);
+ MyMatcher matcher2 = new MyMatcher(false);
+ assertFalse(anyOf(matcher1, matcher2).matches(null));
+ assertTrue(matcher1.matched);
+ assertTrue(matcher2.matched);
+ }
+}
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/MyMatcher.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/MyMatcher.java
new file mode 100644
index 00000000..e750d143
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/matchers/MyMatcher.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Ketan Padegaonkar and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.matchers;
+
+import org.hamcrest.Description;
+
+final class MyMatcher<T> extends AbstractMatcher<T> {
+
+ private final boolean toAnswer;
+ boolean matched;
+
+ public MyMatcher(boolean toAnswer) {
+ this.toAnswer = toAnswer;
+ }
+
+ public void describeTo(Description description) {
+
+ }
+
+ @Override
+ protected boolean doMatch(Object item) {
+ this.matched = true;
+ return toAnswer;
+ }
+
+}