Class SensitiveDataGenerator

java.lang.Object
cloud.opencode.base.test.data.SensitiveDataGenerator

public final class SensitiveDataGenerator extends Object
Sensitive Data Generator - Generates test data that looks real but is fake 敏感数据生成器 - 生成看起来真实但实际是假的测试数据

Generates test data with correct formats (checksums, etc.) but using non-real values to avoid accidental use of real personal information.

生成格式正确(校验和等)但使用非真实值的测试数据,以避免意外使用真实个人信息。

Features | 主要功能:

  • Test phone numbers (non-real carrier prefixes) - 测试手机号(非真实运营商前缀)
  • Test ID card numbers (valid checksum, fake region) - 测试身份证号(有效校验和,虚假地区)
  • Test bank card numbers (Luhn valid, test BIN) - 测试银行卡号(Luhn有效,测试BIN)
  • Test email addresses - 测试邮箱地址

Usage Examples | 使用示例:

String phone = SensitiveDataGenerator.testPhone();     // 199xxxxxxxx
String idCard = SensitiveDataGenerator.testIdCard();   // 999999xxxxxxxxxx
String bankCard = SensitiveDataGenerator.testBankCard(); // 622848xxxxxxxxxx

Security | 安全性:

  • Thread-safe: Yes (uses ThreadLocalRandom) - 线程安全: 是(使用ThreadLocalRandom)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • testPhone

      public static String testPhone()
      Generates a test phone number (199 prefix, not assigned to real carriers). 生成测试手机号(199前缀,未分配给真实运营商)。
      Returns:
      the test phone number | 测试手机号
    • testPhone

      public static String testPhone(String prefix)
      Generates a test phone number with custom prefix. 生成带自定义前缀的测试手机号。
      Parameters:
      prefix - the custom prefix (2-3 digits) | 自定义前缀
      Returns:
      the test phone number | 测试手机号
    • testIdCard

      public static String testIdCard()
      Generates a test 18-digit ID card number (fake region 999999). 生成18位测试身份证号(虚假地区999999)。
      Returns:
      the test ID card number | 测试身份证号
    • testIdCard

      public static String testIdCard(int birthYear)
      Generates a test ID card with specified birth year. 生成指定出生年份的测试身份证号。
      Parameters:
      birthYear - the birth year | 出生年份
      Returns:
      the test ID card number | 测试身份证号
    • testBankCard

      public static String testBankCard()
      Generates a test bank card number with valid Luhn checksum. 生成带有效Luhn校验和的测试银行卡号。
      Returns:
      the test bank card number | 测试银行卡号
    • testBankCard

      public static String testBankCard(String bin)
      Generates a test bank card number with custom BIN. 生成带自定义BIN的测试银行卡号。
      Parameters:
      bin - the bank identification number (6 digits) | 银行识别号
      Returns:
      the test bank card number | 测试银行卡号
    • testEmail

      public static String testEmail()
      Generates a test email address. 生成测试邮箱地址。
      Returns:
      the test email address | 测试邮箱地址
    • testEmail

      public static String testEmail(String domain)
      Generates a test email address with specified domain. 生成带指定域名的测试邮箱地址。
      Parameters:
      domain - the domain | 域名
      Returns:
      the test email address | 测试邮箱地址
    • testSocialCreditCode

      public static String testSocialCreditCode()
      Generates a test unified social credit code. 生成测试统一社会信用代码。
      Returns:
      the test code | 测试代码