Class Text


public class Text extends AbstractProvider<BaseProviders>
Generates random text in a flexible way.
Since:
1.7.0
  • Field Details

  • Constructor Details

  • Method Details

    • character

      public Character character()
    • uppercaseCharacter

      public Character uppercaseCharacter()
    • lowercaseCharacter

      public Character lowercaseCharacter()
    • text

      public String text()
      Returns:
      A lowercase string of 20 to 80 characters long.
    • text

      public String text(boolean includeDigit)
      Parameters:
      includeDigit - if digits should be included
      Returns:
      A lowercase string of 20 to 80 characters long.
    • text

      public String text(int length)
      Parameters:
      length - The length of the string to return
      Returns:
      A lowercase string of exact length
    • text

      public String text(int minimumLength, int maximumLength)
      Parameters:
      minimumLength - The minimum length (inclusive)
      maximumLength - The maximum length (inclusive)
      Returns:
      A lowercase string between minimum and maximum length (inclusive)
    • text

      public String text(int minimumLength, int maximumLength, boolean includeUppercase)
    • text

      public String text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial)
    • text

      public String text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial, boolean includeDigit)
      For example, expression text(5, 15, true, false, true generates a random string of length 5 to 15 containing at least one upper case letter and at least one digit.
      Parameters:
      minimumLength - The generated text will not be shorter than this length
      maximumLength - The generated text will not be longer than this length
      includeUppercase - is at least one uppercase letter required
      includeSpecial - is at least one special symbol required
      includeDigit - is at least one digit required
      Returns:
      a random string withing given length interval
      Throws:
      IllegalArgumentException - if minimumLength > maximumLength
      IllegalArgumentException - if maximumLength is not enough to include the required symbols (upper case letter, special char, digit)
      See Also:
    • text

      public String text(Text.TextRuleConfig textRuleConfig)
      Allows to configure custom expected rules. Example
       
           faker.text().text(Text.TextSymbolsBuilder.builder()
                       .len(5)
                       .with(EN_LOWERCASE, 1)
                       .with(EN_UPPERCASE, 1)
                       .with(DIGITS, 1);
       
       
      This will generate a text with length 5 containing minimum 1 lower case and 1 upper case symbol from en locale and minimum 1 digit. Custom symbol sets are also possible
       
           final String ruLowerCase = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
           final String customSpecialSymbols = "!@#$%^*;'][{}";
           final int ruCnt = 3;
           final int specSmbCnt = 5;
           final Text.TextRuleConfig config = Text.TextSymbolsBuilder.builder()
               .len(faker.number().numberBetween(ruCnt + specSmbCnt, Math.max(ruCnt + specSmbCnt, 10)))
               .with(ruLowerCase, ruCnt)
               .with(customSpecialSymbols, specSmbCnt).build();
           final String text = faker.text().text(config);
       
       
      This will generate a string with length between 8 and 10. The string will contain min 3 lower case symbols from ru locale and minimum 5 symbols from the defined string var final String customSpecialSymbols = "!@#$%^*;'][{}";.