How to use matches method of org.hamcrest.core.AnyOf class

Best junit code snippet using org.hamcrest.core.AnyOf.matches

Source:CauliAssert.java Github

copy

Full Screen

...9 public static <T> void assertThat(T actual, Matcher<? super T> matcher) {10 assertThat("", actual, matcher);11 }12 public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {13 if (!matcher.matches(actual)) {14 Description description = new StringDescription();15 description.appendText(reason)16 .appendText("\nExpected: ")17 .appendDescriptionOf(matcher)18 .appendText("\n but: ");19 matcher.describeMismatch(actual, description);20 throw new AssertionError(description.toString());21 }22 }23 public static void assertThat(String reason, boolean assertion) {24 if (!assertion) {25 throw new AssertionError(reason);26 }27 }28 public static <T> org.hamcrest.Matcher<T> allOf(Iterable<org.hamcrest.Matcher<? super T>> matchers) {29 return org.hamcrest.core.AllOf.<T>allOf(matchers);30 }31 /**32 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.33 * <p/>34 * For example:35 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>36 */37 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T>... matchers) {38 return org.hamcrest.core.AllOf.<T>allOf(matchers);39 }40 /**41 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.42 * <p/>43 * For example:44 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>45 */46 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second) {47 return org.hamcrest.core.AllOf.<T>allOf(first, second);48 }49 /**50 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.51 * <p/>52 * For example:53 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>54 */55 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third) {56 return org.hamcrest.core.AllOf.<T>allOf(first, second, third);57 }58 /**59 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.60 * <p/>61 * For example:62 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>63 */64 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth) {65 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth);66 }67 /**68 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.69 * <p/>70 * For example:71 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>72 */73 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth) {74 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth, fifth);75 }76 /**77 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.78 * <p/>79 * For example:80 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>81 */82 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth) {83 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth, fifth, sixth);84 }85 /**86 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.87 * <p/>88 * For example:89 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>90 */91 public static <T> org.hamcrest.core.AnyOf<T> anyOf(Iterable<org.hamcrest.Matcher<? super T>> matchers) {92 return org.hamcrest.core.AnyOf.<T>anyOf(matchers);93 }94 /**95 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.96 * <p/>97 * For example:98 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>99 */100 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third) {101 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third);102 }103 /**104 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.105 * <p/>106 * For example:107 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>108 */109 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth) {110 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth);111 }112 /**113 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.114 * <p/>115 * For example:116 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>117 */118 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth) {119 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth, fifth);120 }121 /**122 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.123 * <p/>124 * For example:125 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>126 */127 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth) {128 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth, fifth, sixth);129 }130 /**131 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.132 * <p/>133 * For example:134 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>135 */136 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second) {137 return org.hamcrest.core.AnyOf.<T>anyOf(first, second);138 }139 /**140 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.141 * <p/>142 * For example:143 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>144 */145 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<? super T>... matchers) {146 return org.hamcrest.core.AnyOf.<T>anyOf(matchers);147 }148 /**149 * Creates a matcher that matches when both of the specified matchers match the examined object.150 * <p/>151 * For example:152 * <pre>assertThat("fab", both(containsString("a")).and(containsString("b")))</pre>153 */154 public static <LHS> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<LHS> both(org.hamcrest.Matcher<? super LHS> matcher) {155 return org.hamcrest.core.CombinableMatcher.<LHS>both(matcher);156 }157 /**158 * Creates a matcher that matches when either of the specified matchers match the examined object.159 * <p/>160 * For example:161 * <pre>assertThat("fan", either(containsString("a")).and(containsString("b")))</pre>162 */163 public static <LHS> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<LHS> either(org.hamcrest.Matcher<? super LHS> matcher) {164 return org.hamcrest.core.CombinableMatcher.<LHS>either(matcher);165 }166 /**167 * Wraps an existing matcher, overriding its description with that specified. All other functions are168 * delegated to the decorated matcher, including its mismatch description.169 * <p/>170 * For example:171 * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre>172 *173 * @param description174 * the new description for the wrapped matcher175 * @param matcher176 * the matcher to wrap177 * @param values178 * optional values to insert into the tokenised description179 */180 public static <T> org.hamcrest.Matcher<T> describedAs(String description, org.hamcrest.Matcher<T> matcher, Object... values) {181 return org.hamcrest.core.DescribedAs.<T>describedAs(description, matcher, values);182 }183 /**184 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the185 * examined {@link Iterable} yields items that are all matched by the specified186 * <code>itemMatcher</code>.187 * <p/>188 * For example:189 * <pre>assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))</pre>190 *191 * @param itemMatcher192 * the matcher to apply to every item provided by the examined {@link Iterable}193 */194 public static <U> org.hamcrest.Matcher<Iterable<U>> everyItem(org.hamcrest.Matcher<U> itemMatcher) {195 return org.hamcrest.core.Every.<U>everyItem(itemMatcher);196 }197 /**198 * A shortcut to the frequently used <code>is(equalTo(x))</code>.199 * <p/>200 * For example:201 * <pre>assertThat(cheese, is(smelly))</pre>202 * instead of:203 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>204 */205 public static <T> org.hamcrest.Matcher<T> is(T value) {206 return org.hamcrest.core.Is.<T>is(value);207 }208 /**209 * Decorates another Matcher, retaining its behaviour, but allowing tests210 * to be slightly more expressive.211 * <p/>212 * For example:213 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>214 * instead of:215 * <pre>assertThat(cheese, equalTo(smelly))</pre>216 */217 public static <T> org.hamcrest.Matcher<T> is(org.hamcrest.Matcher<T> matcher) {218 return org.hamcrest.core.Is.<T>is(matcher);219 }220 /**221 * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.222 * <p/>223 * For example:224 * <pre>assertThat(cheese, is(Cheddar.class))</pre>225 * instead of:226 * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>227 *228 * @deprecated use isA(Class<T> type) instead.229 */230 public static <T> org.hamcrest.Matcher<T> is(Class<T> type) {231 return org.hamcrest.core.Is.<T>is(type);232 }233 /**234 * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.235 * <p/>236 * For example:237 * <pre>assertThat(cheese, isA(Cheddar.class))</pre>238 * instead of:239 * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>240 */241 public static <T> org.hamcrest.Matcher<T> isA(Class<T> type) {242 return org.hamcrest.core.Is.<T>isA(type);243 }244 /**245 * Creates a matcher that always matches, regardless of the examined object.246 */247 public static org.hamcrest.Matcher<Object> anything() {248 return org.hamcrest.core.IsAnything.anything();249 }250 /**251 * Creates a matcher that always matches, regardless of the examined object, but describes252 * itself with the specified {@link String}.253 *254 * @param description255 * a meaningful {@link String} used when describing itself256 */257 public static org.hamcrest.Matcher<Object> anything(String description) {258 return org.hamcrest.core.IsAnything.anything(description);259 }260 /**261 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the262 * examined {@link Iterable} yields at least one item that is equal to the specified263 * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable}264 * will stop as soon as a matching item is found.265 * <p/>266 * For example:267 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre>268 *269 * @param item270 * the item to compare against the items provided by the examined {@link Iterable}271 */272 public static <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(T item) {273 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item);274 }275 /**276 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the277 * examined {@link Iterable} yields at least one item that is matched by the specified278 * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable}279 * will stop as soon as a matching item is found.280 * <p/>281 * For example:282 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre>283 *284 * @param itemMatcher285 * the matcher to apply to items provided by the examined {@link Iterable}286 */287 public static <T> org.hamcrest.Matcher<Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) {288 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher);289 }290 /**291 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the292 * examined {@link Iterable} yield at least one item that is equal to the corresponding293 * item from the specified <code>items</code>. Whilst matching, each traversal of the294 * examined {@link Iterable} will stop as soon as a matching item is found.295 * <p/>296 * For example:297 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre>298 *299 * @param items300 * the items to compare against the items provided by the examined {@link Iterable}301 */302 public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(T... items) {303 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(items);304 }305 /**306 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the307 * examined {@link Iterable} yield at least one item that is matched by the corresponding308 * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of309 * the examined {@link Iterable} will stop as soon as a matching item is found.310 * <p/>311 * For example:312 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre>313 *314 * @param itemMatchers315 * the matchers to apply to items provided by the examined {@link Iterable}316 */317 public static <T> org.hamcrest.Matcher<Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) {318 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(itemMatchers);319 }320 /**321 * Creates a matcher that matches when the examined object is logically equal to the specified322 * <code>operand</code>, as determined by calling the {@link Object#equals} method on323 * the <b>examined</b> object.324 *325 * <p>If the specified operand is <code>null</code> then the created matcher will only match if326 * the examined object's <code>equals</code> method returns <code>true</code> when passed a327 * <code>null</code> (which would be a violation of the <code>equals</code> contract), unless the328 * examined object itself is <code>null</code>, in which case the matcher will return a positive329 * match.</p>330 *331 * <p>The created matcher provides a special behaviour when examining <code>Array</code>s, whereby332 * it will match if both the operand and the examined object are arrays of the same length and333 * contain items that are equal to each other (according to the above rules) <b>in the same334 * indexes</b>.</p>335 * <p/>336 * For example:337 * <pre>338 * assertThat("foo", equalTo("foo"));339 * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));340 * </pre>341 */342 public static <T> org.hamcrest.Matcher<T> equalTo(T operand) {343 return org.hamcrest.core.IsEqual.<T>equalTo(operand);344 }345 /**346 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,347 * as determined by calling the {@link Class#isInstance(Object)} method on that type, passing the348 * the examined object.349 *350 * <p>The created matcher forces a relationship between specified type and the examined object, and should be351 * used when it is necessary to make generics conform, for example in the JMock clause352 * <code>with(any(Thing.class))</code></p>353 * <p/>354 * For example:355 * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre>356 */357 public static <T> org.hamcrest.Matcher<T> any(Class<T> type) {358 return org.hamcrest.core.IsInstanceOf.<T>any(type);359 }360 /**361 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,362 * as determined by calling the {@link Class#isInstance(Object)} method on that type, passing the363 * the examined object.364 *365 * <p>The created matcher assumes no relationship between specified type and the examined object.</p>366 * <p/>367 * For example:368 * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre>369 */370 public static <T> org.hamcrest.Matcher<T> instanceOf(Class<?> type) {371 return org.hamcrest.core.IsInstanceOf.<T>instanceOf(type);372 }373 /**374 * Creates a matcher that wraps an existing matcher, but inverts the logic by which375 * it will match.376 * <p/>377 * For example:378 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>379 *380 * @param matcher381 * the matcher whose sense should be inverted382 */383 public static <T> org.hamcrest.Matcher<T> not(org.hamcrest.Matcher<T> matcher) {384 return org.hamcrest.core.IsNot.<T>not(matcher);385 }386 /**387 * A shortcut to the frequently used <code>not(equalTo(x))</code>.388 * <p/>389 * For example:390 * <pre>assertThat(cheese, is(not(smelly)))</pre>391 * instead of:392 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>393 *394 * @param value395 * the value that any examined object should <b>not</b> equal396 */397 public static <T> org.hamcrest.Matcher<T> not(T value) {398 return org.hamcrest.core.IsNot.<T>not(value);399 }400 /**401 * Creates a matcher that matches if examined object is <code>null</code>.402 * <p/>403 * For example:404 * <pre>assertThat(cheese, is(nullValue())</pre>405 */406 public static org.hamcrest.Matcher<Object> nullValue() {407 return org.hamcrest.core.IsNull.nullValue();408 }409 /**410 * Creates a matcher that matches if examined object is <code>null</code>. Accepts a411 * single dummy argument to facilitate type inference.412 * <p/>413 * For example:414 * <pre>assertThat(cheese, is(nullValue(Cheese.class))</pre>415 *416 * @param type417 * dummy parameter used to infer the generic type of the returned matcher418 */419 public static <T> org.hamcrest.Matcher<T> nullValue(Class<T> type) {420 return org.hamcrest.core.IsNull.<T>nullValue(type);421 }422 /**423 * A shortcut to the frequently used <code>not(nullValue())</code>.424 * <p/>425 * For example:426 * <pre>assertThat(cheese, is(notNullValue()))</pre>427 * instead of:428 * <pre>assertThat(cheese, is(not(nullValue())))</pre>429 */430 public static org.hamcrest.Matcher<Object> notNullValue() {431 return org.hamcrest.core.IsNull.notNullValue();432 }433 /**434 * A shortcut to the frequently used <code>not(nullValue(X.class)). Accepts a435 * single dummy argument to facilitate type inference.</code>.436 * <p/>437 * For example:438 * <pre>assertThat(cheese, is(notNullValue(X.class)))</pre>439 * instead of:440 * <pre>assertThat(cheese, is(not(nullValue(X.class))))</pre>441 *442 * @param type443 * dummy parameter used to infer the generic type of the returned matcher444 */445 public static <T> org.hamcrest.Matcher<T> notNullValue(Class<T> type) {446 return org.hamcrest.core.IsNull.<T>notNullValue(type);447 }448 /**449 * Creates a matcher that matches only when the examined object is the same instance as450 * the specified target object.451 *452 * @param target453 * the target instance against which others should be assessed454 */455 public static <T> org.hamcrest.Matcher<T> sameInstance(T target) {456 return org.hamcrest.core.IsSame.<T>sameInstance(target);457 }458 /**459 * Creates a matcher that matches only when the examined object is the same instance as460 * the specified target object.461 *462 * @param target463 * the target instance against which others should be assessed464 */465 public static <T> org.hamcrest.Matcher<T> theInstance(T target) {466 return org.hamcrest.core.IsSame.<T>theInstance(target);467 }468 /**469 * Creates a matcher that matches if the examined {@link String} contains the specified470 * {@link String} anywhere.471 * <p/>472 * For example:473 * <pre>assertThat("myStringOfNote", containsString("ring"))</pre>474 *475 * @param substring476 * the substring that the returned matcher will expect to find within any examined string477 */478 public static org.hamcrest.Matcher<String> containsString(String substring) {479 return org.hamcrest.core.StringContains.containsString(substring);480 }481 /**482 * Creates a matcher that matches if the examined {@link String} starts with the specified483 * {@link String}.484 * <p/>485 * For example:486 * <pre>assertThat("myStringOfNote", startsWith("my"))</pre>487 *488 * @param prefix489 * the substring that the returned matcher will expect at the start of any examined string490 */491 public static org.hamcrest.Matcher<String> startsWith(String prefix) {492 return org.hamcrest.core.StringStartsWith.startsWith(prefix);493 }494 /**495 * Creates a matcher that matches if the examined {@link String} ends with the specified496 * {@link String}.497 * <p/>498 * For example:499 * <pre>assertThat("myStringOfNote", endsWith("Note"))</pre>500 *501 * @param suffix502 * the substring that the returned matcher will expect at the end of any examined string503 */504 public static org.hamcrest.Matcher<String> endsWith(String suffix) {505 return org.hamcrest.core.StringEndsWith.endsWith(suffix);506 }507}...

Full Screen

Full Screen

Source:CoreMatchers.java Github

copy

Full Screen

1// Generated source.2package org.hamcrest;3public class CoreMatchers {4 /**5 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.6 * <p/>7 * For example:8 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>9 */10 public static <T> org.hamcrest.Matcher<T> allOf(java.lang.Iterable<org.hamcrest.Matcher<? super T>> matchers) {11 return org.hamcrest.core.AllOf.<T>allOf(matchers);12 }13 /**14 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.15 * <p/>16 * For example:17 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>18 */19 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T>... matchers) {20 return org.hamcrest.core.AllOf.<T>allOf(matchers);21 }22 /**23 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.24 * <p/>25 * For example:26 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>27 */28 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second) {29 return org.hamcrest.core.AllOf.<T>allOf(first, second);30 }31 /**32 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.33 * <p/>34 * For example:35 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>36 */37 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third) {38 return org.hamcrest.core.AllOf.<T>allOf(first, second, third);39 }40 /**41 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.42 * <p/>43 * For example:44 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>45 */46 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth) {47 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth);48 }49 /**50 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.51 * <p/>52 * For example:53 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>54 */55 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth) {56 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth, fifth);57 }58 /**59 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.60 * <p/>61 * For example:62 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>63 */64 public static <T> org.hamcrest.Matcher<T> allOf(org.hamcrest.Matcher<? super T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth) {65 return org.hamcrest.core.AllOf.<T>allOf(first, second, third, fourth, fifth, sixth);66 }67 /**68 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.69 * <p/>70 * For example:71 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>72 */73 public static <T> org.hamcrest.core.AnyOf<T> anyOf(java.lang.Iterable<org.hamcrest.Matcher<? super T>> matchers) {74 return org.hamcrest.core.AnyOf.<T>anyOf(matchers);75 }76 /**77 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.78 * <p/>79 * For example:80 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>81 */82 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third) {83 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third);84 }85 /**86 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.87 * <p/>88 * For example:89 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>90 */91 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth) {92 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth);93 }94 /**95 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.96 * <p/>97 * For example:98 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>99 */100 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth) {101 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth, fifth);102 }103 /**104 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.105 * <p/>106 * For example:107 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>108 */109 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second, org.hamcrest.Matcher<? super T> third, org.hamcrest.Matcher<? super T> fourth, org.hamcrest.Matcher<? super T> fifth, org.hamcrest.Matcher<? super T> sixth) {110 return org.hamcrest.core.AnyOf.<T>anyOf(first, second, third, fourth, fifth, sixth);111 }112 /**113 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.114 * <p/>115 * For example:116 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>117 */118 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<T> first, org.hamcrest.Matcher<? super T> second) {119 return org.hamcrest.core.AnyOf.<T>anyOf(first, second);120 }121 /**122 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.123 * <p/>124 * For example:125 * <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>126 */127 public static <T> org.hamcrest.core.AnyOf<T> anyOf(org.hamcrest.Matcher<? super T>... matchers) {128 return org.hamcrest.core.AnyOf.<T>anyOf(matchers);129 }130 /**131 * Creates a matcher that matches when both of the specified matchers match the examined object.132 * <p/>133 * For example:134 * <pre>assertThat("fab", both(containsString("a")).and(containsString("b")))</pre>135 */136 public static <LHS> org.hamcrest.core.CombinableMatcher.CombinableBothMatcher<LHS> both(org.hamcrest.Matcher<? super LHS> matcher) {137 return org.hamcrest.core.CombinableMatcher.<LHS>both(matcher);138 }139 /**140 * Creates a matcher that matches when either of the specified matchers match the examined object.141 * <p/>142 * For example:143 * <pre>assertThat("fan", either(containsString("a")).and(containsString("b")))</pre>144 */145 public static <LHS> org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher<LHS> either(org.hamcrest.Matcher<? super LHS> matcher) {146 return org.hamcrest.core.CombinableMatcher.<LHS>either(matcher);147 }148 /**149 * Wraps an existing matcher, overriding its description with that specified. All other functions are150 * delegated to the decorated matcher, including its mismatch description.151 * <p/>152 * For example:153 * <pre>describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())</pre>154 * 155 * @param description156 * the new description for the wrapped matcher157 * @param matcher158 * the matcher to wrap159 * @param values160 * optional values to insert into the tokenised description161 */162 public static <T> org.hamcrest.Matcher<T> describedAs(java.lang.String description, org.hamcrest.Matcher<T> matcher, java.lang.Object... values) {163 return org.hamcrest.core.DescribedAs.<T>describedAs(description, matcher, values);164 }165 /**166 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the167 * examined {@link Iterable} yields items that are all matched by the specified168 * <code>itemMatcher</code>.169 * <p/>170 * For example:171 * <pre>assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))</pre>172 * 173 * @param itemMatcher174 * the matcher to apply to every item provided by the examined {@link Iterable}175 */176 public static <U> org.hamcrest.Matcher<java.lang.Iterable<U>> everyItem(org.hamcrest.Matcher<U> itemMatcher) {177 return org.hamcrest.core.Every.<U>everyItem(itemMatcher);178 }179 /**180 * A shortcut to the frequently used <code>is(equalTo(x))</code>.181 * <p/>182 * For example:183 * <pre>assertThat(cheese, is(smelly))</pre>184 * instead of:185 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>186 */187 public static <T> org.hamcrest.Matcher<T> is(T value) {188 return org.hamcrest.core.Is.<T>is(value);189 }190 /**191 * Decorates another Matcher, retaining its behaviour, but allowing tests192 * to be slightly more expressive.193 * <p/>194 * For example:195 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>196 * instead of:197 * <pre>assertThat(cheese, equalTo(smelly))</pre>198 */199 public static <T> org.hamcrest.Matcher<T> is(org.hamcrest.Matcher<T> matcher) {200 return org.hamcrest.core.Is.<T>is(matcher);201 }202 /**203 * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.204 * <p/>205 * For example:206 * <pre>assertThat(cheese, is(Cheddar.class))</pre>207 * instead of:208 * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>209 * 210 * @deprecated use isA(Class<T> type) instead.211 */212 public static <T> org.hamcrest.Matcher<T> is(java.lang.Class<T> type) {213 return org.hamcrest.core.Is.<T>is(type);214 }215 /**216 * A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.217 * <p/>218 * For example:219 * <pre>assertThat(cheese, isA(Cheddar.class))</pre>220 * instead of:221 * <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>222 */223 public static <T> org.hamcrest.Matcher<T> isA(java.lang.Class<T> type) {224 return org.hamcrest.core.Is.<T>isA(type);225 }226 /**227 * Creates a matcher that always matches, regardless of the examined object.228 */229 public static org.hamcrest.Matcher<java.lang.Object> anything() {230 return org.hamcrest.core.IsAnything.anything();231 }232 /**233 * Creates a matcher that always matches, regardless of the examined object, but describes234 * itself with the specified {@link String}.235 * 236 * @param description237 * a meaningful {@link String} used when describing itself238 */239 public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String description) {240 return org.hamcrest.core.IsAnything.anything(description);241 }242 /**243 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the244 * examined {@link Iterable} yields at least one item that is equal to the specified245 * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable}246 * will stop as soon as a matching item is found.247 * <p/>248 * For example:249 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre>250 * 251 * @param item252 * the item to compare against the items provided by the examined {@link Iterable}253 */254 public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) {255 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item);256 }257 /**258 * Creates a matcher for {@link Iterable}s that only matches when a single pass over the259 * examined {@link Iterable} yields at least one item that is matched by the specified260 * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable}261 * will stop as soon as a matching item is found.262 * <p/>263 * For example:264 * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre>265 * 266 * @param itemMatcher267 * the matcher to apply to items provided by the examined {@link Iterable}268 */269 public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) {270 return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher);271 }272 /**273 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the274 * examined {@link Iterable} yield at least one item that is equal to the corresponding275 * item from the specified <code>items</code>. Whilst matching, each traversal of the276 * examined {@link Iterable} will stop as soon as a matching item is found.277 * <p/>278 * For example:279 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre>280 * 281 * @param items282 * the items to compare against the items provided by the examined {@link Iterable}283 */284 public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) {285 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(items);286 }287 /**288 * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the289 * examined {@link Iterable} yield at least one item that is matched by the corresponding290 * matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of291 * the examined {@link Iterable} will stop as soon as a matching item is found.292 * <p/>293 * For example:294 * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre>295 * 296 * @param itemMatchers297 * the matchers to apply to items provided by the examined {@link Iterable}298 */299 public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) {300 return org.hamcrest.core.IsCollectionContaining.<T>hasItems(itemMatchers);301 }302 /**303 * Creates a matcher that matches when the examined object is logically equal to the specified304 * <code>operand</code>, as determined by calling the {@link java.lang.Object#equals} method on305 * the <b>examined</b> object.306 * 307 * <p>If the specified operand is <code>null</code> then the created matcher will only match if308 * the examined object's <code>equals</code> method returns <code>true</code> when passed a309 * <code>null</code> (which would be a violation of the <code>equals</code> contract), unless the310 * examined object itself is <code>null</code>, in which case the matcher will return a positive311 * match.</p>312 * 313 * <p>The created matcher provides a special behaviour when examining <code>Array</code>s, whereby314 * it will match if both the operand and the examined object are arrays of the same length and315 * contain items that are equal to each other (according to the above rules) <b>in the same316 * indexes</b>.</p> 317 * <p/>318 * For example:319 * <pre>320 * assertThat("foo", equalTo("foo"));321 * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));322 * </pre>323 */324 public static <T> org.hamcrest.Matcher<T> equalTo(T operand) {325 return org.hamcrest.core.IsEqual.<T>equalTo(operand);326 }327 /**328 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,329 * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the330 * the examined object.331 * 332 * <p>The created matcher forces a relationship between specified type and the examined object, and should be333 * used when it is necessary to make generics conform, for example in the JMock clause334 * <code>with(any(Thing.class))</code></p>335 * <p/>336 * For example: 337 * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre>338 */339 public static <T> org.hamcrest.Matcher<T> any(java.lang.Class<T> type) {340 return org.hamcrest.core.IsInstanceOf.<T>any(type);341 }342 /**343 * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>,344 * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the345 * the examined object.346 * 347 * <p>The created matcher assumes no relationship between specified type and the examined object.</p>348 * <p/>349 * For example: 350 * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre>351 */352 public static <T> org.hamcrest.Matcher<T> instanceOf(java.lang.Class<?> type) {353 return org.hamcrest.core.IsInstanceOf.<T>instanceOf(type);354 }355 /**356 * Creates a matcher that wraps an existing matcher, but inverts the logic by which357 * it will match.358 * <p/>359 * For example:360 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>361 * 362 * @param matcher363 * the matcher whose sense should be inverted364 */365 public static <T> org.hamcrest.Matcher<T> not(org.hamcrest.Matcher<T> matcher) {366 return org.hamcrest.core.IsNot.<T>not(matcher);367 }368 /**369 * A shortcut to the frequently used <code>not(equalTo(x))</code>.370 * <p/>371 * For example:372 * <pre>assertThat(cheese, is(not(smelly)))</pre>373 * instead of:374 * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre>375 * 376 * @param value377 * the value that any examined object should <b>not</b> equal378 */379 public static <T> org.hamcrest.Matcher<T> not(T value) {380 return org.hamcrest.core.IsNot.<T>not(value);381 }382 /**383 * Creates a matcher that matches if examined object is <code>null</code>.384 * <p/>385 * For example:386 * <pre>assertThat(cheese, is(nullValue())</pre>387 */388 public static org.hamcrest.Matcher<java.lang.Object> nullValue() {389 return org.hamcrest.core.IsNull.nullValue();390 }391 /**392 * Creates a matcher that matches if examined object is <code>null</code>. Accepts a393 * single dummy argument to facilitate type inference.394 * <p/>395 * For example:396 * <pre>assertThat(cheese, is(nullValue(Cheese.class))</pre>397 * 398 * @param type399 * dummy parameter used to infer the generic type of the returned matcher400 */401 public static <T> org.hamcrest.Matcher<T> nullValue(java.lang.Class<T> type) {402 return org.hamcrest.core.IsNull.<T>nullValue(type);403 }404 /**405 * A shortcut to the frequently used <code>not(nullValue())</code>.406 * <p/>407 * For example:408 * <pre>assertThat(cheese, is(notNullValue()))</pre>409 * instead of:410 * <pre>assertThat(cheese, is(not(nullValue())))</pre>411 */412 public static org.hamcrest.Matcher<java.lang.Object> notNullValue() {413 return org.hamcrest.core.IsNull.notNullValue();414 }415 /**416 * A shortcut to the frequently used <code>not(nullValue(X.class)). Accepts a417 * single dummy argument to facilitate type inference.</code>.418 * <p/>419 * For example:420 * <pre>assertThat(cheese, is(notNullValue(X.class)))</pre>421 * instead of:422 * <pre>assertThat(cheese, is(not(nullValue(X.class))))</pre>423 * 424 * @param type425 * dummy parameter used to infer the generic type of the returned matcher426 */427 public static <T> org.hamcrest.Matcher<T> notNullValue(java.lang.Class<T> type) {428 return org.hamcrest.core.IsNull.<T>notNullValue(type);429 }430 /**431 * Creates a matcher that matches only when the examined object is the same instance as432 * the specified target object.433 * 434 * @param target435 * the target instance against which others should be assessed436 */437 public static <T> org.hamcrest.Matcher<T> sameInstance(T target) {438 return org.hamcrest.core.IsSame.<T>sameInstance(target);439 }440 /**441 * Creates a matcher that matches only when the examined object is the same instance as442 * the specified target object.443 * 444 * @param target445 * the target instance against which others should be assessed446 */447 public static <T> org.hamcrest.Matcher<T> theInstance(T target) {448 return org.hamcrest.core.IsSame.<T>theInstance(target);449 }450 /**451 * Creates a matcher that matches if the examined {@link String} contains the specified452 * {@link String} anywhere.453 * <p/>454 * For example:455 * <pre>assertThat("myStringOfNote", containsString("ring"))</pre>456 * 457 * @param substring458 * the substring that the returned matcher will expect to find within any examined string459 */460 public static org.hamcrest.Matcher<java.lang.String> containsString(java.lang.String substring) {461 return org.hamcrest.core.StringContains.containsString(substring);462 }463 /**464 * Creates a matcher that matches if the examined {@link String} starts with the specified465 * {@link String}.466 * <p/>467 * For example:468 * <pre>assertThat("myStringOfNote", startsWith("my"))</pre>469 * 470 * @param prefix471 * the substring that the returned matcher will expect at the start of any examined string472 */473 public static org.hamcrest.Matcher<java.lang.String> startsWith(java.lang.String prefix) {474 return org.hamcrest.core.StringStartsWith.startsWith(prefix);475 }476 /**477 * Creates a matcher that matches if the examined {@link String} ends with the specified478 * {@link String}.479 * <p/>480 * For example:481 * <pre>assertThat("myStringOfNote", endsWith("Note"))</pre>482 * 483 * @param suffix484 * the substring that the returned matcher will expect at the end of any examined string485 */486 public static org.hamcrest.Matcher<java.lang.String> endsWith(java.lang.String suffix) {487 return org.hamcrest.core.StringEndsWith.endsWith(suffix);488 }489}...

Full Screen

Full Screen

Source:AnyOfTest.java Github

copy

Full Screen

1package org.hamcrest.core;2import org.hamcrest.Matcher;3import org.junit.Test;4import static org.hamcrest.AbstractMatcherTest.*;5import static org.hamcrest.core.AnyOf.anyOf;6import static org.hamcrest.core.IsEqual.equalTo;7import static org.hamcrest.core.StringEndsWith.endsWith;8import static org.hamcrest.core.StringStartsWith.startsWith;9public final class AnyOfTest {10 @Test public void11 copesWithNullsAndUnknownTypes() {12 Matcher<String> matcher = anyOf(equalTo("irrelevant"), startsWith("irr"));13 14 assertNullSafe(matcher);15 assertUnknownTypeSafe(matcher);16 }17 @Test public void18 evaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() {19 Matcher<String> matcher = anyOf(startsWith("goo"), endsWith("ood"));20 21 assertMatches("didn't pass both sub-matchers", matcher, "good");22 assertMatches("didn't pass second sub-matcher", matcher, "mood");23 assertMatches("didn't pass first sub-matcher", matcher, "goon");24 assertDoesNotMatch("didn't fail both sub-matchers", matcher, "flan");25 }26 @Test public void27 evaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() {28 Matcher<String> matcher = anyOf(startsWith("g"), startsWith("go"), endsWith("d"), startsWith("go"), startsWith("goo"));29 30 assertMatches("didn't pass middle sub-matcher", matcher, "vlad");31 assertDoesNotMatch("didn't fail all sub-matchers", matcher, "flan");32 }33 @SuppressWarnings("unchecked")34 @Test public void35 supportsMixedTypes() {36 final Matcher<SampleSubClass> matcher = anyOf(37 equalTo(new SampleBaseClass("bad")),38 equalTo(new SampleBaseClass("good")),39 equalTo(new SampleSubClass("ugly")));40 41 assertMatches("didn't pass middle sub-matcher", matcher, new SampleSubClass("good"));42 }43 @Test public void44 hasAReadableDescription() {45 assertDescription("(\"good\" or \"bad\" or \"ugly\")",46 anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));47 }48}...

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1assertThat(1, anyOf(equalTo(1), equalTo(2), equalTo(3)));2assertThat(2, anyOf(equalTo(1), equalTo(2), equalTo(3)));3assertThat(3, anyOf(equalTo(1), equalTo(2), equalTo(3)));4assertThat(4, anyOf(equalTo(1), equalTo(2), equalTo(3)));5assertThat(5, anyOf(equalTo(1), equalTo(2), equalTo(3)));6assertThat(1, allOf(equalTo(1), equalTo(2), equalTo(3)));7assertThat(2, allOf(equalTo(1), equalTo(2), equalTo(3)));8assertThat(3, allOf(equalTo(1), equalTo(2), equalTo(3)));9assertThat(4, allOf(equalTo(1), equalTo(2), equalTo(3)));10assertThat(5, allOf(equalTo(1), equalTo(2), equalTo(3)));11assertThat(1, both(equalTo(1)).and(equalTo(2)));12assertThat(2, both(equalTo(1)).and(equalTo(2)));13assertThat(3, both(equalTo(1)).and(equalTo(2)));14assertThat(4, both(equalTo(1)).and(equalTo(2)));15assertThat(5, both(equalTo(1)).and(equalTo(2)));

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.AnyOf;2import org.hamcrest.core.IsEqual;3import org.hamcrest.core.IsNot;4import org.hamcrest.core.IsNull;5import org.junit.Test;6import static org.hamcrest.MatcherAssert.assertThat;7import static org.hamcrest.core.AnyOf.anyOf;8import static org.hamcrest.core.Is.is;9import static org.hamcrest.core.IsEqual.equalTo;10import static org.hamcrest.core.IsNot.not;11import static org.hamcrest.core.IsNull.nullValue;12public class AnyOfTest {13 public void anyOfTest() {14 String str1 = "test";15 String str2 = "demo";16 String str3 = "test";17 String str4 = null;18 assertThat(str1, anyOf(is(str2), is(str3)));19 assertThat(str1, anyOf(not(str2), is(str3)));20 assertThat(str1, anyOf(not(str2), not(str4)));21 assertThat(str1, anyOf(not(str2), not(str4), is(str3)));22 assertThat(str1, anyOf(not(str2), not(str4), is(str3), is(str1)));23 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1))));24 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1))));25 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue())));26 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue(), not(str4))));27 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue(), not(str4), not(str4))));28 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue(), not(str4), not(str4), not(str4))));29 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue(), not(str4), not(str4), not(str4), not(str4))));30 assertThat(str1, is(anyOf(not(str2), not(str4), is(str3), is(str1), equalTo(str1), nullValue

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat;2import static org.hamcrest.Matchers.anyOf;3import static org.hamcrest.Matchers.equalTo;4import static org.hamcrest.Matchers.is;5public class AnyOfTest {6 public void anyOfTest() {7 String str = "My name is John";8 assertThat(str, anyOf(is(equalTo("My name is John")), is(equalTo("My name is Mark"))));9 }10}

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.AnyOf2import spock.lang.Specification3class AnyOfSpec extends Specification {4 def "any of"() {5 def anyOf = new AnyOf([1, 2, 3])6 anyOf.matches(1)7 anyOf.matches(2)8 anyOf.matches(3)9 !anyOf.matches(4)10 }11}12assertThat("foo", anyOf(equalTo("foo"), equalTo("bar"), equalTo("baz")));13assertThat("foo", anyOf(equalTo("bar"), equalTo("foo"), equalTo("baz")));14assertThat("foo", anyOf(equalTo("bar"), equalTo("baz"), equalTo("foo")));15assertThat("foo", anyOf(equalTo("foo"), equalTo("bar"), equalTo("baz")));16assertThat("foo", anyOf(equalTo("bar"), equalTo("foo"), equalTo("baz")));17assertThat("foo", anyOf(equalTo("bar"), equalTo("baz"), equalTo("foo")));18assertThat("foo", anyOf(equalTo("foo"), equalTo("bar"), equalTo("baz")));19assertThat("foo", anyOf(equalTo("bar"), equalTo("foo"), equalTo("baz")));20assertThat("foo", anyOf(equalTo("bar"), equalTo("baz"), equalTo("foo")));21assertThat("foo", anyOf(equalTo("foo"), equalTo("bar"), equalTo("baz")));22assertThat("foo", anyOf(equalTo("bar"), equalTo("foo"), equalTo("baz")));23assertThat("foo", anyOf(equalTo("bar"), equalTo("baz"), equalTo("foo

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.AnyOf2import org.hamcrest.core.Is3import org.hamcrest.core.IsNot4def anyOf = new AnyOf([Is.is(1), IsNot.not(2), Is.is(3)])5import org.hamcrest.core.AllOf6import org.hamcrest.core.Is7import org.hamcrest.core.IsNot8def allOf = new AllOf([Is.is(1), IsNot.not(2), Is.is(3)])9import org.hamcrest.core.IsNot10import org.hamcrest.core.Is11def isNot = new IsNot([Is.is(1)])12import org.hamcrest.core.Is13import org.hamcrest.core.IsNot14def is = new Is([IsNot.not(1)])15import org.hamcrest.core.Is16import org.hamcrest.core.IsNot17def is = new Is([IsNot.not(1)])18import org.hamcrest.core.Is19import org.hamcrest.core.IsNot20def is = new Is([IsNot.not(1)])21import org.hamcrest.core.Is22import org.hamcrest.core.IsNot23def is = new Is([IsNot.not(1)])24import org.hamcrest.core.Is25import org.hamcrest.core.IsNot

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.AnyOf2import org.junit.Assert.assertThat3assertThat(4 AnyOf.anyOf(5import org.hamcrest.core.AnyOf6import org.junit.Assert.assertThat7assertThat(8 AnyOf.anyOf(9import org.hamcrest.core.AnyOf10import org.junit.Assert.assertThat11assertThat(12 AnyOf.anyOf(13import org.hamcrest.core.AnyOf14import org.junit.Assert.assertThat15assertThat(16 AnyOf.anyOf(17import org.hamcrest.core.AnyOf18import org.junit.Assert.assertThat19assertThat(20 AnyOf.anyOf(21import org.hamcrest.core.AnyOf22import org.junit.Assert.assertThat23assertThat(24 AnyOf.anyOf(25import org.hamcrest.core.AnyOf26import org.junit.Assert.assertThat27assertThat(28 AnyOf.anyOf(29import org.hamcrest.core.AnyOf30import org.junit.Assert.assertThat31assertThat(32 AnyOf.anyOf(33import org.hamcrest.core.AnyOf34import org.junit.Assert.assertThat35assertThat(36 AnyOf.anyOf(37import org.hamcrest.core.AnyOf38import org.junit.Assert.assertThat

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.AnyOf2import spock.lang.Specification3class AnyOfSpec extends Specification {4 def "anyOf"() {5 "abc" ==~ AnyOf.anyOf("a", "b", "c")6 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d")7 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e")8 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f")9 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g")10 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h")11 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i")12 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")13 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k")14 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l")15 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m")16 "abc" ==~ AnyOf.anyOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n")17 "abc" ==~ AnyOf.anyOf("a", "b", "c",

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in AnyOf

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful