|
2 | 2 | */ |
3 | 3 | package org.hamcrest.beans; |
4 | 4 |
|
5 | | -import static org.hamcrest.MatcherAssert.assertThat; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; |
| 9 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 10 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
6 | 11 | import static org.hamcrest.beans.HasProperty.hasProperty; |
7 | | -import static org.hamcrest.core.IsNot.not; |
8 | 12 |
|
9 | | -import org.hamcrest.AbstractMatcherTest; |
10 | 13 | import org.hamcrest.Matcher; |
| 14 | +import org.junit.Test; |
11 | 15 |
|
12 | 16 | /** |
13 | 17 | * @author Iain McGinniss |
14 | 18 | * @author Nat Pryce |
15 | 19 | * @author Steve Freeman |
| 20 | + * @author Tom Denley |
16 | 21 | * @since 1.1.0 |
17 | 22 | */ |
18 | | -public class HasPropertyTest extends AbstractMatcherTest { |
| 23 | +public final class HasPropertyTest { |
19 | 24 |
|
20 | | - private final HasPropertyWithValueTest.BeanWithoutInfo bean |
21 | | - = new HasPropertyWithValueTest.BeanWithoutInfo("a bean"); |
| 25 | + private final HasPropertyWithValueTest.BeanWithoutInfo bean = new HasPropertyWithValueTest.BeanWithoutInfo("a bean"); |
22 | 26 |
|
23 | | - @Override |
24 | | - protected Matcher<?> createMatcher() { |
25 | | - return hasProperty("irrelevant"); |
| 27 | + @Test public void |
| 28 | + copesWithNullsAndUnknownTypes() { |
| 29 | + Matcher<Object> matcher = hasProperty("irrelevant"); |
| 30 | + |
| 31 | + assertNullSafe(matcher); |
| 32 | + assertUnknownTypeSafe(matcher); |
26 | 33 | } |
27 | 34 |
|
28 | | - public void testReturnsTrueIfPropertyExists() { |
29 | | - assertThat(bean, hasProperty("writeOnlyProperty")); |
| 35 | + @Test public void |
| 36 | + matchesWhenThePropertyExists() { |
| 37 | + assertMatches("didn't match", hasProperty("writeOnlyProperty"), bean); |
30 | 38 | } |
31 | 39 |
|
32 | | - public void testReturnsFalseIfPropertyDoesNotExist() { |
33 | | - final Matcher<Object> hasProperty = hasProperty("aNonExistentProp"); |
34 | | - assertThat(bean, not(hasProperty)); |
35 | | - assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>", hasProperty, bean); |
| 40 | + @Test public void |
| 41 | + doesNotMatchIfPropertyDoesNotExist() { |
| 42 | + assertDoesNotMatch("matched unexpectedly", hasProperty("aNonExistentProp"), bean); |
36 | 43 | } |
37 | 44 |
|
38 | | - public void testDescribeTo() { |
| 45 | + @Test public void |
| 46 | + describesItself() { |
39 | 47 | assertDescription("hasProperty(\"property\")", hasProperty("property")); |
40 | 48 | } |
| 49 | + |
| 50 | + @Test public void |
| 51 | + describesAMismatch() { |
| 52 | + assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>", |
| 53 | + hasProperty("aNonExistentProp"), bean); |
| 54 | + } |
41 | 55 | } |
0 commit comments