/** * Creates a matcher that always matches, regardless of the examined object, but describes * itself with the specified {@link String}. * * @param description * a meaningful {@link String} used when describing itself */ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) { return org.hamcrest.core.IsAnything.anything(description); }
/** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher<java.lang.Object> anything() { return org.hamcrest.core.IsAnything.anything(); }
/** * Creates a matcher that always matches, regardless of the examined object, but describes * itself with the specified {@link String}. * * @param description * a meaningful {@link String} used when describing itself */ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) { return org.hamcrest.core.IsAnything.anything(description); }
/** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher<java.lang.Object> anything() { return org.hamcrest.core.IsAnything.anything(); }
/** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher<java.lang.Object> anything() { return org.hamcrest.core.IsAnything.anything(); }
/** * Creates a matcher that always matches, regardless of the examined object, but describes * itself with the specified {@link String}. * * @param description * a meaningful {@link String} used when describing itself */ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) { return org.hamcrest.core.IsAnything.anything(description); }
/** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher<java.lang.Object> anything() { return org.hamcrest.core.IsAnything.anything(); }
/** * Creates a matcher that always matches, regardless of the examined object, but describes * itself with the specified {@link String}. * * @param description * a meaningful {@link String} used when describing itself */ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) { return org.hamcrest.core.IsAnything.anything(description); }
/** * Creates a matcher that always matches, regardless of the examined object. */ public static org.hamcrest.Matcher<java.lang.Object> anything() { return org.hamcrest.core.IsAnything.anything(); }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that satisfies the specified matcher. * <p/> * For example: * <pre>assertThat(myMap, hasKey(equalTo("bar")))</pre> * * @param keyMatcher * the matcher that must be satisfied by at least one key */ @Factory public static <K> Matcher<Map<? extends K, ?>> hasKey(Matcher<? super K> keyMatcher) { return new IsMapContaining<K,Object>(keyMatcher, anything()); }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that is equal to the specified key. * <p/> * For example: * <pre>assertThat(myMap, hasKey("bar"))</pre> * * @param key * the key that satisfying maps must contain */ @Factory public static <K> Matcher<Map<? extends K, ?>> hasKey(K key) { return new IsMapContaining<K,Object>(equalTo(key), anything()); }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one value that satisfies the specified valueMatcher. * <p/> * For example: * <pre>assertThat(myMap, hasValue(equalTo("foo")))</pre> * * @param valueMatcher * the matcher that must be satisfied by at least one value */ @Factory public static <V> Matcher<Map<?, ? extends V>> hasValue(Matcher<? super V> valueMatcher) { return new IsMapContaining<Object,V>(anything(), valueMatcher); }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one value that is equal to the specified value. * <p/> * For example: * <pre>assertThat(myMap, hasValue("foo"))</pre> * * @param value * the value that satisfying maps must contain */ @Factory public static <V> Matcher<Map<?, ? extends V>> hasValue(V value) { return new IsMapContaining<Object,V>(anything(), equalTo(value)); } }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that is equal to the specified key. * For example: * <pre>assertThat(myMap, hasKey("bar"))</pre> * * @param key * the key that satisfying maps must contain */ public static <K> Matcher<Map<? extends K, ?>> hasKey(K key) { return new IsMapContaining<>(equalTo(key), anything()); }
/** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one value that satisfies the specified valueMatcher. * For example: * <pre>assertThat(myMap, hasValue(equalTo("foo")))</pre> * * @param valueMatcher * the matcher that must be satisfied by at least one value */ public static <V> Matcher<Map<?, ? extends V>> hasValue(Matcher<? super V> valueMatcher) { return new IsMapContaining<>(anything(), valueMatcher); }
@Test public void canOverrideDescription() { String description = "description"; assertDescription(description, anything(description)); }
@Test public void overridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { Matcher<?> matcher = describedAs("my description", anything()); assertDescription("my description", matcher); }
public void testDoesNotWriteMismatchIfPropertyMatches() { Description description = new StringDescription(); hasProperty( "property", anything()).describeMismatch(beanWithInfo, description); assertEquals("Expected mismatch description", "", description.toString()); }
public void testExceptionsInBeanMethodsShouldBeReportedCorrectly() { assertMismatchDescription( "Calling 'public java.lang.String org.hamcrest.beans.HasPropertyWithValueTest$BeanWithBug.getBroken()': \"bean failed\"", hasProperty("broken", anything()), new BeanWithBug()); }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<Object> matcher = describedAs("irrelevant", anything()); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); }