Class Stringifiers
This class provides built-in string conversion strategies that handle common Java types
 and objects. These stringifiers are automatically registered when using
 BasicBeanConverter.Builder.defaultSettings().
Purpose:
Stringifiers convert objects to human-readable string representations for use in BCT assertions and test output. They provide consistent, meaningful string formats across different object types while supporting customization for specific testing needs.
Built-in Stringifiers:
- mapEntryStringifier()- Converts- Map.Entryto- "key=value" format
- calendarStringifier()- Converts- GregorianCalendarto ISO-8601 format
- dateStringifier()- Converts- Dateto ISO instant format
- inputStreamStringifier()- Converts- InputStreamcontent to hex strings
- byteArrayStringifier()- Converts byte arrays to hex strings
- readerStringifier()- Converts- Readercontent to strings
- fileStringifier()- Converts- Filecontent to strings
- enumStringifier()- Converts- Enumvalues to name format
- classStringifier()- Converts- Classobjects to name format
- constructorStringifier()- Converts- Constructorto signature format
- methodStringifier()- Converts- Methodto signature format
- listStringifier()- Converts- Listto bracket-delimited format
- mapStringifier()- Converts- Mapto brace-delimited format
Usage Example:
    
Resource Handling:
Warning: Some stringifiers consume or close their input resources:
- InputStream: Stream is consumed and closed during stringification
- Reader: Reader is consumed and closed during stringification
- File: File content is read completely during stringification
Custom Stringifier Development:
When creating custom stringifiers, follow these patterns:
- Null Safety: Handle null inputs gracefully
- Resource Management: Properly close resources after use
- Exception Handling: Convert exceptions to meaningful error messages
- Performance: Consider string building efficiency for complex objects
- Readability: Ensure output is useful for debugging and assertions
- 
Method SummaryModifier and TypeMethodDescriptionstatic Stringifier<byte[]>Returns a stringifier for byte arrays that converts them to hex strings.static Stringifier<GregorianCalendar>Returns a stringifier forGregorianCalendarobjects that formats them as ISO-8601 strings.static Stringifier<Class>Returns a stringifier forClassobjects that formats them according to configured settings.static Stringifier<Constructor>Returns a stringifier forConstructorobjects that formats them as readable signatures.static Stringifier<Date>Returns a stringifier forDateobjects that formats them as ISO instant strings.static Stringifier<Enum>Returns a stringifier forEnumobjects that converts them to name format.static Stringifier<File>Returns a stringifier forFileobjects that converts file content to strings.static Stringifier<InputStream>Returns a stringifier forInputStreamobjects that converts content to hex strings.static Stringifier<List>Returns a stringifier forListobjects that formats them with configurable delimiters.static Stringifier<Map.Entry>Returns a stringifier forMap.Entryobjects that formats them as"key=value" .static Stringifier<Map>Returns a stringifier forMapobjects that formats them with configurable delimiters.static Stringifier<Method>Returns a stringifier forMethodobjects that formats them as readable signatures.static Stringifier<Reader>Returns a stringifier forReaderobjects that converts content to strings.
- 
Method Details- 
mapEntryStringifierReturns a stringifier forMap.Entryobjects that formats them as"key=value" .This stringifier creates a human-readable representation of map entries by converting both the key and value to strings and joining them with the configured entry separator. Behavior:- Format: Uses the pattern "{key}{separator}{value}" 
- Separator: Uses the mapEntrySeparatorsetting (default:"=" )
- Recursive conversion: Both key and value are converted using the same converter
 Usage Examples:// Test map entry stringification var entry = Map.entry ("name" ,"John" );assertBean (entry ,"<self>" ,"name=John" );// Test with custom separator var converter = BasicBeanConverter.builder () .defaultSettings() .addSetting(SETTING_mapEntrySeparator ,": " ) .build();assertBean (entry ,"<self>" ,"name: John" );- Returns:
- A StringifierforMap.Entryobjects
- See Also:
 
- Format: Uses the pattern 
- 
calendarStringifierReturns a stringifier forGregorianCalendarobjects that formats them as ISO-8601 strings.This stringifier converts calendar objects to standardized ISO-8601 timestamp format, which provides consistent, sortable, and internationally recognized date representations. Behavior:- Format: Uses the calendarFormatsetting (default:DateTimeFormatter.ISO_INSTANT)
- Timezone: Respects the calendar's timezone information
- Precision: Includes full precision available in the calendar
 Usage Examples:// Test calendar stringification var calendar =new GregorianCalendar(2023 , Calendar.JANUARY ,15 );assertMatchesGlob ("2023-01-*" ,calendar );// Test with custom format var converter = BasicBeanConverter.builder () .defaultSettings() .addSetting(SETTING_calendarFormat , DateTimeFormatter.ISO_LOCAL_DATE ) .build();- Returns:
- A StringifierforGregorianCalendarobjects
- See Also:
 
- Format: Uses the 
- 
dateStringifierReturns a stringifier forDateobjects that formats them as ISO instant strings.This stringifier converts Date objects to ISO-8601 instant format, providing standardized timestamp representations suitable for logging and comparison. Behavior:- Format: ISO-8601 instant format (e.g., "2023-01-15T10:30:00Z" )
- Timezone: Always represents time in UTC (Z timezone)
- Precision: Millisecond precision as available in Date objects
 Usage Examples:// Test date stringification var date =new Date(1673780400000L );// 2023-01-15T10:00:00Z assertBean (date ,"<self>" ,"2023-01-15T10:00:00Z" );// Test in object property var event =new Event().setTimestamp(date );assertBean (event ,"timestamp" ,"2023-01-15T10:00:00Z" );- Returns:
- A StringifierforDateobjects
- See Also:
 
- Format: ISO-8601 instant format (e.g., 
- 
inputStreamStringifierReturns a stringifier forInputStreamobjects that converts content to hex strings.Warning: This stringifier consumes and closes the input stream during conversion. After stringification, the stream cannot be used again. Behavior:- Content reading: Reads all available bytes from the stream
- Hex conversion: Converts bytes to uppercase hexadecimal representation
- Resource management: Automatically closes the stream after reading
 Usage Examples:// Test with byte content var stream =new ByteArrayInputStream(new byte []{0x48 ,0x65 ,0x6C ,0x6C ,0x6F });assertBean (stream ,"<self>" ,"48656C6C6F" );// "Hello" in hex // Test empty stream var empty =new ByteArrayInputStream(new byte [0 ]);assertBean (empty ,"<self>" ,"" );Important Notes:- One-time use: The stream is consumed and closed during conversion
- Memory usage: All content is loaded into memory for conversion
- Exception handling: IO exceptions are wrapped in RuntimeException
 - Returns:
- A StringifierforInputStreamobjects
- See Also:
 
- 
byteArrayStringifierReturns a stringifier for byte arrays that converts them to hex strings.This stringifier provides a consistent way to represent binary data as readable hexadecimal strings, useful for testing and debugging binary content. Behavior:- Hex format: Each byte is represented as two uppercase hex digits
- No separators: Bytes are concatenated without spaces or delimiters
- Empty arrays: Returns empty string for zero-length arrays
 Usage Examples:// Test byte array stringification byte []data = {0x48 ,0x65 ,0x6C ,0x6C ,0x6F };assertBean (data ,"<self>" ,"48656C6C6F" );// "Hello" in hex // Test with zeros and high values byte []mixed = {0x00 ,0xFF ,0x7F };assertBean (mixed ,"<self>" ,"00FF7F" );- Returns:
- A Stringifierfor byte arrays
 
- 
readerStringifierReturns a stringifier forReaderobjects that converts content to strings.Warning: This stringifier consumes and closes the reader during conversion. After stringification, the reader cannot be used again. Behavior:- Content reading: Reads all available characters from the reader
- String conversion: Converts characters directly to string format
- Resource management: Automatically closes the reader after reading
 Usage Examples:// Test with string content var reader =new StringReader("Hello World" );assertBean (reader ,"<self>" ,"Hello World" );// Test with file reader var fileReader = Files.newBufferedReader (path);assertMatchesGlob ("*expected content*" ,fileReader );Important Notes:- One-time use: The reader is consumed and closed during conversion
- Memory usage: All content is loaded into memory for conversion
- Exception handling: IO exceptions are wrapped in RuntimeException
 - Returns:
- A StringifierforReaderobjects
- See Also:
 
- 
fileStringifierReturns a stringifier forFileobjects that converts file content to strings.This stringifier reads the entire file content and returns it as a string, making it useful for testing file-based operations and content verification. Behavior:- Content reading: Reads the entire file content into memory
- Encoding: Uses the default platform encoding for text files
- Resource management: Properly closes file resources after reading
 Usage Examples:// Test file content var configFile =new File("config.properties" );assertMatchesGlob ("*database.url=*" ,configFile );// Test empty file var emptyFile =new File("empty.txt" );assertBean (emptyFile ,"<self>" ,"" );Important Notes:- Memory usage: Large files will consume significant memory
- File existence: Non-existent files will cause exceptions
- Binary files: May produce unexpected results with binary content
- Exception handling: IO exceptions are wrapped in RuntimeException
 - Returns:
- A StringifierforFileobjects
- See Also:
 
- 
enumStringifierReturns a stringifier forEnumobjects that converts them to name format.This stringifier provides a consistent way to represent enum values as their declared constant names, which is typically the most useful format for testing. Behavior:- Name format: Uses Enum.name()method for string representation
- Case preservation: Maintains the exact case as declared in enum
- All enum types: Works with any enum implementation
 Usage Examples:// Test enum stringification assertBean (Color.RED ,"<self>" ,"RED" );assertBean (Status.IN_PROGRESS ,"<self>" ,"IN_PROGRESS" );// Test in object property var task =new Task().setStatus(Status.COMPLETED );assertBean (task ,"status" ,"COMPLETED" );Alternative Formats:If you need different enum string representations (like Enum.toString()or custom formatting), register a custom stringifier for specific enum types.- Returns:
- A StringifierforEnumobjects
- See Also:
 
- Name format: Uses 
- 
classStringifierReturns a stringifier forClassobjects that formats them according to configured settings.This stringifier provides flexible class name formatting, supporting different levels of detail from simple names to fully qualified class names. Behavior:- Format options: Controlled by classNameFormatsetting
- Simple format: Class simple name (default)
- Canonical format: Fully qualified canonical name
- Full format: Complete class name including package
 Usage Examples:// Test with default simple format assertBean (String.class ,"<self>" ,"String" );assertBean (ArrayList.class ,"<self>" ,"ArrayList" );// Test with canonical format var converter = BasicBeanConverter.builder () .defaultSettings() .addSetting(SETTING_classNameFormat ,"canonical" ) .build();assertBean (String.class ,"<self>" ,"java.lang.String" );- Returns:
- A StringifierforClassobjects
- See Also:
 
- Format options: Controlled by 
- 
constructorStringifierReturns a stringifier forConstructorobjects that formats them as readable signatures.This stringifier creates human-readable constructor signatures including the declaring class name and parameter types, useful for reflection-based testing. Behavior:- Format: "{ClassName}({paramType1},{paramType2},...)" 
- Class names: Uses the configured class name format
- Parameter types: Includes all parameter types in declaration order
 Usage Examples:// Test constructor stringification var constructor = String.class .getConstructor(char [].class );assertBean (constructor ,"<self>" ,"String(char[])" );// Test no-arg constructor var defaultConstructor = ArrayList.class .getConstructor();assertBean (defaultConstructor ,"<self>" ,"ArrayList()" );- Returns:
- A StringifierforConstructorobjects
- See Also:
 
- Format: 
- 
methodStringifierReturns a stringifier forMethodobjects that formats them as readable signatures.This stringifier creates human-readable method signatures including the method name and parameter types, useful for reflection-based testing and debugging. Behavior:- Format: "{methodName}({paramType1},{paramType2},...)" 
- Method name: Uses the declared method name
- Parameter types: Includes all parameter types in declaration order
 Usage Examples:// Test method stringification var method = String.class .getMethod("substring" ,int .class ,int .class );assertBean (method ,"<self>" ,"substring(int,int)" );// Test no-arg method var toString = Object.class .getMethod("toString" );assertBean (toString ,"<self>" ,"toString()" );- Returns:
- A StringifierforMethodobjects
- See Also:
 
- Format: 
- 
listStringifierReturns a stringifier forListobjects that formats them with configurable delimiters.This stringifier converts lists to bracket-delimited strings with customizable separators and prefixes/suffixes, providing consistent list representation across tests. Behavior:- Format: "{prefix}{element1}{separator}{element2}...{suffix}" 
- Separator: Uses fieldSeparatorsetting (default:"," )
- Prefix: Uses collectionPrefixsetting (default:"[" )
- Suffix: Uses collectionSuffixsetting (default:"]" )
- Recursive: Elements are converted using the same converter
 Usage Examples:// Test list stringification var list = List.of ("apple" ,"banana" ,"cherry" );assertBean (list ,"<self>" ,"[apple,banana,cherry]" );// Test with custom formatting var converter = BasicBeanConverter.builder () .defaultSettings() .addSetting(SETTING_fieldSeparator ,"; " ) .addSetting(SETTING_collectionPrefix ,"(" ) .addSetting(SETTING_collectionSuffix ,")" ) .build();assertBean (list ,"<self>" ,"(apple; banana; cherry)" );- Returns:
- A StringifierforListobjects
- See Also:
 
- Format: 
- 
mapStringifierReturns a stringifier forMapobjects that formats them with configurable delimiters.This stringifier converts maps to brace-delimited strings by first converting the map to a list of entries and then stringifying each entry, providing consistent map representation across tests. Behavior:- Format: "{prefix}{entry1}{separator}{entry2}...{suffix}" 
- Separator: Uses fieldSeparatorsetting (default:"," )
- Prefix: Uses mapPrefixsetting (default:"{" )
- Suffix: Uses mapSuffixsetting (default:"}" )
- Entry format: Each entry uses the map entry stringifier
 Usage Examples:// Test map stringification var map = Map.of ("name" ,"John" ,"age" ,25 );assertMatchesGlob ("{*name=John*age=25*}" ,map );// Test empty map var emptyMap = Map.of ();assertBean (emptyMap ,"<self>" ,"{}" );Order Considerations:The order of entries in the string depends on the map implementation's iteration order. Use order-independent assertions (like assertMatchesGlob) for maps where order is not guaranteed.- Returns:
- A StringifierforMapobjects
- See Also:
 
- Format: 
 
-