Skip to content

Commit 8d25c2c

Browse files
committed
deprecated some matcher factory methods that have the "is" prefix, providing alternatives which omit it. This addresses googlecode issue no 153
1 parent 9e2a159 commit 8d25c2c

3 files changed

Lines changed: 101 additions & 14 deletions

File tree

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsIn.java‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,31 @@ public void describeTo(Description buffer) {
3737
* For example:
3838
* <pre>assertThat("foo", isIn(Arrays.asList("bar", "foo")))</pre>
3939
*
40+
* @deprecated use is(in(...)) instead
41+
*
4042
* @param collection
4143
* the collection in which matching items must be found
4244
*
4345
*/
46+
@Deprecated
4447
@Factory
4548
public static <T> Matcher<T> isIn(Collection<T> collection) {
49+
return in(collection);
50+
}
51+
52+
/**
53+
* Creates a matcher that matches when the examined object is found within the
54+
* specified collection.
55+
* <p/>
56+
* For example:
57+
* <pre>assertThat("foo", is(in(Arrays.asList("bar", "foo"))))</pre>
58+
*
59+
* @param collection
60+
* the collection in which matching items must be found
61+
*
62+
*/
63+
@Factory
64+
public static <T> Matcher<T> in(Collection<T> collection) {
4665
return new IsIn<T>(collection);
4766
}
4867

@@ -53,12 +72,31 @@ public static <T> Matcher<T> isIn(Collection<T> collection) {
5372
* For example:
5473
* <pre>assertThat("foo", isIn(new String[]{"bar", "foo"}))</pre>
5574
*
75+
* @deprecated use is(in(...)) instead
76+
*
5677
* @param elements
5778
* the array in which matching items must be found
5879
*
5980
*/
81+
@Deprecated
6082
@Factory
6183
public static <T> Matcher<T> isIn(T[] elements) {
84+
return in(elements);
85+
}
86+
87+
/**
88+
* Creates a matcher that matches when the examined object is found within the
89+
* specified array.
90+
* <p/>
91+
* For example:
92+
* <pre>assertThat("foo", is(in(new String[]{"bar", "foo"})))</pre>
93+
*
94+
* @param elements
95+
* the array in which matching items must be found
96+
*
97+
*/
98+
@Factory
99+
public static <T> Matcher<T> in(T[] elements) {
62100
return new IsIn<T>(elements);
63101
}
64102

@@ -67,14 +105,33 @@ public static <T> Matcher<T> isIn(T[] elements) {
67105
* specified elements.
68106
* <p/>
69107
* For example:
70-
* <pre>assertThat("foo", isIn("bar", "foo"))</pre>
71-
*
108+
* <pre>assertThat("foo", isOneOf("bar", "foo"))</pre>
109+
*
110+
* @deprecated use is(oneOf(...)) instead
111+
*
72112
* @param elements
73113
* the elements amongst which matching items will be found
74114
*
75115
*/
116+
@Deprecated
76117
@Factory
77118
public static <T> Matcher<T> isOneOf(T... elements) {
78-
return isIn(elements);
119+
return oneOf(elements);
120+
}
121+
122+
/**
123+
* Creates a matcher that matches when the examined object is equal to one of the
124+
* specified elements.
125+
* <p/>
126+
* For example:
127+
* <pre>assertThat("foo", is(oneOf("bar", "foo")))</pre>
128+
*
129+
* @param elements
130+
* the elements amongst which matching items will be found
131+
*
132+
*/
133+
@Factory
134+
public static <T> Matcher<T> oneOf(T... elements) {
135+
return in(elements);
79136
}
80137
}

‎hamcrest-library/src/main/java/org/hamcrest/text/IsEmptyString.java‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,23 @@ public void describeTo(Description description) {
3333
* For example:
3434
* <pre>assertThat("", isEmptyString())</pre>
3535
*
36+
* @deprecated use is(emptyString()) instead
3637
*/
38+
@Deprecated
3739
@Factory
3840
public static Matcher<String> isEmptyString() {
41+
return emptyString();
42+
}
43+
44+
/**
45+
* Creates a matcher of {@link String} that matches when the examined string has zero length.
46+
* <p/>
47+
* For example:
48+
* <pre>assertThat("", is(emptyString()))</pre>
49+
*
50+
*/
51+
@Factory
52+
public static Matcher<String> emptyString() {
3953
return INSTANCE;
4054
}
4155

@@ -44,11 +58,27 @@ public static Matcher<String> isEmptyString() {
4458
* has zero length.
4559
* <p/>
4660
* For example:
47-
* <pre>assertThat(((String)null), isEmptyString())</pre>
61+
* <pre>assertThat(((String)null), isEmptyOrNullString())</pre>
62+
*
63+
* @deprecated use is(emptyOrNullString()) instead
4864
*
4965
*/
66+
@Deprecated
5067
@Factory
5168
public static Matcher<String> isEmptyOrNullString() {
69+
return emptyOrNullString();
70+
}
71+
72+
/**
73+
* Creates a matcher of {@link String} that matches when the examined string is <code>null</code>, or
74+
* has zero length.
75+
* <p/>
76+
* For example:
77+
* <pre>assertThat(((String)null), is(emptyOrNullString()))</pre>
78+
*
79+
*/
80+
@Factory
81+
public static Matcher<String> emptyOrNullString() {
5282
return NULL_OR_EMPTY_INSTANCE;
5383
}
5484
}

‎hamcrest-unit-test/src/main/java/org/hamcrest/text/IsEmptyStringTest.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.core.IsNot.not;
5-
import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString;
6-
import static org.hamcrest.text.IsEmptyString.isEmptyString;
5+
import static org.hamcrest.text.IsEmptyString.emptyOrNullString;
6+
import static org.hamcrest.text.IsEmptyString.emptyString;
77

88
import org.hamcrest.AbstractMatcherTest;
99
import org.hamcrest.Matcher;
@@ -12,29 +12,29 @@ public class IsEmptyStringTest extends AbstractMatcherTest {
1212

1313
@Override
1414
protected Matcher<?> createMatcher() {
15-
return isEmptyOrNullString();
15+
return emptyOrNullString();
1616
}
1717

1818
public void testEmptyOrNullIsNull() {
19-
assertThat(null, isEmptyOrNullString());
19+
assertThat(null, emptyOrNullString());
2020
}
2121

2222

2323
public void testEmptyIsNotNull() {
24-
assertThat(null, not(isEmptyString()));
24+
assertThat(null, not(emptyString()));
2525
}
2626

2727
public void testMatchesEmptyString() {
28-
assertMatches("empty string", isEmptyString(), "");
29-
assertMatches("empty string", isEmptyOrNullString(), "");
28+
assertMatches("empty string", emptyString(), "");
29+
assertMatches("empty string", emptyOrNullString(), "");
3030
}
3131

3232
public void testDoesNotMatchNonEmptyString() {
33-
assertDoesNotMatch("non empty string", isEmptyString(), "a");
33+
assertDoesNotMatch("non empty string", emptyString(), "a");
3434
}
3535

3636
public void testHasAReadableDescription() {
37-
assertDescription("an empty string", isEmptyString());
38-
assertDescription("(null or an empty string)", isEmptyOrNullString());
37+
assertDescription("an empty string", emptyString());
38+
assertDescription("(null or an empty string)", emptyOrNullString());
3939
}
4040
}

0 commit comments

Comments
 (0)