* * *

|  [ **Overview** ](../../../overview-summary.html) |  [ **Package** ](package-summary.html) |  **Class** |  [ **Use** ](class-use/HasPropertyWithValue.html) |  [ **Tree** ](package-tree.html) |  [ **Deprecated** ](../../../deprecated-list.html) |  [ **Index** ](../../../index-all.html) |  [ **Help** ](../../../help-doc.html)  
---|---|---|---|---|---|---|---  
__  
[ **PREV CLASS** ](../../../org/hamcrest/beans/HasProperty.html "class in org.hamcrest.beans") [ **NEXT CLASS** ](../../../org/hamcrest/beans/PropertyUtil.html "class in org.hamcrest.beans") |  [ **FRAMES** ](../../../index.html?org/hamcrest/beans/HasPropertyWithValue.html) [ **NO FRAMES** ](HasPropertyWithValue.html) [ **All Classes** ](../../../allclasses-noframe.html)  
SUMMARY: NESTED | FIELD |  CONSTR  |  METHOD  |  DETAIL: FIELD |  CONSTR  |  METHOD   
  
* * *

##  org.hamcrest.beans  
Class HasPropertyWithValue<T>

    
    
    java.lang.Object
      ![extended by ](../../../resources/inherit.gif)[org.hamcrest.BaseMatcher](../../../org/hamcrest/BaseMatcher.html "class in org.hamcrest")<T>
          ![extended by ](../../../resources/inherit.gif)[org.hamcrest.TypeSafeDiagnosingMatcher](../../../org/hamcrest/TypeSafeDiagnosingMatcher.html "class in org.hamcrest")<T>
              ![extended by ](../../../resources/inherit.gif)**org.hamcrest.beans.HasPropertyWithValue <T>**
    

**All Implemented Interfaces:**      [ Matcher
](../../../org/hamcrest/Matcher.html "interface in org.hamcrest") <T>, [
SelfDescribing ](../../../org/hamcrest/SelfDescribing.html "interface in
org.hamcrest")

* * *
    
    
    public class **HasPropertyWithValue <T>**extends [TypeSafeDiagnosingMatcher](../../../org/hamcrest/TypeSafeDiagnosingMatcher.html "class in org.hamcrest")<T>

Matcher that asserts that a JavaBean property on an argument passed to the
mock object meets the provided matcher. This is useful for when objects are
created within code under test and passed to a mock object, and you wish to
assert that the created object has certain properties.

##  Example Usage

Consider the situation where we have a class representing a person, which
follows the basic JavaBean convention of having get() and possibly set()
methods for it's properties:

    
    
     public class Person {
       private String name;
       public Person(String person) {
         this.person = person;
       }
       public String getName() {
         return name;
       }
     }

And that these person objects are generated within a piece of code under test
(a class named PersonGenerator). This object is sent to one of our mock
objects which overrides the PersonGenerationListener interface:

    
    
     public interface PersonGenerationListener {
       public void personGenerated(Person person);
     }

In order to check that the code under test generates a person with name "Iain"
we would do the following:

    
    
     Mock personGenListenerMock = mock(PersonGenerationListener.class);
     personGenListenerMock.expects(once()).method("personGenerated").with(and(isA(Person.class), hasProperty("Name", eq("Iain")));
     PersonGenerationListener listener = (PersonGenerationListener)personGenListenerMock.proxy();

If an exception is thrown by the getter method for a property, the property
does not exist, is not readable, or a reflection related exception is thrown
when trying to invoke it then this is treated as an evaluation failure and the
matches method will return false.

This matcher class will also work with JavaBean objects that have explicit
bean descriptions via an associated BeanInfo description class. See the
JavaBeans specification for more information:

http://java.sun.com/products/javabeans/docs/index.html

**Author:**

     Iain McGinniss, Nat Pryce, Steve Freeman 

* * *

**Constructor Summary**  
---  
` **[ HasPropertyWithValue
](../../../org/hamcrest/beans/HasPropertyWithValue.html#HasPropertyWithValue\(java.lang.String,
org.hamcrest.Matcher\)) ** (java.lang.String prop