Class TestingUtils

java.lang.Object
rife.bld.extension.testing.TestingUtils

public final class TestingUtils extends Object
Provides static methods for generating random values and predefined character sets.

This class is thread-safe. The shared SecureRandom instance is safe for concurrent use, making this utility suitable for parallel test frameworks (e.g. JUnit 5 parallel execution).

Since:
1.0
Author:
Erik C. Thauvin
  • Field Details

    • ALPHANUMERIC_CHARACTERS

      public static final String ALPHANUMERIC_CHARACTERS
      A string constant containing all uppercase letters, lowercase letters, and numeric digits.
      See Also:
    • HEXADECIMAL_CHARACTERS

      public static final String HEXADECIMAL_CHARACTERS
      A string constant containing all hexadecimal digits and letters.
      See Also:
    • LOWERCASE_CHARACTERS

      public static final String LOWERCASE_CHARACTERS
      A string constant containing all lowercase letters.
      See Also:
    • NUMERIC_CHARACTERS

      public static final String NUMERIC_CHARACTERS
      A string constant containing all numeric digits.
      See Also:
    • UPPERCASE_CHARACTERS

      public static final String UPPERCASE_CHARACTERS
      A string constant containing all uppercase letters.
      See Also:
    • URL_SAFE_CHARACTERS

      public static final String URL_SAFE_CHARACTERS
      A string constant representing a set of characters that are safe for use in URLs.

      It includes uppercase and lowercase letters, digits, the symbols - and _

      See Also:
  • Method Details

    • generateRandomInt

      public static int generateRandomInt(int min, int max)
      Generates a random integer within the specified range.

      Note: max must not be Integer.MAX_VALUE, as max + 1 would overflow. Passing Integer.MAX_VALUE as max results in undefined behavior.

      Parameters:
      min - the minimum value (inclusive) of the random number
      max - the maximum value (inclusive) of the random number
      Returns:
      a random integer between min and max, inclusive
      Throws:
      IllegalArgumentException - if min is greater than max
    • generateRandomString

      public static String generateRandomString(int length, String characters)
      Generates a random string with specified parameters.

      Each character in the set is chosen with equal probability. Note that duplicate characters in the characters argument will increase their relative selection probability proportionally. The predefined character set constants in this class contain no duplicates.

      Parameters:
      length - the desired length of the generated string
      characters - the character set to use; duplicate characters increase their selection probability
      Returns:
      a randomly generated string of the specified length
      Throws:
      IllegalArgumentException - if the length is non-positive or the character set is null or empty
    • generateRandomString

      public static String generateRandomString()
      Generates a random string with default parameters.

      Equivalent to generateRandomString(10, ALPHANUMERIC_CHARACTERS).

      Returns:
      a 10-character random alphanumeric string
    • generateRandomString

      public static String generateRandomString(int length)
      Generates a random string with a specified length.

      Equivalent to generateRandomString(length, ALPHANUMERIC_CHARACTERS).

      Parameters:
      length - the desired length of the generated string
      Returns:
      a random alphanumeric string of the specified length
      Throws:
      IllegalArgumentException - if length is non-positive
    • isEmpty

      public static boolean isEmpty(String s)
      Determines if a string is null or empty
      Parameters:
      s - the string to check
      Returns:
      true if the string is null or empty, false otherwise