Class BctAssertions

java.lang.Object
org.apache.juneau.junit.bct.BctAssertions

public class BctAssertions extends Object
Comprehensive utility class for Bean-Centric Tests (BCT) and general testing operations.

This class extends the functionality provided by the JUnit Assertions class, with particular emphasis on the Bean-Centric Testing (BCT) framework. BCT enables sophisticated assertion patterns for testing object properties, collections, maps, and complex nested structures with minimal code.

Bean-Centric Testing (BCT) Framework:

The BCT framework consists of several key components:

  • BeanConverter: Core interface for object conversion and property access
  • BasicBeanConverter: Default implementation with extensible type handlers
  • Assertion Methods: High-level testing methods that leverage the converter framework
Primary BCT Assertion Methods:
assertBean(Object, String, String)
Tests object properties with nested syntax support and collection iteration
assertBeans(Collection, String, String...)
Tests collections of objects by extracting and comparing specific fields
assertMapped(Object, java.util.function.BiFunction, String, String)
Tests custom property access using BiFunction for non-standard objects
assertList(List, Object...)
Tests list/collection elements with varargs for expected values
BCT Advanced Features:
  • Nested Property Syntax: "address{street,city}" for testing nested objects
  • Collection Iteration: "#{address{street,city}}" syntax for testing all elements
  • Universal Size Properties: "length" and "size" work on all collection types
  • Array/List Access: Numeric indices for element-specific testing
  • Method Chaining: Fluent setters can be tested directly
  • Direct Field Access: Public fields accessed without getters
  • Map Key Access: Including special "<null>" syntax for null keys
Converter Extensibility:

The BCT framework is built on the extensible BasicBeanConverter which allows:

  • Custom Stringifiers: Type-specific string conversion logic
  • Custom Listifiers: Collection-type conversion for iteration
  • Custom Swappers: Object transformation before conversion
  • Custom PropertyExtractors: Property extraction
  • Configurable Settings: Formatting, delimiters, and display options
Usage Examples:

Basic Property Testing:

// Test multiple properties assertBean(user, "name,age,active", "John,30,true"); // Test nested properties - user has getAddress() returning Address with getStreet() and getCity() assertBean(user, "name,address{street,city}", "John,{123 Main St,Springfield}");

Collection and Array Testing:

// Test collection size and iterate over all elements - order has getItems() returning List<Product> where Product has getName() assertBean(order, "items{length,#{name}}", "{3,[{Laptop},{Phone},{Tablet}]}"); // Test specific array elements - listOfData is a List<DataObject> where DataObject has getData() assertBean(listOfData, "0{data},1{data}", "{100},{200}");

Collection Testing:

// Test list elements assertList(tags, "red", "green", "blue"); // Test map entries using assertBean assertBean(config, "timeout,retries", "30000,3");

Custom Property Access:

// Test with custom accessor function assertMapped(myObject, (obj, prop) -> obj.getProperty(prop), "prop1,prop2", "value1,value2");

Performance and Thread Safety:

The BCT framework is designed for high performance with:

  • Caching: Type-to-handler mappings cached for fast lookup
  • Thread Safety: All operations are thread-safe for concurrent testing
  • Minimal Allocation: Efficient object reuse and minimal temporary objects
See Also:
  • Method Details

    • args

      public static AssertionArgs args()
      Creates a new AssertionArgs instance for configuring assertion behavior.

      AssertionArgs provides fluent configuration for customizing assertion behavior, including:

      • Custom Messages: Static strings, parameterized with MessageFormat, or dynamic suppliers
      • Custom Bean Converters: Override default object-to-string conversion behavior
      • Timeout Configuration: Set timeouts for operations that may take time
      Usage Examples:

      // Static message assertBean(args().setMessage("User validation failed"), user, "name,age", "John,30"); // Parameterized message assertBean(args().setMessage("Test failed for user {0}", userId), user, "status", "ACTIVE"); // Dynamic message with supplier assertBean(args().setMessage(() -> "Test failed at " + Instant.now()), result, "success", "true"); // Custom bean converter var converter = BasicBeanConverter.builder() .defaultSettings() .addStringifier(LocalDate.class, date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)) .build(); assertBean(args().setBeanConverter(converter), event, "date", "2023-12-01");

      Returns:
      A new AssertionArgs instance for fluent configuration
      See Also:
    • assertBean

      public static void assertBean(Object actual, String fields, String expected)
      Asserts that the fields/properties on the specified bean are the specified values after being converted to strings.

      This is the primary method for Bean-Centric Tests (BCT), supporting extensive property validation patterns including nested objects, collections, arrays, method chaining, direct field access, collection iteration with "#{property}" syntax, and universal "length"/"size" properties for all collection types.

      The method uses the BasicBeanConverter.DEFAULT converter internally for object introspection and value extraction. The converter provides sophisticated property access through the BeanConverter interface, supporting multiple fallback mechanisms for accessing object properties and values.

      Basic Usage:

      // Test multiple properties assertBean(myBean, "prop1,prop2,prop3", "val1,val2,val3"); // Test single property assertBean(myBean, "name", "John");

      Nested Property Testing:

      // Test nested bean properties assertBean(myBean, "name,address{street,city,state}", "John,{123 Main St,Springfield,IL}"); // Test arbitrarily deep nesting assertBean(myBean, "name,person{address{geo{lat,lon}}}", "John,{{{40.7,-74.0}}}");

      Array, List, and Stream Testing:

      // Test array/list elements by index - items is a String[] or List<String> assertBean(myBean, "items{0,1,2}", "{item1,item2,item3}"); // Test nested properties within array elements - orders is a List<Order> where Order has getId() and getTotal() assertBean(myBean, "orders{0{id,total}}", "{{123,99.95}}"); // Test array length property - items can be any array or collection type assertBean(myBean, "items{length}", "{5}"); // Works with any iterable type including Streams - userStream returns a Stream<User> where User has getName() assertBean(myBean, "userStream{#{name}}", "[{Alice},{Bob}]");

      Collection Iteration Syntax:

      // Test properties across ALL elements in a collection using #{...} syntax - userList is a List<User> where User has getName() assertBean(myBean, "userList{#{name}}", "[{John},{Jane},{Bob}]"); // Test multiple properties from each element - orderList is a List<Order> where Order has getId() and getStatus() assertBean(myBean, "orderList{#{id,status}}", "[{123,ACTIVE},{124,PENDING}]"); // Works with nested properties within each element - customers is a List<Customer> where Customer has getAddress() returning Address with getCity() assertBean(myBean, "customers{#{address{city}}}", "[{{New York}},{{Los Angeles}}]"); // Works with arrays and any iterable collection type (including Streams) assertBean(config, "itemArray{#{type}}", "[{String},{Integer},{Boolean}]"); assertBean(data, "statusSet{#{name}}", "[{ACTIVE},{PENDING},{CANCELLED}]"); assertBean(processor, "dataStream{#{value}}", "[{A},{B},{C}]");

      Universal Collection Size Properties:

      // Both 'length' and 'size' work universally across all collection types assertBean(myBean, "myArray{length}", "{5}"); // Arrays assertBean(myBean, "myArray{size}", "{5}"); // Also works for arrays assertBean(myBean, "myList{size}", "{3}"); // Collections assertBean(myBean, "myList{length}", "{3}"); // Also works for collections assertBean(myBean, "myMap{size}", "{7}"); // Maps assertBean(myBean, "myMap{length}", "{7}"); // Also works for maps

      Class Name Testing:

      // Test class properties (prefer simple names for maintainability) assertBean(myBean, "obj{class{simpleName}}", "{{MyClass}}"); // Test full class names when needed assertBean(myBean, "obj{class{name}}", "{{com.example.MyClass}}");

      Method Chaining Support:

      // Test fluent setter chains (returns same object) assertBean( item.setType("foo").setFormat("bar").setDefault("baz"), "type,format,default", "foo,bar,baz" );

      Advanced Collection Analysis:

      // Combine size/length, metadata, and content iteration in single assertions - users is a List<User> assertBean(myBean, "users{length,class{simpleName},#{name}}", "{3,{ArrayList},[{John},{Jane},{Bob}]}"); // Comprehensive collection validation with multiple iteration patterns - items is a List<Product> where Product has getName() and getPrice() assertBean(order, "items{size,#{name},#{price}}", "{3,[{Laptop},{Phone},{Tablet}],[{999.99},{599.99},{399.99}]}"); // Perfect for validation testing - verify error count and details; errors is a List<ValidationError> where ValidationError has getField() and getCode() assertBean(result, "errors{length,#{field},#{code}}", "{2,[{email},{password}],[{E001},{E002}]}"); // Mixed collection types with consistent syntax - results and metadata are different collection types assertBean(response, "results{size},metadata{length}", "{25},{4}");

      Direct Field Access:

      // Test public fields directly (no getters required) assertBean(myBean, "f1,f2,f3", "val1,val2,val3"); // Test field properties with chaining assertBean(myBean, "f1{length},f2{class{simpleName}}", "{5},{{String}}");

      Map Testing:

      // Test map values by key assertBean(myBean, "configMap{timeout,retries}", "{30000,3}"); // Test map size assertBean(myBean, "settings{size}", "{5}"); // Test null keys using special <null> syntax assertBean(myBean, "mapWithNullKey{<null>}", "{nullKeyValue}");

      Collection and Boolean Values:

      // Test boolean values assertBean(myBean, "enabled,visible", "true,false"); // Test enum collections assertBean(myBean, "statuses", "[ACTIVE,PENDING]");

      Value Syntax Rules:
      • Simple values: "value" for direct property values
      • Nested values: "{value}" for single-level nested properties
      • Deep nested values: "{{value}}", "{{{value}}}" for multiple nesting levels
      • Array/Collection values: "[item1,item2]" for collections
      • Collection iteration: "#{property}" iterates over ALL collection elements, returns "[{val1},{val2}]"
      • Universal size properties: "length" and "size" work on arrays, collections, and maps
      • Boolean values: "true", "false"
      • Null values: "null"
      Property Access Priority:
      1. Collection/Array access: Numeric indices for arrays/lists (e.g., "0", "1")
      2. Universal size properties: "length" and "size" for arrays, collections, and maps
      3. Map key access: Direct key lookup for Map objects (including "<null>" for null keys)
      4. is{Property}() methods (for boolean properties)
      5. get{Property}() methods
      6. Public fields (direct field access)
      Parameters:
      actual - The bean object to test. Must not be null.
      fields - Comma-delimited list of property names to test. Supports nested syntax with {}.
      expected - Comma-delimited list of expected values. Must match the order of fields.
      Throws:
      NullPointerException - if the bean is null
      AssertionError - if any property values don't match expected values
      See Also:
    • assertBean

      public static void assertBean(AssertionArgs args, Object actual, String fields, String expected)
      Same as assertBean(Object, String, String) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The bean to test. Must not be null.
      fields - A comma-delimited list of bean property names (supports nested syntax).
      expected - The expected property values as a comma-delimited string.
      See Also:
    • assertBeans

      public static void assertBeans(Object actual, String fields, String... expected)
      Asserts that multiple beans in a collection have the expected property values.

      This method validates that each bean in a collection has the specified property values, using the same property access logic as assertBean(Object, String, String). It's perfect for testing collections of similar objects or validation results.

      Basic Usage:

      // Test list of user beans assertBeans(userList, "name,age", "John,25", "Jane,30", "Bob,35");

      Complex Property Testing:

      // Test nested properties across multiple beans - orderList is a List<Order> where Order has getId() and getCustomer() returning Customer with getName() and getEmail() assertBeans(orderList, "id,customer{name,email}", "1,{John,john@example.com}", "2,{Jane,jane@example.com}"); // Test collection properties within beans - cartList is a List<ShoppingCart> where ShoppingCart has getItems() returning List<Product> and getTotal() assertBeans(cartList, "items{0{name}},total", "{{Laptop}},999.99", "{{Phone}},599.99");

      Validation Testing:

      // Test validation results assertBeans(validationErrors, "field,message,code", "email,Invalid email format,E001", "age,Must be 18 or older,E002");

      Collection Iteration Testing:

      // Test collection iteration within beans (#{...} syntax) assertBeans(departmentList, "name,employees{#{name}}", "Engineering,[{Alice},{Bob},{Charlie}]", "Marketing,[{David},{Eve}]");

      Parser Result Testing:

      // Test parsed object collections var parsed = JsonParser.DEFAULT.parse(jsonArray, MyBean[].class); assertBeans(Arrays.asList(parsed), "prop1,prop2", "val1,val2", "val3,val4");

      Parameters:
      actual - The collection of beans to check. Must not be null.
      fields - A comma-delimited list of bean property names (supports nested syntax).
      expected - Array of expected value strings, one per bean. Each string contains comma-delimited values matching the fields.
      Throws:
      AssertionError - if the collection size doesn't match values array length or if any bean properties don't match
      See Also:
    • assertBeans

      public static void assertBeans(AssertionArgs args, Object actual, String fields, String... expected)
      Same as assertBeans(Object, String, String...) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The collection of beans to test. Must not be null.
      fields - A comma-delimited list of bean property names (supports nested syntax).
      expected - Array of expected value strings, one per bean.
      See Also:
    • assertMapped

      public static <T> void assertMapped(T actual, BiFunction<T,String,Object> function, String properties, String expected)
      Asserts that mapped property access on an object returns expected values using a custom BiFunction.

      This is designed for testing objects that don't follow standard JavaBean patterns or require custom property access logic. The BiFunction allows complete control over how properties are retrieved from the target object.

      This method creates an intermediate LinkedHashMap to collect all property values before using the same logic as assertBean for comparison. This ensures consistent ordering and supports the full nested property syntax. The BasicBeanConverter.DEFAULT is used for value stringification and nested property access.

      Type Parameters:
      T - The type of object being tested
      Parameters:
      actual - The object to test properties on
      function - The BiFunction that extracts property values. Receives (object, propertyName) and returns the property value.
      properties - Comma-delimited list of property names to test
      expected - Comma-delimited list of expected values (exceptions become simple class names)
      Throws:
      AssertionError - if any mapped property values don't match expected values
      See Also:
    • assertMapped

      public static <T> void assertMapped(AssertionArgs args, T actual, BiFunction<T,String,Object> function, String properties, String expected)
      Same as assertMapped(Object, BiFunction, String, String) but with configurable assertion behavior.
      Type Parameters:
      T - The object type being tested.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The object to test. Must not be null.
      function - Custom property access function.
      properties - A comma-delimited list of property names.
      expected - The expected property values as a comma-delimited string.
      See Also:
    • assertContains

      public static void assertContains(String expected, Object actual)
      Asserts that the string representation of an object contains the expected substring.

      This method converts the actual object to its string representation using the current BeanConverter and then checks if it contains the expected substring. This is useful for testing partial content matches without requiring exact string equality.

      Usage Examples:

      // Test that error message contains key information assertContains("FileNotFoundException", exception); // Test that object string representation contains expected data assertContains("status=ACTIVE", user); // Test partial JSON/XML content assertContains("\"name\":\"John\"", jsonResponse);

      Parameters:
      expected - The substring that must be present in the actual object's string representation
      actual - The object to test. Must not be null.
      Throws:
      AssertionError - if the actual object is null or its string representation doesn't contain the expected substring
      See Also:
    • assertContains

      public static void assertContains(AssertionArgs args, String expected, Object actual)
      Same as assertContains(String, Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      expected - The substring that must be present.
      actual - The object to test. Must not be null.
      See Also:
    • assertContainsAll

      public static void assertContainsAll(Object actual, String... expected)
      Asserts that the string representation of an object contains all specified substrings.

      This method is similar to assertContains(String, Object) but tests for multiple required substrings. All provided substrings must be present in the actual object's string representation for the assertion to pass.

      Usage Examples:

      // Test that error contains multiple pieces of information assertContainsAll(exception, "FileNotFoundException", "config.xml", "/etc"); // Test that user object contains expected fields assertContainsAll(user, "name=John", "age=30", "status=ACTIVE"); // Test log output contains all required entries assertContainsAll(logOutput, "INFO", "Started", "Successfully");

      Parameters:
      actual - The object to test. Must not be null.
      expected - Multiple substrings that must all be present in the actual object's string representation
      Throws:
      AssertionError - if the actual object is null or its string representation doesn't contain all expected substrings
      See Also:
    • assertContainsAll

      public static void assertContainsAll(AssertionArgs args, Object actual, String... expected)
      Same as assertContainsAll(Object, String...) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The object to test. Must not be null.
      expected - Multiple substrings that must all be present.
      See Also:
    • assertEmpty

      public static void assertEmpty(Object value)
      Asserts that a collection-like object or Optional is not null and empty.

      This method validates that the provided object is empty according to its type:

      • Optional: Must be empty (not present)
      • Map: Must have no entries
      • Collection-like objects: Must be convertible to an empty List via BeanConverter.listify(Object)
      Supported Types:

      Any object that can be converted to a List, including:

      • Collections (List, Set, Queue, etc.)
      • Arrays (primitive and object arrays)
      • Iterables, Iterators, Streams
      • Maps (converted to list of entries)
      • Optional objects
      Usage Examples:

      // Test empty collections assertEmpty(Collections.emptyList()); assertEmpty(new ArrayList<>()); // Test empty arrays assertEmpty(new String[0]); // Test empty Optional assertEmpty(Optional.empty()); // Test empty Map assertEmpty(new HashMap<>());

      Parameters:
      value - The object to test. Must not be null.
      Throws:
      AssertionError - if the object is null or not empty
      See Also:
    • assertEmpty

      public static void assertEmpty(AssertionArgs args, Object value)
      Same as assertEmpty(Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      value - The object to test. Must not be null.
      See Also:
    • assertList

      public static void assertList(Object actual, Object... expected)
      Asserts that a List or List-like object contains the expected values using flexible comparison logic.
      Testing Non-List Collections:

      // Test a Set using l() conversion Set<String> mySet = new TreeSet<>(Arrays.asList("a", "b", "c")); assertList(l(mySet), "a", "b", "c"); // Test an array using l() conversion String[] myArray = {"x", "y", "z"}; assertList(l(myArray), "x", "y", "z"); // Test a Stream using l() conversion Stream<String> myStream = Stream.of("foo", "bar"); assertList(l(myStream), "foo", "bar");

      Comparison Modes:

      The method supports three different ways to compare expected vs actual values:

      1. String Comparison (Readable Format):

      // Elements are converted to strings using the bean converter and compared as strings assertList(List.of(1, 2, 3), "1", "2", "3"); assertList(List.of("a", "b"), "a", "b");

      2. Predicate Testing (Functional Validation):

      // Use Predicate<T> for functional testing Predicate<Integer> greaterThanOne = x -> x > 1; assertList(List.of(2, 3, 4), greaterThanOne, greaterThanOne, greaterThanOne); // Mix predicates with other comparison types Predicate<String> startsWithA = s -> s.startsWith("a"); assertList(List.of("apple", "banana"), startsWithA, "banana");

      3. Object Equality (Direct Comparison):

      // Non-String, non-Predicate objects use Objects.equals() comparison assertList(List.of(1, 2, 3), 1, 2, 3); // Integer objects assertList(List.of(myBean1, myBean2), myBean1, myBean2); // Custom objects

      Parameters:
      actual - The List to test. Must not be null.
      expected - Multiple arguments of expected values. Can be Strings (readable format comparison), Predicates (functional testing), or Objects (direct equality).
      Throws:
      AssertionError - if the List size or contents don't match expected values
    • assertMap

      public static void assertMap(Map<?,?> actual, Object... expected)
      Asserts that a Map contains the expected key/value pairs using flexible comparison logic.
      Map Entry Serialization:

      Map entries are serialized to strings as key/value pairs in the format "key=value". Nested maps and collections are supported with appropriate formatting.

      Testing Nested Maps and Collections:

      // Test simple map entries Map<String,String> simpleMap = Map.of("a", "1", "b", "2"); assertMap(simpleMap, "a=1", "b=2"); // Test nested maps Map<String,Map<String,Integer>> nestedMap = Map.of("a", Map.of("b", 1)); assertMap(nestedMap, "a={b=1}"); // Test maps with arrays/collections Map<String,Map<String,Integer[]>> mapWithArrays = Map.of("a", Map.of("b", new Integer[]{1,2})); assertMap(mapWithArrays, "a={b=[1,2]}");

      Comparison Modes:

      The method supports the same comparison modes as assertList(Object, Object...):

      1. String Comparison (Readable Format):

      // Map entries are converted to strings and compared as strings assertMap(Map.of("key1", "value1"), "key1=value1"); assertMap(Map.of("count", 42), "count=42");

      2. Predicate Testing (Functional Validation):

      // Use Predicate<Map.Entry<K,V>> for functional testing Predicate<Map.Entry<String,Integer>> valueGreaterThanTen = entry -> entry.getValue() > 10; assertMap(Map.of("count", 42), valueGreaterThanTen);

      3. Object Equality (Direct Comparison):

      // Non-String, non-Predicate objects use Objects.equals() comparison assertMap(Map.of("key", myObject), expectedEntry);

      Map Ordering Behavior:

      The Listifiers.mapListifier() method ensures deterministic ordering for map entries:

      This ensures predictable test results regardless of the original map implementation.

      Parameters:
      actual - The Map to test. Must not be null.
      expected - Multiple arguments of expected map entries. Can be Strings (readable format comparison), Predicates (functional testing), or Objects (direct equality).
      Throws:
      AssertionError - if the Map size or contents don't match expected values
      See Also:
    • assertMap

      public static void assertMap(AssertionArgs args, Map<?,?> actual, Object... expected)
      Same as assertMap(Map, Object...) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The Map to test. Must not be null.
      expected - Multiple arguments of expected map entries.
      See Also:
    • assertList

      public static void assertList(AssertionArgs args, Object actual, Object... expected)
      Same as assertList(Object, Object...) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      actual - The List to test. Must not be null.
      expected - Multiple arguments of expected values.
      See Also:
    • assertNotEmpty

      public static void assertNotEmpty(Object value)
      Asserts that a collection-like object or Optional is not null and not empty.

      This method validates that the provided object is not empty according to its type:

      • Optional: Must be present (not empty)
      • Map: Must have at least one entry
      • Collection-like objects: Must convert to a non-empty List via BeanConverter.listify(Object)
      Supported Types:

      Any object that can be converted to a List, including:

      • Collections (List, Set, Queue, etc.)
      • Arrays (primitive and object arrays)
      • Iterables, Iterators, Streams
      • Maps (converted to list of entries)
      • Optional objects
      Usage Examples:

      // Test non-empty collections assertNotEmpty(List.of("item1", "item2")); assertNotEmpty(new ArrayList<>(Arrays.asList("a"))); // Test non-empty arrays assertNotEmpty(new String[]{"value"}); // Test present Optional assertNotEmpty(Optional.of("value")); // Test non-empty Map assertNotEmpty(Map.of("key", "value"));

      Parameters:
      value - The object to test. Must not be null.
      Throws:
      AssertionError - if the object is null or empty
      See Also:
    • assertNotEmpty

      public static void assertNotEmpty(AssertionArgs args, Object value)
      Same as assertNotEmpty(Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      value - The object to test. Must not be null.
      See Also:
    • assertSize

      public static void assertSize(int expected, Object actual)
      Asserts that a collection-like object or string is not null and of the specified size.

      This method can validate the size of various types of objects:

      • String: Validates character length
      • Collection-like objects: Any object that can be converted to a List via the underlying converter
      Usage Examples:

      // Test string length assertSize(5, "hello"); // Test collection size assertSize(3, List.of("a", "b", "c")); // Test array size assertSize(2, new String[]{"x", "y"});

      Parameters:
      expected - The expected size/length.
      actual - The object to test. Must not be null.
      Throws:
      AssertionError - if the object is null or not the expected size.
    • assertSize

      public static void assertSize(AssertionArgs args, int expected, Object actual)
      Same as assertSize(int, Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      expected - The expected size/length.
      actual - The object to test. Must not be null.
      See Also:
    • assertString

      public static void assertString(String expected, Object actual)
      Asserts that an object's string representation exactly matches the expected value.

      This method converts the actual object to its string representation using the current BeanConverter and performs an exact equality comparison with the expected string. This is useful for testing complete string output, formatted objects, or converted values.

      Usage Examples:

      // Test exact string conversion assertString("John,30,true", user); // Assuming user converts to this format // Test formatted dates or numbers assertString("2023-12-01", localDate); // Test complex object serialization assertString("{name=John,age=30}", userMap); // Test array/collection formatting assertString("[red,green,blue]", colors);

      Parameters:
      expected - The exact string that the actual object should convert to
      actual - The object to test. Must not be null.
      Throws:
      AssertionError - if the actual object is null or its string representation doesn't exactly match expected
      See Also:
    • assertString

      public static void assertString(AssertionArgs args, String expected, Object actual)
      Same as assertString(String, Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      expected - The expected string value.
      actual - The object to test. Must not be null.
      See Also:
    • assertMatchesGlob

      public static void assertMatchesGlob(String pattern, Object value)
      Asserts that an object's string representation matches the specified glob-style pattern.

      This method converts the actual object to its string representation using the current BeanConverter and then tests it against the provided glob-style pattern. This is useful for testing string formats with simple wildcard patterns.

      Pattern Syntax:

      The pattern uses glob-style wildcards:

      • * matches any sequence of characters (including none)
      • ? matches exactly one character
      • All other characters are treated literally
      Usage Examples:

      // Test filename patterns assertMatchesGlob("user_*_temp", filename); // Test single character wildcards assertMatchesGlob("file?.txt", fileName); // Test combined patterns assertMatchesGlob("log_*_?.txt", logFile);

      Parameters:
      pattern - The glob-style pattern to match against.
      value - The object to test. Must not be null.
      Throws:
      AssertionError - if the value is null or its string representation doesn't match the pattern
      See Also:
    • assertMatchesGlob

      public static void assertMatchesGlob(AssertionArgs args, String pattern, Object value)
      Same as assertMatchesGlob(String, Object) but with configurable assertion behavior.
      Parameters:
      args - Assertion configuration. See args() for usage examples.
      pattern - The glob-style pattern to match against.
      value - The object to test. Must not be null.
      See Also: