aboutsummaryrefslogtreecommitdiff
path: root/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-01-24 13:35:17 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-01-24 13:35:18 +0000
commit5d9cc8c989815b4180a6a0bd220dbfd35e126c84 (patch)
treeaa4a6a53609f47d386dfa114be0abfc01e0e5dff /hamcrest-core/src/main/java/org/hamcrest/core/Is.java
parentf1015b50e715aefc3070d83d95340cbc29811329 (diff)
parent74299c53a59140905e0259cb0a1130cb719733d8 (diff)
downloadhamcrest-5d9cc8c989815b4180a6a0bd220dbfd35e126c84.tar.gz
Merge "Match upstream file structure"
Diffstat (limited to 'hamcrest-core/src/main/java/org/hamcrest/core/Is.java')
-rw-r--r--hamcrest-core/src/main/java/org/hamcrest/core/Is.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/hamcrest-core/src/main/java/org/hamcrest/core/Is.java b/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
new file mode 100644
index 0000000..f9152e9
--- /dev/null
+++ b/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
@@ -0,0 +1,68 @@
+package org.hamcrest.core;
+
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsEqual.equalTo;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+
+/**
+ * Decorates another Matcher, retaining the behavior but allowing tests
+ * to be slightly more expressive.
+ *
+ * eg. assertThat(cheese, equalTo(smelly))
+ * vs assertThat(cheese, is(equalTo(smelly)))
+ */
+public class Is<T> extends BaseMatcher<T> {
+
+ private final Matcher<T> matcher;
+
+ public Is(Matcher<T> matcher) {
+ this.matcher = matcher;
+ }
+
+ public boolean matches(Object arg) {
+ return matcher.matches(arg);
+ }
+
+ public void describeTo(Description description) {
+ description.appendText("is ").appendDescriptionOf(matcher);
+ }
+
+ /**
+ * Decorates another Matcher, retaining the behavior but allowing tests
+ * to be slightly more expressive.
+ *
+ * eg. assertThat(cheese, equalTo(smelly))
+ * vs assertThat(cheese, is(equalTo(smelly)))
+ */
+ @Factory
+ public static <T> Matcher<T> is(Matcher<T> matcher) {
+ return new Is<T>(matcher);
+ }
+
+ /**
+ * This is a shortcut to the frequently used is(equalTo(x)).
+ *
+ * eg. assertThat(cheese, is(equalTo(smelly)))
+ * vs assertThat(cheese, is(smelly))
+ */
+ @Factory
+ public static <T> Matcher<T> is(T value) {
+ return is(equalTo(value));
+ }
+
+ /**
+ * This is a shortcut to the frequently used is(instanceOf(SomeClass.class)).
+ *
+ * eg. assertThat(cheese, is(instanceOf(Cheddar.class)))
+ * vs assertThat(cheese, is(Cheddar.class))
+ */
+ @Factory
+ public static Matcher<Object> is(Class<?> type) {
+ return is(instanceOf(type));
+ }
+
+}
+