Class Faker

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

public final class Faker extends Object
Faker - Fake data generator for realistic test data Faker - 生成逼真测试数据的假数据生成器

Generates realistic-looking fake data for testing purposes.

为测试目的生成看起来逼真的假数据。

Features | 主要功能:

  • English and Chinese personal data (names, phones, emails) - 英文和中文个人数据(姓名、电话、邮箱)
  • Address data (US and Chinese) - 地址数据(美国和中国)
  • Company and internet data (domains, URLs, IPs) - 公司和互联网数据(域名、URL、IP)
  • Lorem ipsum text generation - Lorem ipsum文本生成

Usage Examples | 使用示例:

// Person data
String name = Faker.name();
String email = Faker.email();
String phone = Faker.phone();

// Chinese data
String chineseName = Faker.chineseName();
String chinesePhone = Faker.chinesePhone();

// Address data
String city = Faker.city();
String address = Faker.address();

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

    • firstName

      public static String firstName()
      Generates random first name. 生成随机名字。
      Returns:
      the first name | 名字
    • lastName

      public static String lastName()
      Generates random last name. 生成随机姓氏。
      Returns:
      the last name | 姓氏
    • name

      public static String name()
      Generates random full name. 生成随机全名。
      Returns:
      the full name | 全名
    • chineseName

      public static String chineseName()
      Generates random Chinese name. 生成随机中文名。
      Returns:
      the Chinese name | 中文名
    • email

      public static String email()
      Generates random email. 生成随机邮箱。
      Returns:
      the email | 邮箱
    • phone

      public static String phone()
      Generates random phone number (US format). 生成随机电话号码(美国格式)。
      Returns:
      the phone number | 电话号码
    • chinesePhone

      public static String chinesePhone()
      Generates random Chinese mobile phone. 生成随机中国手机号。
      Returns:
      the phone number | 手机号
    • city

      public static String city()
      Generates random city name. 生成随机城市名。
      Returns:
      the city name | 城市名
    • chineseCity

      public static String chineseCity()
      Generates random Chinese city name. 生成随机中国城市名。
      Returns:
      the city name | 城市名
    • streetAddress

      public static String streetAddress()
      Generates random street address. 生成随机街道地址。
      Returns:
      the address | 地址
    • chineseStreetAddress

      public static String chineseStreetAddress()
      Generates random Chinese street address. 生成随机中国街道地址。
      Returns:
      the address | 地址
    • address

      public static String address()
      Generates random full address. 生成随机完整地址。
      Returns:
      the address | 地址
    • chineseAddress

      public static String chineseAddress()
      Generates random Chinese full address. 生成随机中国完整地址。
      Returns:
      the address | 地址
    • state

      public static String state()
      Generates random US state abbreviation. 生成随机美国州缩写。
      Returns:
      the state | 州
    • zipCode

      public static String zipCode()
      Generates random ZIP code. 生成随机邮政编码。
      Returns:
      the ZIP code | 邮政编码
    • chinesePostalCode

      public static String chinesePostalCode()
      Generates random Chinese postal code. 生成随机中国邮政编码。
      Returns:
      the postal code | 邮政编码
    • company

      public static String company()
      Generates random company name. 生成随机公司名。
      Returns:
      the company name | 公司名
    • chineseCompany

      public static String chineseCompany()
      Generates random Chinese company name. 生成随机中国公司名。
      Returns:
      the company name | 公司名
    • username

      public static String username()
      Generates random username. 生成随机用户名。
      Returns:
      the username | 用户名
    • domainName

      public static String domainName()
      Generates random domain name. 生成随机域名。
      Returns:
      the domain name | 域名
    • url

      public static String url()
      Generates random URL. 生成随机URL。
      Returns:
      the URL | URL
    • ipv4

      public static String ipv4()
      Generates random IPv4 address. 生成随机IPv4地址。
      Returns:
      the IP address | IP地址
    • pastDate

      public static LocalDate pastDate(int yearsBack)
      Generates random past date. 生成随机过去日期。
      Parameters:
      yearsBack - years back from now | 距今的年数
      Returns:
      the date | 日期
    • futureDate

      public static LocalDate futureDate(int yearsAhead)
      Generates random future date. 生成随机未来日期。
      Parameters:
      yearsAhead - years ahead from now | 距今的年数
      Returns:
      the date | 日期
    • birthday

      public static LocalDate birthday(int minAge, int maxAge)
      Generates random birthday. 生成随机生日。
      Parameters:
      minAge - minimum age | 最小年龄
      maxAge - maximum age | 最大年龄
      Returns:
      the birthday | 生日
    • word

      public static String word()
      Generates random word. 生成随机单词。
      Returns:
      the word | 单词
    • sentence

      public static String sentence(int wordCount)
      Generates random sentence. 生成随机句子。
      Parameters:
      wordCount - word count | 单词数
      Returns:
      the sentence | 句子
    • paragraph

      public static String paragraph(int sentenceCount)
      Generates random paragraph. 生成随机段落。
      Parameters:
      sentenceCount - sentence count | 句子数
      Returns:
      the paragraph | 段落