Class MapAssert<K,V>

java.lang.Object
cloud.opencode.base.test.assertion.MapAssert<K,V>
Type Parameters:
K - the key type | 键类型
V - the value type | 值类型

public final class MapAssert<K,V> extends Object
Map Assert - Fluent assertions for Map instances Map断言 - Map实例的流式断言

Provides comprehensive assertion methods for Map types including size checks, key/value containment, and predicate-based matching.

Map 类型提供全面的断言方法,包括大小检查、键/值包含和基于谓词的匹配。

Features | 主要功能:

  • Fluent assertion API for maps - Map的流式断言API
  • Size, key, value containment checks - 大小、键、值包含检查
  • Key-value pair assertions - 键值对断言
  • Predicate-based matching (allKeysMatch, allValuesMatch) - 基于谓词的匹配

Usage Examples | 使用示例:

MapAssert.assertThat(map)
    .isNotEmpty()
    .hasSize(3)
    .containsKey("name")
    .containsEntry("age", 30)
    .doesNotContainKey("password");

Security | 安全性:

  • Thread-safe: No (not designed for concurrent use) - 线程安全: 否(非设计用于并发使用)
  • Null-safe: Yes (validates non-null map) - 空值安全: 是(验证非空Map)
Since:
JDK 25, opencode-base-test V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • assertThat

      public static <K,V> MapAssert<K,V> assertThat(Map<K,V> actual)
      Creates assertion for a map. 为Map创建断言。
      Type Parameters:
      K - the key type | 键类型
      V - the value type | 值类型
      Parameters:
      actual - the actual map | 实际Map
      Returns:
      the assertion | 断言
    • isNull

      public MapAssert<K,V> isNull()
      Asserts that the map is null. 断言Map为null。
      Returns:
      this | 此对象
    • isNotNull

      public MapAssert<K,V> isNotNull()
      Asserts that the map is not null. 断言Map不为null。
      Returns:
      this | 此对象
    • isEmpty

      public MapAssert<K,V> isEmpty()
      Asserts that the map is empty. 断言Map为空。
      Returns:
      this | 此对象
    • isNotEmpty

      public MapAssert<K,V> isNotEmpty()
      Asserts that the map is not empty. 断言Map不为空。
      Returns:
      this | 此对象
    • hasSize

      public MapAssert<K,V> hasSize(int expectedSize)
      Asserts that the map has the specified size. 断言Map具有指定大小。
      Parameters:
      expectedSize - the expected size | 期望大小
      Returns:
      this | 此对象
    • hasSizeGreaterThan

      public MapAssert<K,V> hasSizeGreaterThan(int size)
      Asserts that the map has size greater than the specified value. 断言Map大小大于指定值。
      Parameters:
      size - the size | 大小
      Returns:
      this | 此对象
    • hasSizeLessThan

      public MapAssert<K,V> hasSizeLessThan(int size)
      Asserts that the map has size less than the specified value. 断言Map大小小于指定值。
      Parameters:
      size - the size | 大小
      Returns:
      this | 此对象
    • containsKey

      public MapAssert<K,V> containsKey(K key)
      Asserts that the map contains the specified key. 断言Map包含指定键。
      Parameters:
      key - the key | 键
      Returns:
      this | 此对象
    • doesNotContainKey

      public MapAssert<K,V> doesNotContainKey(K key)
      Asserts that the map does not contain the specified key. 断言Map不包含指定键。
      Parameters:
      key - the key | 键
      Returns:
      this | 此对象
    • containsValue

      public MapAssert<K,V> containsValue(V value)
      Asserts that the map contains the specified value. 断言Map包含指定值。
      Parameters:
      value - the value | 值
      Returns:
      this | 此对象
    • doesNotContainValue

      public MapAssert<K,V> doesNotContainValue(V value)
      Asserts that the map does not contain the specified value. 断言Map不包含指定值。
      Parameters:
      value - the value | 值
      Returns:
      this | 此对象
    • containsEntry

      public MapAssert<K,V> containsEntry(K key, V value)
      Asserts that the map contains the specified key-value entry. 断言Map包含指定的键值对。
      Parameters:
      key - the key | 键
      value - the value | 值
      Returns:
      this | 此对象
    • doesNotContainEntry

      public MapAssert<K,V> doesNotContainEntry(K key, V value)
      Asserts that the map does not contain the specified key-value entry. 断言Map不包含指定的键值对。
      Parameters:
      key - the key | 键
      value - the value | 值
      Returns:
      this | 此对象
    • containsKeys

      @SafeVarargs public final MapAssert<K,V> containsKeys(K... keys)
      Asserts that the map contains all specified keys. 断言Map包含所有指定键。
      Parameters:
      keys - the keys | 键
      Returns:
      this | 此对象
    • allKeysMatch

      public MapAssert<K,V> allKeysMatch(Predicate<K> predicate)
      Asserts that all keys match the given predicate. 断言所有键匹配给定谓词。
      Parameters:
      predicate - the predicate | 谓词
      Returns:
      this | 此对象
    • allValuesMatch

      public MapAssert<K,V> allValuesMatch(Predicate<V> predicate)
      Asserts that all values match the given predicate. 断言所有值匹配给定谓词。
      Parameters:
      predicate - the predicate | 谓词
      Returns:
      this | 此对象
    • isEqualTo

      public MapAssert<K,V> isEqualTo(Map<K,V> expected)
      Asserts that the map equals the expected map. 断言Map等于期望的Map。
      Parameters:
      expected - the expected map | 期望Map
      Returns:
      this | 此对象