aboutsummaryrefslogtreecommitdiff
path: root/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2017-01-20 15:04:28 +0000
committerPaul Duffin <paulduffin@google.com>2017-02-09 15:12:38 +0000
commitc1dbb44e71e47410ad5685aba3ef3fccb095a2b4 (patch)
tree08f6e90ece87cf59e3c7c645a7519eaaf63c716e /hamcrest-core/src/main/java/org/hamcrest/core/Is.java
parent21a7b5b68f0bdc465bf6270db8917b881cf04157 (diff)
downloadhamcrest-c1dbb44e71e47410ad5685aba3ef3fccb095a2b4.tar.gz
Upgrade to almost 2.0.0.0
See the README.android for the exact version used and an explanation as to why it was chosen. Bug: 30946317 Test: make checkbuild Change-Id: Icae106f5e4a62d2a34f4cf03506fd63676814c07
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.java64
1 files changed, 36 insertions, 28 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
index f9152e9..ec22238 100644
--- a/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
+++ b/hamcrest-core/src/main/java/org/hamcrest/core/Is.java
@@ -1,68 +1,76 @@
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;
+import org.hamcrest.Matcher;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
/**
- * Decorates another Matcher, retaining the behavior but allowing tests
+ * Decorates another Matcher, retaining the behaviour but allowing tests
* to be slightly more expressive.
*
- * eg. assertThat(cheese, equalTo(smelly))
- * vs assertThat(cheese, is(equalTo(smelly)))
+ * For example: 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;
}
+ @Override
public boolean matches(Object arg) {
return matcher.matches(arg);
}
+ @Override
public void describeTo(Description description) {
description.appendText("is ").appendDescriptionOf(matcher);
}
-
+
+ @Override
+ public void describeMismatch(Object item, Description mismatchDescription) {
+ matcher.describeMismatch(item, mismatchDescription);
+ }
+
/**
- * Decorates another Matcher, retaining the behavior but allowing tests
+ * Decorates another Matcher, retaining its behaviour, but allowing tests
* to be slightly more expressive.
- *
- * eg. assertThat(cheese, equalTo(smelly))
- * vs assertThat(cheese, is(equalTo(smelly)))
+ * For example:
+ * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
+ * instead of:
+ * <pre>assertThat(cheese, equalTo(smelly))</pre>
+ *
*/
- @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))
+ * A shortcut to the frequently used <code>is(equalTo(x))</code>.
+ * For example:
+ * <pre>assertThat(cheese, is(smelly))</pre>
+ * instead of:
+ * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
+ *
*/
- @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))
+ * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.
+ * For example:
+ * <pre>assertThat(cheese, isA(Cheddar.class))</pre>
+ * instead of:
+ * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>
+ *
*/
- @Factory
- public static Matcher<Object> is(Class<?> type) {
- return is(instanceOf(type));
+ public static <T> Matcher<T> isA(Class<T> type) {
+ final Matcher<T> typeMatcher = instanceOf(type);
+ return is(typeMatcher);
}
-
}
-