Package rife.bld.extension.testing
Annotation Interface RandomString
JUnit annotation for configuring random string generation in test method parameters.
Apply this annotation to String parameters in test methods to automatically
inject randomly generated strings. The extension will resolve these parameters during
test execution.
This annotation can also be applied at the method level to configure default settings for all String parameters in that method.
Usage examples:
@ExtendWith(RandomStringResolver.class)
public class MyTest {
// Default: 10 alphanumeric characters
@Test
void test(@RandomString String str) { ... }
// Custom length: 15 characters
@Test
void test(@RandomString(length = 15) String str) { ... }
// Custom character set: only uppercase letters
@Test
void test(@RandomString(characters = TestingUtils.UPPERCASE_CHARACTERS) String str) { ... }
// Both custom length and characters: 8-character hex string
void test(@RandomString(length = 8, characters = TestingUtils.HEXADECIMAL_CHARACTERS) String hexStr) { ... }
// Multiple parameters
@Test
void test(@RandomString(characters = "ABC123") String str1, @RandomString(length = 5) String str2) { ... }
// Method-level annotation for single parameter
@Test
@RandomString(length = 5)
void test(String random) { ... }
// Method-level annotation applies to all String parameters
@Test
@RandomString(length = 8, characters = TestingUtils.URL_SAFE_CHARACTERS)
void test(String url1, String url2) { ... }
// Parameter-level annotation overrides method-level
@Test
@RandomString(length = 5)
void test(String defaultRandom, @RandomString(length = 3) String shortRandom) { ... }
// Field injection
@RandomString
private String myRandomString;
@Test
void test() {
// myRandomString is initialized before test
}
// List of random strings
@Test
void test(@RandomString(size = 5) List<String> randomList) { ... }
// Set of random strings with custom length
@Test
void test(@RandomString(size = 10, length = 8) Set<String> randomSet) { ... }
// List with custom character set
@Test
void test(@RandomString(size = 3, characters = TestingUtils.HEXADECIMAL_CHARACTERS) List<String> hexList) { ... }
// Field injection for List
@RandomString(size = 5)
private List<String> randomStrings;
// Field injection for Set
@RandomString(size = 10, length = 15)
private Set<String> randomStringSet;
}-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe alphanumeric character set to use for random string generation.intThe length of the generated random string.intThe number of random strings to generate for List or Set parameters.
-
Element Details
-
characters
String charactersThe alphanumeric character set to use for random string generation.- Returns:
- the character set string
- Throws:
IllegalArgumentException- if the character set isnullor empty during resolution
- Default:
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
-
length
int lengthThe length of the generated random string.- Returns:
- the desired length
- Throws:
IllegalArgumentException- if length is 0 or negative during resolution
- Default:
- 10
-
size
int sizeThe number of random strings to generate for List or Set parameters.When
sizeis greater than 0, this annotation can be applied to:List<String>parameters - generates a list of random stringsSet<String>parameters - generates a set of unique random strings
When
sizeis 0 (default), this annotation applies to singleStringparameters.- Returns:
- the number of strings to generate, or 0 for single string generation
- Throws:
IllegalArgumentException- if size is negative during resolution
- Default:
- 0
-