...88 * instead of:89 * <pre>assertThat(cheese, equalTo(smelly))</pre>90 */91 public static <T> org.hamcrest.Matcher<T> is(org.hamcrest.Matcher<T> matcher) {92 return org.hamcrest.core.Is.is(matcher);93 }94 /**95 * A shortcut to the frequently used <code>is(equalTo(x))</code>.96 * For example:97 * <pre>assertThat(cheese, is(smelly))</pre>98 * instead of:99 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>100 */101 public static <T> org.hamcrest.Matcher<T> is(T value) {102 return org.hamcrest.core.Is.is(value);103 }104 /**105 * Provided to cause compile time error when used in preference to a possible runtime error if106 * this was not here.107 *108 * <p>This method was removed upstream between Hamcrest 1.1 and 1.3 in favour of the109 * instanceOf(Class) method. Unfortunately, existing usages of it could still compile against the110 * {@link #is(Object)} method instead. Although not every existing usage would compile111 * successfully it is possible that some could and that would result in a change in the runtime112 * behavior that could be difficult to detect and fix. This change aims to turn any significant113 * usage of this method into a compile time error.114 *115 * @deprecated Use instanceOf(SomeClass.class) instead.116 */117 public static void is(java.lang.Class<?> type) {118 }119 /**120 * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.121 * For example:122 * <pre>assertThat(cheese, isA(Cheddar.class))</pre>123 * instead of:124 * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>125 */126 public static <T> org.hamcrest.Matcher<T> isA(java.lang.Class<T> type) {127 return org.hamcrest.core.Is.isA(type);128 }129 /**130 * Creates a matcher that always matches, regardless of the examined object.131 */132 public static org.hamcrest.Matcher<java.lang.Object> anything() {133 return org.hamcrest.core.IsAnything.anything();134 }135 /**136 * Creates a matcher that always matches, regardless of the examined object, but describes137 * itself with the specified {@link String}.138 * 139 * @param description140 * a meaningful {@link String} used when describing itself141 */142 public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) {143 return org.hamcrest.core.IsAnything.anything(description);144 }145 /**146 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the147 * examined {@link Iterable} yields at least one item that is matched by the specified148 * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable}149 * will stop as soon as a matching item is found.150 * For example:151 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre>152 * 153 * @param itemMatcher154 * the matcher to apply to items provided by the examined {@link Iterable}155 */156 public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) {157 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher);158 }159 /**160 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the161 * examined {@link Iterable} yields at least one item that is equal to the specified162 * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable}163 * will stop as soon as a matching item is found.164 * For example:165 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre>166 * 167 * @param item168 * the item to compare against the items provided by the examined {@link Iterable}169 */170 public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) {171 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item);172 }173 /**174 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the175 * examined {@link Iterable} yield at least one item that is matched by the corresponding176 * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of177 * the examined {@link Iterable} will stop as soon as a matching item is found.178 * For example:179 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre>180 * 181 * @param itemMatchers182 * the matchers to apply to items provided by the examined {@link Iterable}183 */184 @SafeVarargs185 public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) {186 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(itemMatchers);187 }188 /**189 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the190 * examined {@link Iterable} yield at least one item that is equal to the corresponding191 * item from the specified <code>items</code>. Whilst matching, each traversal of the192 * examined {@link Iterable} will stop as soon as a matching item is found.193 * For example:194 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre>195 * 196 * @param items197 * the items to compare against the items provided by the examined {@link Iterable}198 */199 @SafeVarargs200 public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) {201 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(items);202 }203 /**204 * Creates a matcher that matches when the examined object is logically equal to the specified205 * <code>operand</code>, as determined by calling the {@link java.lang.Object#equals} method on206 * the <b>examined</b> object.207 * 208 * <p>If the specified operand is <code>null</code> then the created matcher will only match if209 * the examined object's <code>equals</code> method returns <code>true</code> when passed a210 * <code>null</code> (which would be a violation of the <code>equals</code> contract), unless the211 * examined object itself is <code>null</code>, in which case the matcher will return a positive212 * match.</p>213 * 214 * <p>The created matcher provides a special behaviour when examining <code>Array</code>s, whereby215 * it will match if both the operand and the examined object are arrays of the same length and216 * contain items that are equal to each other (according to the above rules) <b>in the same217 * indexes</b>.</p> 218 * For example:219 * <pre>220 * assertThat("foo", equalTo("foo"));221 * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));222 * </pre>223 */224 public static <T> org.hamcrest.Matcher<T> equalTo(T operand) {225 return org.hamcrest.core.IsEqual.equalTo(operand);226 }227 /**228 * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being229 * compared to be of the same static type.230 */231 public static org.hamcrest.Matcher<java.lang.Object> equalToObject(java.lang.Object operand) {232 return org.hamcrest.core.IsEqual.equalToObject(operand);233 }234 /**235 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,236 * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the237 * the examined object.238 * 239 * <p>The created matcher forces a relationship between specified type and the examined object, and should be240 * used when it is necessary to make generics conform, for example in the JMock clause241 * <code>with(any(Thing.class))</code></p>242 * For example:243 * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre>244 */245 public static <T> org.hamcrest.Matcher<T> any(java.lang.Class<T> type) {246 return org.hamcrest.core.IsInstanceOf.any(type);247 }248 /**249 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,250 * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the251 * the examined object.252 * 253 * <p>The created matcher assumes no relationship between specified type and the examined object.</p>254 * For example:255 * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre>256 */257 public static <T> org.hamcrest.Matcher<T> instanceOf(java.lang.Class<?> type) {258 return org.hamcrest.core.IsInstanceOf.instanceOf(type);259 }260 /**261 * Creates a matcher that wraps an existing matcher, but inverts the logic by which262 * it will match.263 * For example:264 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>265 * 266 * @param matcher267 * the matcher whose sense should be inverted268 */269 public static <T> org.hamcrest.Matcher<T> not(org.hamcrest.Matcher<T> matcher) {270 return org.hamcrest.core.IsNot.not(matcher);271 }272 /**273 * A shortcut to the frequently used <code>not(equalTo(x))</code>.274 * For example:275 * <pre>assertThat(cheese, is(not(smelly)))</pre>276 * instead of:277 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>278 * 279 * @param value280 * the value that any examined object should <b>not</b> equal281 */282 public static <T> org.hamcrest.Matcher<T> not(T value) {283 return org.hamcrest.core.IsNot.not(value);284 }285 /**286 * A shortcut to the frequently used <code>not(nullValue())</code>.287 * For example:288 * <pre>assertThat(cheese, is(notNullValue()))</pre>289 * instead of:290 * <pre>assertThat(cheese, is(not(nullValue())))</pre>291 */292 public static org.hamcrest.Matcher<java.lang.Object> notNullValue() {293 return org.hamcrest.core.IsNull.notNullValue();294 }295 /**296 * A shortcut to the frequently used <code>not(nullValue(X.class)). Accepts a297 * single dummy argument to facilitate type inference.</code>.298 * For example:299 * <pre>assertThat(cheese, is(notNullValue(X.class)))</pre>300 * instead of:301 * <pre>assertThat(cheese, is(not(nullValue(X.class))))</pre>302 * 303 * @param type304 * dummy parameter used to infer the generic type of the returned matcher305 */306 public static <T> org.hamcrest.Matcher<T> notNullValue(java.lang.Class<T> type) {307 return org.hamcrest.core.IsNull.notNullValue(type);308 }309 /**310 * Creates a matcher that matches if examined object is <code>null</code>.311 * For example:312 * <pre>assertThat(cheese, is(nullValue())</pre>313 */314 public static org.hamcrest.Matcher<java.lang.Object> nullValue() {315 return org.hamcrest.core.IsNull.nullValue();316 }317 /**318 * Creates a matcher that matches if examined object is <code>null</code>. Accepts a319 * single dummy argument to facilitate type inference.320 * For example:321 * <pre>assertThat(cheese, is(nullValue(Cheese.class))</pre>322 * 323 * @param type324 * dummy parameter used to infer the generic type of the returned matcher325 */326 public static <T> org.hamcrest.Matcher<T> nullValue(java.lang.Class<T> type) {327 return org.hamcrest.core.IsNull.nullValue(type);328 }329 /**330 * Creates a matcher that matches only when the examined object is the same instance as331 * the specified target object.332 * 333 * @param target334 * the target instance against which others should be assessed335 */336 public static <T> org.hamcrest.Matcher<T> sameInstance(T target) {337 return org.hamcrest.core.IsSame.sameInstance(target);338 }339 /**340 * Creates a matcher that matches only when the examined object is the same instance as341 * the specified target object.342 * 343 * @param target344 * the target instance against which others should be assessed345 */346 public static <T> org.hamcrest.Matcher<T> theInstance(T target) {347 return org.hamcrest.core.IsSame.theInstance(target);348 }349 /**350 * Creates a matcher that matches if the examined {@link String} contains the specified351 * {@link String} anywhere.352 * For example:353 * <pre>assertThat("myStringOfNote", containsString("ring"))</pre>354 * 355 * @param substring356 * the substring that the returned matcher will expect to find within any examined string357 */358 public static org.hamcrest.Matcher<java.lang.String> containsString(java.lang.String substring) {359 return org.hamcrest.core.StringContains.containsString(substring);360 }361 /**...