|
2 | 2 | */ |
3 | 3 | package org.hamcrest.object; |
4 | 4 |
|
| 5 | +import static org.hamcrest.core.IsAnything.anything; |
| 6 | +import static org.hamcrest.core.IsEqual.eq; |
| 7 | +import static org.hamcrest.core.IsNot.not; |
| 8 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | +import static org.hamcrest.object.HasPropertyWithValue.hasProperty; |
5 | 10 | import org.hamcrest.AbstractMatcherTest; |
6 | 11 | import org.hamcrest.Description; |
| 12 | +import org.hamcrest.Matcher; |
7 | 13 | import org.hamcrest.core.IsAnything; |
8 | 14 | import org.hamcrest.core.IsEqual; |
9 | | -import org.hamcrest.core.IsSame; |
10 | 15 | import org.hamcrest.internal.StringDescription; |
11 | 16 |
|
12 | 17 | import java.beans.IntrospectionException; |
|
20 | 25 | * @since 1.1.0 |
21 | 26 | */ |
22 | 27 | public class HasPropertyWithValueTest extends AbstractMatcherTest { |
23 | | - final private BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected"); |
24 | | - final private BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo("not expected"); |
25 | | - final private BeanWithInfo beanWithInfo = new BeanWithInfo("with info"); |
26 | 28 |
|
27 | | - public void testMatchesInfolessBeanWithMatchedNamedProperty() { |
28 | | - HasPropertyWithValue hasProperty = new HasPropertyWithValue("property", new IsSame("is expected")); |
| 29 | + private final BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected"); |
| 30 | + private final BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo("not expected"); |
| 31 | + private final BeanWithInfo beanWithInfo = new BeanWithInfo("with info"); |
29 | 32 |
|
30 | | - assertTrue(hasProperty.match(shouldMatch)); |
31 | | - assertFalse(hasProperty.match(shouldNotMatch)); |
| 33 | + public void testMatchesInfolessBeanWithMatchedNamedProperty() { |
| 34 | + assertThat(shouldMatch, hasProperty("property", eq("is expected"))); |
| 35 | + assertThat(shouldNotMatch, not(hasProperty("property", eq("is expected")))); |
32 | 36 | } |
33 | 37 |
|
34 | 38 | public void testMatchesBeanWithInfoWithMatchedNamedProperty() { |
35 | | - HasPropertyWithValue hasProperty = new HasPropertyWithValue("property", new IsSame("with info")); |
36 | | - assertTrue(hasProperty.match(beanWithInfo)); |
| 39 | + assertThat(beanWithInfo, hasProperty("property", eq("with info"))); |
37 | 40 | } |
38 | 41 |
|
39 | 42 | public void testDoesNotMatchInfolessBeanWithoutMatchedNamedProperty() { |
40 | | - HasPropertyWithValue hasProperty = new HasPropertyWithValue("nonExistentProperty", new IsAnything()); |
41 | | - assertFalse(hasProperty.match(shouldNotMatch)); |
| 43 | + assertThat(shouldNotMatch, not(hasProperty("nonExistentProperty", anything()))); |
42 | 44 | } |
43 | 45 |
|
44 | 46 | public void testDoesNotMatchWriteOnlyProperty() { |
45 | | - HasPropertyWithValue hasProperty = new HasPropertyWithValue("writeOnlyProperty", new IsAnything()); |
46 | | - assertFalse(hasProperty.match(shouldNotMatch)); |
| 47 | + assertThat(shouldNotMatch, not(hasProperty("writeOnlyProperty", anything()))); |
47 | 48 | } |
48 | 49 |
|
49 | 50 | public void testDescribeTo() { |
50 | | - IsEqual isEqual = new IsEqual(Boolean.TRUE); |
| 51 | + Matcher matcher = eq(true); |
51 | 52 | Description isEqualDescription = new StringDescription(); |
52 | | - isEqual.describeTo(isEqualDescription); |
53 | | - HasPropertyWithValue hasProperty = new HasPropertyWithValue("property", new IsEqual(Boolean.TRUE)); |
| 53 | + matcher.describeTo(isEqualDescription); |
54 | 54 |
|
55 | | - assertDescription("hasProperty(\"property\", " + isEqualDescription + ")", hasProperty); |
| 55 | + assertDescription("hasProperty(\"property\", " + isEqualDescription + ")", |
| 56 | + hasProperty("property", matcher)); |
56 | 57 | } |
57 | 58 |
|
58 | 59 | public static class BeanWithoutInfo { |
|
0 commit comments