Class CollectionAssert<E>
java.lang.Object
cloud.opencode.base.test.assertion.CollectionAssert<E>
- Type Parameters:
E- the element type | 元素类型
Collection Assert - Fluent assertions for collections
集合断言 - 集合的流式断言
Provides comprehensive assertion methods for Collection types including List, Set, and other Collection implementations.
为Collection类型提供全面的断言方法,包括List、Set和其他Collection实现。
Features | 主要功能:
- Fluent assertion API for collections - 集合的流式断言API
- Size, containment, ordering checks - 大小、包含、排序检查
- Predicate-based matching (allMatch, anyMatch, noneMatch) - 基于谓词的匹配
- Duplicate detection - 重复检测
Usage Examples | 使用示例:
CollectionAssert.assertThat(list)
.isNotEmpty()
.hasSize(3)
.contains("apple")
.containsAll("apple", "banana")
.doesNotContain("cherry");
Security | 安全性:
- Thread-safe: No (not designed for concurrent use) - 线程安全: 否(非设计用于并发使用)
- Null-safe: Yes (validates non-null collection) - 空值安全: 是(验证非空集合)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAsserts that collection contains only elements matching predicate.Asserts that collection contains any element matching predicate.static <E> CollectionAssert<E> assertThat(Collection<E> actual) Creates assertion for collection.Asserts that collection contains element.final CollectionAssert<E> containsAll(E... elements) Asserts that collection contains all elements.final CollectionAssert<E> containsExactly(E... elements) Asserts that collection contains exactly the given elements.final CollectionAssert<E> containsExactlyInAnyOrder(E... elements) Asserts that collection contains exactly the given elements in any order.doesNotContain(E element) Asserts that collection does not contain element.Asserts that collection has no duplicates.hasSize(int expectedSize) Asserts that collection has specified size.hasSizeGreaterThan(int size) Asserts that collection has size greater than.hasSizeLessThan(int size) Asserts that collection has size less than.isEmpty()Asserts that collection is empty.isEqualTo(Collection<E> expected) Asserts that collection equals another.Asserts that collection is not empty.Asserts that collection is not null.isNull()Asserts that collection is null.isSorted(Comparator<E> comparator) Asserts that collection is sorted.Asserts that collection contains no element matching predicate.
-
Method Details
-
assertThat
Creates assertion for collection. 为集合创建断言。- Type Parameters:
E- the element type | 元素类型- Parameters:
actual- the actual collection | 实际集合- Returns:
- the assertion | 断言
-
isNull
-
isNotNull
Asserts that collection is not null. 断言集合不为null。- Returns:
- this | 此对象
-
isEmpty
-
isNotEmpty
Asserts that collection is not empty. 断言集合不为空。- Returns:
- this | 此对象
-
hasSize
Asserts that collection has specified size. 断言集合有指定大小。- Parameters:
expectedSize- the expected size | 期望大小- Returns:
- this | 此对象
-
hasSizeGreaterThan
Asserts that collection has size greater than. 断言集合大小大于。- Parameters:
size- the size | 大小- Returns:
- this | 此对象
-
hasSizeLessThan
Asserts that collection has size less than. 断言集合大小小于。- Parameters:
size- the size | 大小- Returns:
- this | 此对象
-
contains
Asserts that collection contains element. 断言集合包含元素。- Parameters:
element- the element | 元素- Returns:
- this | 此对象
-
doesNotContain
Asserts that collection does not contain element. 断言集合不包含元素。- Parameters:
element- the element | 元素- Returns:
- this | 此对象
-
containsAll
Asserts that collection contains all elements. 断言集合包含所有元素。- Parameters:
elements- the elements | 元素- Returns:
- this | 此对象
-
containsExactly
Asserts that collection contains exactly the given elements. 断言集合恰好包含给定元素。- Parameters:
elements- the elements | 元素- Returns:
- this | 此对象
-
containsExactlyInAnyOrder
Asserts that collection contains exactly the given elements in any order. 断言集合恰好包含给定元素(任意顺序)。- Parameters:
elements- the elements | 元素- Returns:
- this | 此对象
-
allMatch
Asserts that collection contains only elements matching predicate. 断言集合只包含匹配谓词的元素。- Parameters:
predicate- the predicate | 谓词- Returns:
- this | 此对象
-
anyMatch
Asserts that collection contains any element matching predicate. 断言集合包含任何匹配谓词的元素。- Parameters:
predicate- the predicate | 谓词- Returns:
- this | 此对象
-
noneMatch
Asserts that collection contains no element matching predicate. 断言集合不包含匹配谓词的元素。- Parameters:
predicate- the predicate | 谓词- Returns:
- this | 此对象
-
hasNoDuplicates
Asserts that collection has no duplicates. 断言集合没有重复元素。- Returns:
- this | 此对象
-
isSorted
Asserts that collection is sorted. 断言集合已排序。- Parameters:
comparator- the comparator | 比较器- Returns:
- this | 此对象
-
isEqualTo
Asserts that collection equals another. 断言集合等于另一个。- Parameters:
expected- the expected collection | 期望集合- Returns:
- this | 此对象
-