• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.hamcrest.beans;
2 
3 import org.hamcrest.Matcher;
4 import org.junit.Test;
5 
6 import static org.hamcrest.AbstractMatcherTest.*;
7 import static org.hamcrest.beans.HasProperty.hasProperty;
8 
9 /**
10  * @author Iain McGinniss
11  * @author Nat Pryce
12  * @author Steve Freeman
13  * @author Tom Denley
14  * @since 1.1.0
15  */
16 public final class HasPropertyTest {
17 
18     private final HasPropertyWithValueTest.BeanWithoutInfo bean = new HasPropertyWithValueTest.BeanWithoutInfo("a bean");
19 
20     @Test public void
copesWithNullsAndUnknownTypes()21     copesWithNullsAndUnknownTypes() {
22         Matcher<Object> matcher = hasProperty("irrelevant");
23 
24         assertNullSafe(matcher);
25         assertUnknownTypeSafe(matcher);
26     }
27 
28     @Test public void
matchesWhenThePropertyExists()29     matchesWhenThePropertyExists() {
30         assertMatches(hasProperty("writeOnlyProperty"), bean);
31     }
32 
33     @Test public void
doesNotMatchIfPropertyDoesNotExist()34     doesNotMatchIfPropertyDoesNotExist() {
35         assertDoesNotMatch(hasProperty("aNonExistentProp"), bean);
36     }
37 
38     @Test public void
describesItself()39     describesItself() {
40         assertDescription("hasProperty(\"property\")", hasProperty("property"));
41     }
42 
43     @Test public void
describesAMismatch()44     describesAMismatch() {
45         assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>",
46                                   hasProperty("aNonExistentProp"), bean);
47     }
48 }
49