Brings the popular ruby faker gem to Java

Overview

Java Faker

Maven Status Build Status Coverage Status License

This library is a port of Ruby's faker gem (as well as Perl's Data::Faker library) that generates fake data. It's useful when you're developing a new project and need some pretty data for showcase.

Usage

In pom.xml, add the following xml stanza between <dependencies> ... </dependencies>

<dependency>
    <groupId>com.github.javafaker</groupId>
    <artifactId>javafaker</artifactId>
    <version>1.0.2</version>
</dependency>

For gradle users, add the following to your build.gradle file.

dependencies {
    implementation 'com.github.javafaker:javafaker:1.0.2'
}

In your Java code

Faker faker = new Faker();

String name = faker.name().fullName(); // Miss Samanta Schmidt
String firstName = faker.name().firstName(); // Emory
String lastName = faker.name().lastName(); // Barton

String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 449

This is a demo web application that uses the library.

Javadoc

http://dius.github.io/java-faker/apidocs/index.html

Contributions

See CONTRIBUTING.md

Fakers

  • Address
  • Ancient
  • Animal
  • App
  • Aqua Teen Hunger Force
  • Artist
  • Avatar
  • Back To The Future
  • Aviation
  • Basketball
  • Beer
  • Bojack Horseman
  • Book
  • Bool
  • Business
  • ChuckNorris
  • Cat
  • Code
  • Coin
  • Color
  • Commerce
  • Company
  • Crypto
  • DateAndTime
  • Demographic
  • Disease
  • Dog
  • DragonBall
  • Dune
  • Educator
  • Esports
  • EnglandFootBall
  • File
  • Finance
  • Food
  • Friends
  • FunnyName
  • GameOfThrones
  • Gender
  • Hacker
  • HarryPotter
  • Hipster
  • HitchhikersGuideToTheGalaxy
  • Hobbit
  • HowIMetYourMother
  • IdNumber
  • Internet
  • Job
  • Kaamelott
  • LeagueOfLegends
  • Lebowski
  • LordOfTheRings
  • Lorem
  • Matz
  • Music
  • Name
  • Nation
  • Number
  • Options
  • Overwatch
  • PhoneNumber
  • Photography
  • Pokemon
  • Princess Bride
  • Relationship Terms
  • RickAndMorty
  • Robin
  • RockBand
  • Shakespeare
  • Sip
  • SlackEmoji
  • Space
  • StarCraft
  • StarTrek
  • Stock
  • Superhero
  • Team
  • TwinPeaks
  • University
  • Weather
  • Witcher
  • Yoda
  • Zelda

Usage with Locales

Faker faker = new Faker(new Locale("YOUR_LOCALE"));

Supported Locales

  • bg
  • ca
  • ca-CAT
  • da-DK
  • de
  • de-AT
  • de-CH
  • en
  • en-AU
  • en-au-ocker
  • en-BORK
  • en-CA
  • en-GB
  • en-IND
  • en-MS
  • en-NEP
  • en-NG
  • en-NZ
  • en-PAK
  • en-SG
  • en-UG
  • en-US
  • en-ZA
  • es
  • es-MX
  • fa
  • fi-FI
  • fr
  • he
  • hu
  • in-ID
  • it
  • ja
  • ko
  • nb-NO
  • nl
  • pl
  • pt
  • pt-BR
  • ru
  • sk
  • sv
  • sv-SE
  • tr
  • uk
  • vi
  • zh-CN
  • zh-TW

TODO

  • Port more classes over as there are more entries in the yml file that we don't have classes for

LICENSE

Copyright (c) 2019 DiUS Computing Pty Ltd. See the LICENSE file for license rights and limitations.

Comments
  • NullPointerException when instancing `com.github.javafaker.Faker`

    NullPointerException when instancing `com.github.javafaker.Faker`

    I'm using the following Maven artifact:

    <dependency>
      <groupId>com.github.javafaker</groupId>
      <artifactId>javafaker</artifactId>
      <version>0.2</version>
    </dependency>
    

    And instancing com.github.javafaker.Faker by obviously doing: Faker faker = new Faker();

    I got the following exception:

    java.lang.NullPointerException
        java.io.Reader.<init>(Reader.java:78)
        java.io.InputStreamReader.<init>(InputStreamReader.java:97)
        org.ho.yaml.YamlDecoder.<init>(Unknown Source)
        org.ho.yaml.YamlConfig.load(Unknown Source)
        org.ho.yaml.Yaml.load(Unknown Source)
        com.github.javafaker.Faker.<init>(Faker.java:41)
        com.github.javafaker.Faker.<init>(Faker.java:35)
    

    Is there something I'm missing?

    opened by rmariuzzo 17
  • University name fails for german locale

    University name fails for german locale

    new Faker(Locale.GERMAN).university().name(); fails with:

    java.lang.RuntimeException: Can't find top level faker object named City.
        at com.github.javafaker.service.FakeValuesService.resolveFakerObjectAndMethod(FakeValuesService.java:456)
        at com.github.javafaker.service.FakeValuesService.resolveExpression(FakeValuesService.java:407)
        at com.github.javafaker.service.FakeValuesService.resolveExpression(FakeValuesService.java:362)
        at com.github.javafaker.service.FakeValuesService.resolve(FakeValuesService.java:319)
        at com.github.javafaker.University.name(University.java:11)
    

    I believe this is a general problem.

    In https://github.com/DiUS/java-faker/commit/f574317642a820fc24eef51a1a1fbafa02db2043 the resolution of variables in the yml files was changed, e.g. "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}" was replaced by "#{area_code}-#{exchange_code}-#{subscriber_number}", but this change was only done in en-US.yml.

    In my opinion this change should be reverted, because it means that java-faker can no longer use the yml files from faker.

    opened by PascalSchumacher 14
  • Please add browser user-agent Faker

    Please add browser user-agent Faker

    Either use real-world data like https://pypi.org/project/fake-useragent/ or use snapshot cache like https://github.com/mkstayalive/random-user-agent-java

    opened by bkalbfus 12
  • Wrapping sublists with Serializable collections

    Wrapping sublists with Serializable collections

    I guess it is better to replace words.subList(0, num) with new ArrayList(words.subList(0, num)) in

    public List<String> words(int num) {
        List<String> words = (List<String>) fetchObject("lorem.words");
        Collections.shuffle(words);
        return words.subList(0, num);
    }
    

    and similar to it. Because there are cases when we have such exception:

    java.io.NotSerializableException: java.util.ArrayList$SubList
    

    Because ArrayList$SubList does not implement Serializable. In this way, user has to wrap fake string list with ArrayList manually. And code looks like the following:

    new ArrayList<>(faker.words(3))
    

    I understand, that fake data is mostly read-only and is not serialized often.

    What do you think about it?

    opened by aaabramov 11
  • NullPointerException after upgrading to 0.17

    NullPointerException after upgrading to 0.17

    Hi, after upgrading from 0.16 to 0.17 I get a NullPointerException when I do new Faker()

    java.lang.NullPointerException
    	at com.github.javafaker.service.FakeValuesService.<init>(FakeValuesService.java:74)
    	at com.github.javafaker.Faker.<init>(Faker.java:101)
    	at com.github.javafaker.Faker.<init>(Faker.java:92)
    	at com.github.javafaker.Faker.<init>(Faker.java:88)
    

    Anything I missed for upgrading to the new version?

    opened by wakramp 8
  • Vehicle Faker

    Vehicle Faker

    Problem I want a faker that generates vehicle data such as:

    • Make
    • Model
    • Year
    • VIN
    • Mileage

    Solution

    • Implement the missing Vehicle class
    • .yml file already exists

    Additional Details

    It appears that the work for this was done in PR #436 but is not in master. Is this a mistake? In a future release? or was there a decision to remove this?

    opened by thePantz 7
  • Use month values between 0-11 for GregorianCalendar

    Use month values between 0-11 for GregorianCalendar

    Hi!

    Thanks for java-faker, saved me some time writing tests this past week.

    I think GregorianCalendar's month is 0-based, and in the birthday faker it would result in an error?

    This pull request changes the value from 12 to 11. Also removed the unnecessary canonical name for java.util.Date which was already imported.

    Thanks again Bruno

    opened by kinow 7
  • Why does the jar contain snake-yaml?

    Why does the jar contain snake-yaml?

    Generally speaking, the main artifact for a library should NOT include dependencies. This can cause issues in larger projects where the shaded classes may cause duplicate classes.

    A better option is to publish an unshaded jar by default and add another jar identified by a classifier like 'deps'.

    It's a little odd because this shaded jar ONLY contains the snake-yaml dependency and nothing else, yet there are plenty of other dependencies.

    Would you guys be open to publishing the shaded jar with a deps ?

    opened by trevershick 7
  • Please remove slf4j-simple dependency

    Please remove slf4j-simple dependency

    I'm using Logback in my app.

    But Logback is not picked up because SLF4J sees that there are both slf4j-simple (added by java-faker) and Logback, and SLF4J selects slf4j-simple.

    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/home/jan/app/lib/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/home/jan/app/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
    

    I guess slf4j-simple is added by java-faker not on purpose, so please remove it.

    opened by ngocdaothanh 7
  • Add more Faker classes

    Add more Faker classes

    This adds new classes and tests for:

    • DragonBall
    • FunnyName
    • HitchhikersGuideToTheGalaxy
    • Hobbit
    • HowIMetYourMother
    • LeagueOfLegends
    • Overwatch
    • Robin
    • StarTrek
    opened by rolyatwilson 6
  • java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.loadAs

    java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.loadAs

    Hi

    I have cloned the repo and trying to use the same in my project by doing below changes in pom.xml (as per the version of the cloned code):-

    com.github.javafaker javafaker 0.13-SNAPSHOT

    But, I am getting below error on doing:- Faker faker = new Faker(new Locale("en-IND"));

    java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.loadAs(Ljava/io/InputStream;Ljava/lang/Class;)Ljava/lang/Object;
    	at com.github.javafaker.service.FakeValuesService.fakerFromStream(FakeValuesService.java:99)
    	at com.github.javafaker.service.FakeValuesService.<init>(FakeValuesService.java:67)
    	at com.github.javafaker.Faker.<init>(Faker.java:71)
    	at com.github.javafaker.Faker.<init>(Faker.java:62)
    

    Please suggest.

    opened by nitinmukhija 6
  • Wrong credit card numbers

    Wrong credit card numbers

    Describe the bug Some generated credit card numbers for CreditCardType.VISA and CreditCardType.DISCOVER are wrong

    To Reproduce

    repeat(1000) {
        val creditCard = Faker.instance().finance().creditCard(CreditCardType.DISCOVER).replace("-", "")
        if (creditCard.length == 20 || creditCard.length == 13) {
            println(creditCard)
        }
    }
    

    Expected behavior

    • Discover PAN should have a length of 16-19, not 20
    • Visa PAN should have a length of 16-19, not 13

    Versions:

    • OS: OSX
    • JDK 17
    • Faker Version 1.0.2
    opened by MRezaNasirloo 5
  • A bug in the job method

    A bug in the job method

    To Reproduce

    Faker faker = new Faker(Locale.CHINA);
    System.out.println(faker.name().name());
    System.out.println(faker.job().field());
    System.out.println(faker.job().position());
    System.out.println(faker.job().title());
    

    this is result. image

    Versions:

    • OS: windows
    • JDK 1.8
    • Faker Version 1.0.2
    opened by Gandhi-gd 1
  • Make sure that padding is used in Crypto

    Make sure that padding is used in Crypto

    In some cases it's possible to have MD5 hash (and possibly other as well) with the first byte set to 0. In this case it gets removed, while converting to BigInteger and the hex string has 31 characters. To make sure that it works as expected, we need to guarantee proper padding.

    opened by CucumisSativus 0
  • Allow some email addresses to contain single quote characters

    Allow some email addresses to contain single quote characters

    Problem: Some email addresses contain single quote characters. I'd like to test that my software can handle them properly.

    Solution: Include the single quotes in the email addresses generated by faker.internet().emailAddress()

    opened by malloryavvir 0
  • Feature/garment size faker

    Feature/garment size faker


    name: Add Garments Sizes Faker about: new feature to use Garments Sizes. see example: XS, S, M, L, XL, XXL, XXXL title: 'Garments Sizes' labels: 'Garments Sizes' assignees: ''


    Is your feature request related to a problem? Please describe. No, is just a feature.

    Describe the solution you'd like None.

    Describe alternatives you've considered None.

    Additional context None.

    opened by p4pupro 2
Owner
DiUS Computing Pty Ltd
DiUS Computing Pty Ltd
Most popular Mocking framework for unit tests written in Java

Most popular mocking framework for Java Current version is 3.x Still on Mockito 1.x? See what's new in Mockito 2! Mockito 3 does not introduce any bre

mockito 13.6k Jan 9, 2023
A Java architecture test library, to specify and assert architecture rules in plain Java

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between pa

TNG Technology Consulting GmbH 2.5k Jan 2, 2023
HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON.

hate HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON. More info in the wiki. Install with Maven

null 20 Oct 5, 2022
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java

Scott Test Reporter for Maven and Gradle Get extremely detailed failure messages for your tests without assertion libraries, additional configuration

Dávid Csákvári 133 Nov 17, 2022
TCP Chat Application - Java networking, java swing

TCP-Chat-Application-in-Java TCP Chat Application - Java networking, java swing Java – Multithread Chat System Java Project on core Java, Java swing &

Muhammad Asad 5 Feb 4, 2022
A sample repo to help you handle basic auth for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle basic auth for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you clear browser cache with Selenium 4 Java on LambdaTest cloud. Run your Java Selenium tests on LambdaTest platform.

How to clear browser cache with Selenium 4 Java on LambdaTest cloud Prerequisites Install and set environment variable for java. Windows - https://www

null 12 Jul 13, 2022
A sample repo to help you run automation test in incognito mode in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to run automation test in incognito mode in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you handle cookies for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle cookies for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https:

null 13 Jul 13, 2022
A sample repo to help you set geolocation for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to set geolocation for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https

null 12 Jul 13, 2022
A sample repo to help you capture JavaScript exception for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to capture JavaScript exception for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Wi

null 12 Jul 13, 2022
A sample repo to help you find an element by text for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to find an element by text for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows

null 12 Jul 13, 2022
A sample repo to help you emulate network conditions in Java-selenium automation test on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to emulate network conditions in Java-selenium automation test on LambdaTest Prerequisites Install and set environment variable for java. Windows

null 12 Jul 13, 2022
Awaitility is a small Java DSL for synchronizing asynchronous operations

Testing asynchronous systems is hard. Not only does it require handling threads, timeouts and concurrency issues, but the intent of the test code can

Awaitility 3.3k Dec 31, 2022
Java binding for Hoverfly

Hoverfly Java - Easy Creation of Stub Http Servers for Testing A Java native language binding for Hoverfly, a Go proxy which allows you to simulate ht

null 148 Nov 21, 2022
Java DSL for easy testing of REST services

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of usi

REST Assured 6.2k Dec 31, 2022
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.

J8Spec J8Spec is a library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine. More details here: j8spec.github

J8Spec 45 Feb 17, 2022
A modern testing and behavioural specification framework for Java 8

Introduction If you're a Java developer and you've seen the fluent, modern specification frameworks available in other programming languages such as s

Richard Warburton 250 Sep 12, 2022