Top Description Fields Constructors Methods
org.hamcrest.beans

public Class HasProperty<T>

extends TypeSafeMatcher<T>
Class Inheritance
Imports
org.hamcrest.Description, .Factory, .Matcher, .TypeSafeMatcher

A Matcher that checks that an object has a JavaBean property with the specified name. If an error occurs during introspection of the object then this is treated as a mismatch.
Authors
Iain McGinniss, Nat Pryce, Steve Freeman

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
HasProperty(String propertyName)

Method Summary

Modifier and TypeMethod and Description
public void
describeMismatchSafely(T item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <T> Matcher<T>
hasProperty(String
the name of the JavaBean property that examined beans should possess
propertyName
)

Creates a matcher that matches when the examined object has a JavaBean property with the specified name.

public boolean
matchesSafely(T obj)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeMatcher:
describeMismatchmatches

Field Detail

propertyNameback to summary
private final String propertyName

Constructor Detail

HasPropertyback to summary
public HasProperty(String propertyName)

Method Detail

describeMismatchSafelyback to summary
public void describeMismatchSafely(T item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
hasPropertyback to summary
public static <T> Matcher<T> hasProperty(String propertyName)

Creates a matcher that matches when the examined object has a JavaBean property with the specified name.

For example:

assertThat(myBean, hasProperty("foo"))
Parameters
propertyName:String

the name of the JavaBean property that examined beans should possess

Annotations
@Factory
matchesSafelyback to summary
public boolean matchesSafely(T obj)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override