Package de.cuioss.test.generator.impl
Class NonBlankStringGenerator
java.lang.Object
de.cuioss.test.generator.impl.NonBlankStringGenerator
- All Implemented Interfaces:
TypedGenerator<String>
Generates non-empty and non-blank string values for testing purposes.
This generator ensures that the produced strings contain at least one
non-whitespace character.
Generation rules:
- Uses
Generators.nonEmptyStrings()as base generator - Validates that the string contains non-whitespace characters
- Retries up to 100 times to generate a valid string
- Throws
IllegalStateExceptionif no valid string can be generated
Example usage:
var generator = new NonBlankStringGenerator(); String value = generator.next(); // Returns a string with at least one non-whitespace char
This generator is particularly useful for testing input validation where whitespace-only strings should be treated differently from strings with actual content.
- Author:
- Oliver Wolff
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
NonBlankStringGenerator
public NonBlankStringGenerator()
-
-
Method Details
-
getType
Description copied from interface:TypedGeneratorProvides type information about what kind of objects this generator creates. The default implementation uses the first non-null result fromTypedGenerator.next()to determine the type.Note: If your generator may return null values or the generated type differs from the actual instance type, you should override this method.
- Specified by:
getTypein interfaceTypedGenerator<String>- Returns:
- The class information indicating which type this generator is responsible for.
-
next
Description copied from interface:TypedGeneratorGenerates the next instance based on the generator's configuration. Implementations must ensure thread-safety.- Specified by:
nextin interfaceTypedGenerator<String>- Returns:
- A newly created instance. May be null if the generator explicitly supports null value generation.
-