/*  Copyright (c) 2000-2006 hamcrest.org
 */
package org.hamcrest.beans;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.beans.HasProperty.hasProperty;
import static org.hamcrest.core.IsNot.not;

import org.hamcrest.AbstractMatcherTest;
import org.hamcrest.Matcher;

/**
 * @author Iain McGinniss
 * @author Nat Pryce
 * @author Steve Freeman
 * @since 1.1.0
 */
public class HasPropertyTest extends AbstractMatcherTest {

    private final HasPropertyWithValueTest.BeanWithoutInfo bean
            = new HasPropertyWithValueTest.BeanWithoutInfo("a bean");

    @Override
    protected Matcher<?> createMatcher() {
        return hasProperty("irrelevant");
    }

    public void testReturnsTrueIfPropertyExists() {
        assertThat(bean, hasProperty("writeOnlyProperty"));
    }

    public void testReturnsFalseIfPropertyDoesNotExist() {
        final Matcher<Object> hasProperty = hasProperty("aNonExistentProp");
        assertThat(bean, not(hasProperty));
        assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>", hasProperty, bean);
    }

    public void testDescribeTo() {
        assertDescription("hasProperty(\"property\")", hasProperty("property"));
    }
}

@@ -98,176 +98,441 @@
 est.
-MatcherAssert.assertThat;%0Aimport static org.hamcrest.beans.HasProperty.hasProperty;%0Aimport static org.hamcrest.core.IsNot.not;%0A%0Aimport org.hamcrest.AbstractMatcherTest;
+AbstractMatcherTest.assertDescription;%0Aimport static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch;%0Aimport static org.hamcrest.AbstractMatcherTest.assertMatches;%0Aimport static org.hamcrest.AbstractMatcherTest.assertMismatchDescription;%0Aimport static org.hamcrest.AbstractMatcherTest.assertNullSafe;%0Aimport static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe;%0Aimport static org.hamcrest.beans.HasProperty.hasProperty;%0A
 %0Aimp
@@ -556,16 +556,39 @@
 Matcher;
+%0Aimport org.junit.Test;
 %0A%0A/**%0A *
@@ -657,16 +657,38 @@
 Freeman%0A
+ * @author Tom Denley%0A
  * @sinc
@@ -706,16 +706,22 @@
 %0Apublic 
+final 
 class Ha
@@ -738,36 +738,8 @@
 est 
-extends AbstractMatcherTest 
 %7B%0A%0A 
@@ -804,20 +804,8 @@
 bean
-%0A           
  = n
@@ -869,99 +869,203 @@
    @
-Overr
+Test public vo
 id
-e
 %0A    
-protected Matcher%3C?%3E createMatcher() %7B%0A        return hasProperty(%22irrelevant%22
+copesWithNullsAndUnknownTypes() %7B%0A        Matcher%3CObject%3E matcher = hasProperty(%22irrelevant%22);%0A        %0A        assertNullSafe(matcher);%0A        assertUnknownTypeSafe(matcher
 );%0A 
@@ -1066,32 +1066,38 @@
 er);%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1095,26 +1095,27 @@
 void
- testReturnsTrueIf
+%0A    matchesWhenThe
 Prop
@@ -1143,25 +1143,38 @@
   assert
-That(bean
+Matches(%22didn't match%22
 , hasPro
@@ -1191,32 +1191,38 @@
 teOnlyProperty%22)
+, bean
 );%0A    %7D%0A%0A    pu
@@ -1211,32 +1211,38 @@
 an);%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1240,25 +1240,25 @@
 void
- testReturnsFalse
+%0A    doesNotMatch
 IfPr
@@ -1292,43 +1292,50 @@
     
-final Matcher%3CObject%3E hasProperty =
+assertDoesNotMatch(%22matched unexpectedly%22,
  has
@@ -1366,53 +1366,69 @@
 op%22)
+, bean)
 ;%0A    
+%7D%0A%0A
     
-assertThat(bean, not(hasProperty));
+@Test public void%0A    describesItself() %7B
 %0A   
@@ -1434,32 +1434,24 @@
       assert
-Mismatch
 Description(
@@ -1455,53 +1455,33 @@
 on(%22
-no %5C%22aNonExistentProp%5C%22 in %3C%5BPerson: a bean%5D%3E
+hasProperty(%5C%22property%5C%22)
 %22, h
@@ -1490,22 +1490,28 @@
 Property
-, bean
+(%22property%22)
 );%0A    %7D
@@ -1516,16 +1516,22 @@
  %7D%0A%0A    
+@Test 
 public v
@@ -1537,23 +1537,31 @@
 void
- testD
+%0A    d
 escribe
-To
+sAMismatch
 () %7B
@@ -1567,32 +1567,40 @@
 %7B%0A        assert
+Mismatch
 Description(%22has
@@ -1600,59 +1600,127 @@
 on(%22
-hasProperty(%5C%22property%5C%22)%22, hasProperty(%22property%22)
+no %5C%22aNonExistentProp%5C%22 in %3C%5BPerson: a bean%5D%3E%22,%0A                                  hasProperty(%22aNonExistentProp%22), bean
 );%0A 

convert test for HasProperty matcher JUnit 4.