Skip to content

Commit 60d350a

Browse files
committed
convert test for HasProperty matcher JUnit 4.
1 parent a7c4167 commit 60d350a

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

‎hamcrest-library/src/test/java/org/hamcrest/beans/HasPropertyTest.java‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,54 @@
22
*/
33
package org.hamcrest.beans;
44

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;
611
import static org.hamcrest.beans.HasProperty.hasProperty;
7-
import static org.hamcrest.core.IsNot.not;
812

9-
import org.hamcrest.AbstractMatcherTest;
1013
import org.hamcrest.Matcher;
14+
import org.junit.Test;
1115

1216
/**
1317
* @author Iain McGinniss
1418
* @author Nat Pryce
1519
* @author Steve Freeman
20+
* @author Tom Denley
1621
* @since 1.1.0
1722
*/
18-
public class HasPropertyTest extends AbstractMatcherTest {
23+
public final class HasPropertyTest {
1924

20-
private final HasPropertyWithValueTest.BeanWithoutInfo bean
21-
= new HasPropertyWithValueTest.BeanWithoutInfo("a bean");
25+
private final HasPropertyWithValueTest.BeanWithoutInfo bean = new HasPropertyWithValueTest.BeanWithoutInfo("a bean");
2226

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);
2633
}
2734

28-
public void testReturnsTrueIfPropertyExists() {
29-
assertThat(bean, hasProperty("writeOnlyProperty"));
35+
@Test public void
36+
matchesWhenThePropertyExists() {
37+
assertMatches("didn't match", hasProperty("writeOnlyProperty"), bean);
3038
}
3139

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);
3643
}
3744

38-
public void testDescribeTo() {
45+
@Test public void
46+
describesItself() {
3947
assertDescription("hasProperty(\"property\")", hasProperty("property"));
4048
}
49+
50+
@Test public void
51+
describesAMismatch() {
52+
assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>",
53+
hasProperty("aNonExistentProp"), bean);
54+
}
4155
}

0 commit comments

Comments
 (0)