summaryrefslogtreecommitdiffstats
path: root/testutil/src/test
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /testutil/src/test
Publish
Diffstat (limited to 'testutil/src/test')
-rw-r--r--testutil/src/test/java/com/yahoo/test/MatchersTestCase.java33
-rw-r--r--testutil/src/test/java/com/yahoo/test/OrderTesterTest.java76
-rw-r--r--testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java40
3 files changed, 149 insertions, 0 deletions
diff --git a/testutil/src/test/java/com/yahoo/test/MatchersTestCase.java b/testutil/src/test/java/com/yahoo/test/MatchersTestCase.java
new file mode 100644
index 00000000000..c560a0e0624
--- /dev/null
+++ b/testutil/src/test/java/com/yahoo/test/MatchersTestCase.java
@@ -0,0 +1,33 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.hamcrest.Matcher;
+import org.junit.Test;
+
+/**
+ * Tests for com.yahoo.test.Matchers.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class MatchersTestCase {
+
+ @Test
+ public final void testHasItemWithMethodObjectString() {
+ @SuppressWarnings("rawtypes")
+ final Matcher<Iterable> m = Matchers.hasItemWithMethod("nalle",
+ "toLowerCase");
+ assertEquals(
+ false,
+ m.matches(Arrays.asList(new Object[] { Integer.valueOf(1),
+ Character.valueOf('c'), "blbl" })));
+ assertEquals(
+ true,
+ m.matches(Arrays.asList(new Object[] { Character.valueOf('c'),
+ "NALLE" })));
+ }
+
+}
diff --git a/testutil/src/test/java/com/yahoo/test/OrderTesterTest.java b/testutil/src/test/java/com/yahoo/test/OrderTesterTest.java
new file mode 100644
index 00000000000..a9e4212ffc7
--- /dev/null
+++ b/testutil/src/test/java/com/yahoo/test/OrderTesterTest.java
@@ -0,0 +1,76 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.test;
+
+import org.junit.Test;
+
+/**
+ * @author Vegard Sjonfjell
+ */
+public class OrderTesterTest {
+ private class PartialInt implements Comparable<PartialInt> {
+ int value;
+
+ public PartialInt(int value) {
+ this.value = value;
+ }
+
+ @Override
+ public int compareTo(PartialInt other) {
+ if (Math.abs(value - other.value) < 3) {
+ return 0;
+ }
+ else if (value > other.value) {
+ return 1;
+ }
+ else if (value < other.value) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(value);
+ }
+ }
+
+ @Test
+ public void testTotalOrderTester() {
+ new TotalOrderTester<Integer>()
+ .theseObjects(3, 3)
+ .areLessThan(4)
+ .areLessThan(5)
+ .areLessThan(6)
+ .testOrdering();
+ }
+
+ @Test
+ public void testPartialOrderTester() {
+ new PartialOrderTester<PartialInt>()
+ .theseObjects(new PartialInt(3))
+ .areLessThan(new PartialInt(3), new PartialInt(3))
+ .areLessThan(new PartialInt(4))
+ .areLessThan(new PartialInt(4))
+ .areLessThan(new PartialInt(5))
+ .testOrdering();
+ }
+
+ @Test (expected = AssertionError.class)
+ public void testTotalOrderTesterFailsOnIncorrectOrdering() {
+ new TotalOrderTester<Integer>()
+ .theseObjects(3)
+ .areLessThan(2)
+ .areLessThan(5)
+ .testOrdering();
+ }
+
+ @Test (expected = AssertionError.class)
+ public void testPartialOrderTesterFailsOnIncorrectOrdering() {
+ new PartialOrderTester<PartialInt>()
+ .theseObjects(new PartialInt(6))
+ .areLessThan(new PartialInt(2))
+ .areLessThan(new PartialInt(3))
+ .testOrdering();
+ }
+}
diff --git a/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java b/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java
new file mode 100644
index 00000000000..6c9eac53fb1
--- /dev/null
+++ b/testutil/src/test/java/com/yahoo/test/PatternMatchersTestCase.java
@@ -0,0 +1,40 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.test;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+/**
+ * Check CollectionPatternMatcher, LinePatternMatcher and PatternMatcher.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class PatternMatchersTestCase {
+
+ @Test
+ public final void testCollections() {
+ CollectionPatternMatcher cm = new CollectionPatternMatcher("a.*");
+ String[] coll = new String[] {};
+ assertEquals(false, cm.matches(Arrays.asList(coll)));
+ coll = new String[] { "ba", "ab" };
+ assertEquals(true, cm.matches(Arrays.asList(coll)));
+ }
+
+ @Test
+ public final void testLines() {
+ LinePatternMatcher lp = new LinePatternMatcher("a");
+ assertEquals(true, lp.matches("a\nab"));
+ assertEquals(false, lp.matches("ab\nb"));
+ }
+
+ @Test
+ public final void testPatterns() {
+ PatternMatcher m = new PatternMatcher(".*a.*");
+ assertEquals(true, m.matches("ab"));
+ assertEquals(false, m.matches("b"));
+ }
+
+}