Class StringAssert

java.lang.Object
cloud.opencode.base.test.assertion.StringAssert

public final class StringAssert extends Object
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 Details

    • assertThat

      public static StringAssert assertThat(String actual)
      Creates assertion for string. 为字符串创建断言。
      Parameters:
      actual - the actual string | 实际字符串
      Returns:
      the assertion | 断言
    • isNull

      public StringAssert isNull()
      Asserts that string is null. 断言字符串为null。
      Returns:
      this | 此对象
    • isNotNull

      public StringAssert isNotNull()
      Asserts that string is not null. 断言字符串不为null。
      Returns:
      this | 此对象
    • isEmpty

      public StringAssert isEmpty()
      Asserts that string is empty. 断言字符串为空。
      Returns:
      this | 此对象
    • isNotEmpty

      public StringAssert isNotEmpty()
      Asserts that string is not empty. 断言字符串不为空。
      Returns:
      this | 此对象
    • isBlank

      public StringAssert isBlank()
      Asserts that string is blank. 断言字符串为空白。
      Returns:
      this | 此对象
    • isNotBlank

      public StringAssert isNotBlank()
      Asserts that string is not blank. 断言字符串不为空白。
      Returns:
      this | 此对象
    • hasLength

      public StringAssert hasLength(int length)
      Asserts that string has specified length. 断言字符串有指定长度。
      Parameters:
      length - the expected length | 期望长度
      Returns:
      this | 此对象
    • hasLengthBetween

      public StringAssert hasLengthBetween(int min, int max)
      Asserts that string has length between. 断言字符串长度在范围内。
      Parameters:
      min - minimum length | 最小长度
      max - maximum length | 最大长度
      Returns:
      this | 此对象
    • isEqualTo

      public StringAssert isEqualTo(String expected)
      Asserts that string equals another. 断言字符串等于另一个。
      Parameters:
      expected - the expected string | 期望字符串
      Returns:
      this | 此对象
    • isEqualToIgnoringCase

      public StringAssert isEqualToIgnoringCase(String expected)
      Asserts that string equals another ignoring case. 断言字符串等于另一个(忽略大小写)。
      Parameters:
      expected - the expected string | 期望字符串
      Returns:
      this | 此对象
    • contains

      public StringAssert contains(String substring)
      Asserts that string contains substring. 断言字符串包含子字符串。
      Parameters:
      substring - the substring | 子字符串
      Returns:
      this | 此对象
    • doesNotContain

      public StringAssert doesNotContain(String substring)
      Asserts that string does not contain substring. 断言字符串不包含子字符串。
      Parameters:
      substring - the substring | 子字符串
      Returns:
      this | 此对象
    • startsWith

      public StringAssert startsWith(String prefix)
      Asserts that string starts with prefix. 断言字符串以前缀开始。
      Parameters:
      prefix - the prefix | 前缀
      Returns:
      this | 此对象
    • endsWith

      public StringAssert endsWith(String suffix)
      Asserts that string ends with suffix. 断言字符串以后缀结束。
      Parameters:
      suffix - the suffix | 后缀
      Returns:
      this | 此对象
    • matches

      public StringAssert matches(String regex)
      Asserts that string matches regex. 断言字符串匹配正则表达式。
      Parameters:
      regex - the regex | 正则表达式
      Returns:
      this | 此对象
    • matches

      public StringAssert matches(Pattern pattern)
      Asserts that string matches pattern. 断言字符串匹配模式。
      Parameters:
      pattern - the pattern | 模式
      Returns:
      this | 此对象
    • containsOnlyDigits

      public StringAssert containsOnlyDigits()
      Asserts that string contains only digits. 断言字符串只包含数字。
      Returns:
      this | 此对象
    • containsOnlyLetters

      public StringAssert containsOnlyLetters()
      Asserts that string contains only letters. 断言字符串只包含字母。
      Returns:
      this | 此对象
    • isUpperCase

      public StringAssert isUpperCase()
      Asserts that string is all uppercase. 断言字符串全部大写。
      Returns:
      this | 此对象
    • isLowerCase

      public StringAssert isLowerCase()
      Asserts that string is all lowercase. 断言字符串全部小写。
      Returns:
      this | 此对象
    • isEqualToIgnoringWhitespace

      public StringAssert isEqualToIgnoringWhitespace(String expected)
      Asserts that trimmed strings are equal. 断言去除空白后的字符串相等。
      Parameters:
      expected - the expected string | 期望字符串
      Returns:
      this | 此对象