|
14 | 14 | import java.util.Map;
|
15 | 15 | import java.util.Objects;
|
16 | 16 | import java.util.Set;
|
| 17 | +import java.util.function.Predicate; |
17 | 18 | import java.util.stream.Collectors;
|
18 | 19 | import java.util.stream.StreamSupport;
|
19 | 20 | import org.testng.collections.Lists;
|
@@ -2455,4 +2456,58 @@ public static <T extends Throwable> T expectThrows(
|
2455 | 2456 | "Expected %s to be thrown, but nothing was thrown", throwableClass.getSimpleName());
|
2456 | 2457 | throw new AssertionError(message != null ? message : nothingThrownMessage);
|
2457 | 2458 | }
|
| 2459 | + |
| 2460 | + /** |
| 2461 | + * Asserts that List contains object. Uses java.util.List#contains method, be sure that equals and |
| 2462 | + * hashCode of tested object are overridden. |
| 2463 | + * |
| 2464 | + * @param list the list to search in |
| 2465 | + * @param object the object to search in list |
| 2466 | + * @param message the fail message |
| 2467 | + * @param <T> type of object |
| 2468 | + */ |
| 2469 | + public static <T> void assertListContainsObject(List<T> list, T object, String message) { |
| 2470 | + assertTrue(list.contains(object), "List NOT contains: [" + message + "]"); |
| 2471 | + } |
| 2472 | + |
| 2473 | + /** |
| 2474 | + * Asserts that List not contains object. Opposite to assertListContainsObject() Uses |
| 2475 | + * java.util.List#contains method, be sure that equals and hashCode of tested object are |
| 2476 | + * overridden. |
| 2477 | + * |
| 2478 | + * @param list the list to search in |
| 2479 | + * @param object to search in list |
| 2480 | + * @param message the fail message |
| 2481 | + * @param <T> type of object |
| 2482 | + */ |
| 2483 | + public static <T> void assertListNotContainsObject(List<T> list, T object, String message) { |
| 2484 | + assertFalse(list.contains(object), "List contains: [" + message + "]"); |
| 2485 | + } |
| 2486 | + |
| 2487 | + /** |
| 2488 | + * Asserts that List contains object by specific Predicate. Uses |
| 2489 | + * java.util.stream.Stream#anyMatch(java.util.function.Predicate) method. |
| 2490 | + * |
| 2491 | + * @param list the list to search in |
| 2492 | + * @param predicate the Predicate to match object |
| 2493 | + * @param message the fail message |
| 2494 | + * @param <T> type of object |
| 2495 | + */ |
| 2496 | + public static <T> void assertListContains(List<T> list, Predicate<T> predicate, String message) { |
| 2497 | + assertTrue(list.stream().anyMatch(predicate), "List NOT contains: [" + message + "]"); |
| 2498 | + } |
| 2499 | + |
| 2500 | + /** |
| 2501 | + * Asserts that List not contains object by specific Predicate. Opposite to assertListContains() |
| 2502 | + * method. Uses java.util.stream.Stream#noneMatch(java.util.function.Predicate) method. |
| 2503 | + * |
| 2504 | + * @param list the list to search in |
| 2505 | + * @param predicate the Predicate to match object |
| 2506 | + * @param message the fail message |
| 2507 | + * @param <T> type of object |
| 2508 | + */ |
| 2509 | + public static <T> void assertListNotContains( |
| 2510 | + List<T> list, Predicate<T> predicate, String message) { |
| 2511 | + assertTrue(list.stream().noneMatch(predicate), "List contains: [" + message + "]"); |
| 2512 | + } |
2458 | 2513 | }
|
0 commit comments