diff options
author | Paul Duffin <paulduffin@google.com> | 2017-01-20 13:50:23 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2017-01-20 13:50:23 +0000 |
commit | 74299c53a59140905e0259cb0a1130cb719733d8 (patch) | |
tree | aa4a6a53609f47d386dfa114be0abfc01e0e5dff /hamcrest-core/src/main/java/org/hamcrest/core/Is.java | |
parent | f1015b50e715aefc3070d83d95340cbc29811329 (diff) | |
download | hamcrest-74299c53a59140905e0259cb0a1130cb719733d8.tar.gz |
Match upstream file structure
Bug: 30946317
Test: make checkbuild and run cts CtsTextTestCases
Change-Id: I6c1773018f95855eb6599d66f6fb5923c7d48b03
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.java | 68 |
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)); + } + +} + |