Class StringAssert
java.lang.Object
cloud.opencode.base.test.assertion.StringAssert
String Assert - Fluent assertions for strings
字符串断言 - 字符串的流式断言
Provides comprehensive assertion methods for String types.
为String类型提供全面的断言方法。
Features | 主要功能:
- Empty, blank, length checks - 空、空白、长度检查
- Content checks (contains, startsWith, endsWith) - 内容检查(包含、前缀、后缀)
- Regex and pattern matching - 正则和模式匹配
- Case and character type checks - 大小写和字符类型检查
Usage Examples | 使用示例:
StringAssert.assertThat(str)
.isNotBlank()
.startsWith("Hello")
.endsWith("World")
.contains("lo Wo")
.hasLength(11);
Security | 安全性:
- Thread-safe: No (not designed for concurrent use) - 线程安全: 否(非设计用于并发使用)
- Null-safe: Yes (validates non-null string) - 空值安全: 是(验证非空字符串)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringAssertassertThat(String actual) Creates assertion for string.Asserts that string contains substring.Asserts that string contains only digits.Asserts that string contains only letters.doesNotContain(String substring) Asserts that string does not contain substring.Asserts that string ends with suffix.hasLength(int length) Asserts that string has specified length.hasLengthBetween(int min, int max) Asserts that string has length between.isBlank()Asserts that string is blank.isEmpty()Asserts that string is empty.Asserts that string equals another.isEqualToIgnoringCase(String expected) Asserts that string equals another ignoring case.isEqualToIgnoringWhitespace(String expected) Asserts that trimmed strings are equal.Asserts that string is all lowercase.Asserts that string is not blank.Asserts that string is not empty.Asserts that string is not null.isNull()Asserts that string is null.Asserts that string is all uppercase.Asserts that string matches regex.Asserts that string matches pattern.startsWith(String prefix) Asserts that string starts with prefix.
-
Method Details
-
assertThat
Creates assertion for string. 为字符串创建断言。- Parameters:
actual- the actual string | 实际字符串- Returns:
- the assertion | 断言
-
isNull
-
isNotNull
-
isEmpty
-
isNotEmpty
-
isBlank
-
isNotBlank
-
hasLength
Asserts that string has specified length. 断言字符串有指定长度。- Parameters:
length- the expected length | 期望长度- Returns:
- this | 此对象
-
hasLengthBetween
Asserts that string has length between. 断言字符串长度在范围内。- Parameters:
min- minimum length | 最小长度max- maximum length | 最大长度- Returns:
- this | 此对象
-
isEqualTo
Asserts that string equals another. 断言字符串等于另一个。- Parameters:
expected- the expected string | 期望字符串- Returns:
- this | 此对象
-
isEqualToIgnoringCase
Asserts that string equals another ignoring case. 断言字符串等于另一个(忽略大小写)。- Parameters:
expected- the expected string | 期望字符串- Returns:
- this | 此对象
-
contains
Asserts that string contains substring. 断言字符串包含子字符串。- Parameters:
substring- the substring | 子字符串- Returns:
- this | 此对象
-
doesNotContain
Asserts that string does not contain substring. 断言字符串不包含子字符串。- Parameters:
substring- the substring | 子字符串- Returns:
- this | 此对象
-
startsWith
Asserts that string starts with prefix. 断言字符串以前缀开始。- Parameters:
prefix- the prefix | 前缀- Returns:
- this | 此对象
-
endsWith
Asserts that string ends with suffix. 断言字符串以后缀结束。- Parameters:
suffix- the suffix | 后缀- Returns:
- this | 此对象
-
matches
Asserts that string matches regex. 断言字符串匹配正则表达式。- Parameters:
regex- the regex | 正则表达式- Returns:
- this | 此对象
-
matches
Asserts that string matches pattern. 断言字符串匹配模式。- Parameters:
pattern- the pattern | 模式- Returns:
- this | 此对象
-
containsOnlyDigits
Asserts that string contains only digits. 断言字符串只包含数字。- Returns:
- this | 此对象
-
containsOnlyLetters
Asserts that string contains only letters. 断言字符串只包含字母。- Returns:
- this | 此对象
-
isUpperCase
Asserts that string is all uppercase. 断言字符串全部大写。- Returns:
- this | 此对象
-
isLowerCase
Asserts that string is all lowercase. 断言字符串全部小写。- Returns:
- this | 此对象
-
isEqualToIgnoringWhitespace
Asserts that trimmed strings are equal. 断言去除空白后的字符串相等。- Parameters:
expected- the expected string | 期望字符串- Returns:
- this | 此对象
-