Package org.apache.juneau.junit.bct
This package provides a comprehensive testing framework that extends JUnit with streamlined assertion methods for Java objects. The Bean-Centric Testing (BCT) framework eliminates verbose test code while providing comprehensive object introspection and comparison capabilities.
Key Features:
- Concise Assertions: Replace multiple lines of manual property extraction with single assertion calls
- Powerful Property Access: Nested objects, collections, arrays, and maps with unified syntax
- Flexible Comparison: Support for custom converters, formatters, and comparison logic
- Type Safety: Comprehensive error messages with clear property paths
- Extensible: Custom property extractors, stringifiers, and conversion logic
Core Classes:
BctAssertions
: Main assertion methods for BCTBeanConverter
: Interface for object conversion and property accessBasicBeanConverter
: Default implementation with extensible type handlersAssertionArgs
: Configuration for assertions with custom messages and converters
Quick Start:
Assertion Method Examples:
1. assertBean()
Tests object properties with support for nested syntax and collection iteration.
User
2. assertBeans()
Tests collections of objects by extracting and comparing specific fields.
List<User>
3. assertMapped()
Tests custom property access using BiFunction for non-standard objects.
Map<String,Object>
4. assertList()
Tests list/collection elements with varargs for expected values.
List<String>
5. assertContains()
Tests that a string appears somewhere within the stringified object.
User
6. assertContainsAll()
Tests that all specified strings appear within the stringified object.
User
7. assertEmpty()
Tests that collections, arrays, maps, or strings are empty.
List<String>
8. assertNotEmpty()
Tests that collections, arrays, maps, or strings are not empty.
List<String>
9. assertSize()
Tests the size/length of collections, arrays, maps, or strings.
List<String>
10. assertString()
Tests the string representation of an object using the configured converter.
User
11. assertMatchesGlob()
Tests that the stringified object matches a glob-style pattern (* and ? wildcards).
User
Custom Configuration with AssertionArgs
:
All assertion methods support custom configuration through AssertionArgs
:
- See Also:
-
ClassDescriptionConfiguration and context object for advanced assertion operations.Default implementation of
BeanConverter
for Bean-Centric Test (BCT) object conversion.Builder for creating customized BasicBeanConverter instances.Comprehensive utility class for Bean-Centric Tests (BCT) and general testing operations.Abstract interface for Bean-Centric Test (BCT) object conversion and property access.Listifier<T>Functional interface for converting collection-like objects to standardized List<Object> format.Collection of standard listifier implementations for the Bean-Centric Testing framework.Interface for custom property extraction strategies in the Bean-Centric Testing framework.Collection of standard property extractor implementations for the Bean-Centric Testing framework.Property extractor for array and collection objects with numeric indexing and size access.Property extractor for Map objects with direct key access and size property.Standard JavaBean property extractor using reflection.Exception thrown when a requested property cannot be found on an object.Stringifier<T>Functional interface for converting objects of a specific type to their string representation.Collection of standard stringifier implementations for the Bean-Centric Testing framework.Swapper<T>Functional interface for pre-processing and transforming objects before conversion.Collection of standard swapper implementations for the Bean-Centric Testing framework.A supplier that throws an exception.