Skip to content
A framework for creating dummy data for POJOs.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.settings
random-example
random
.gitignore
.project
.travis.yml
LICENSE
README.md
pom.xml

README.md

Random Framework

Build Status Maven Central

A framework for creating dummy data for POJOs. It can fill a lot of fields with random data, and is even able to recognize some fields that need special values to look pretty.

Getting Started

Prerequisites

You need at least Java 1.8 or above to use this library. You can use Maven as a build tool, but Gradle or using plain JARs should work as well.

Installing

This library is in Maven Central, so you can easily add it like this:

<dependency>
    <groupId>de.slothsoft.random</groupId>
    <artifactId>random</artifactId>
    <version>2.0.0</version>
</dependency>

For other build tools and the JAR take a look at Maven Central or the MVN Repository.

Using the Framework

The new and improved API is really easy to use. To create a simple POJO without much ado, do this:

class MyPerson { 
    private String firstName;
    private Date birthdate;
    
    // add getter and setter!
}

RandomFactory<MyPerson> factory = RandomFactory.forClass(MyPerson.class);

// create a single POJO
System.out.println(factory.createSingle());


// create many POJOs
for (final MyPerson person : factory.create(5)) {
    System.out.println(person);
}

If you want to have more control over the generated values, you cann add your own RandomFields like this:

class MyPojo { 
    private String firstName;
    private Date birthdate;
    
    // add getter and setter!
}

RandomFactory<MyPojo> factory = RandomFactory.forClass(MyPojo.class);
factory.addRandomField("firstName", new FirstNameRandomField().gender(Gender.MALE));
factory.addRandomField("burzeltag", new BirthdayRandomField());


System.out.println(factory.createSingle());

And finally, to create a hierarchical structure of POJOs, use the RandomIndustrialArea like this:

class MyPerson { 
    private MyPersonsAddress address;
    // add getter and setter!
}
class MyPersonsAddress { 
    private String city;
    // add getter and setter!
}

RandomIndustrialArea factory = RandomIndustrialArea.forClasses(MyPerson.class, MyPersonsAddress.class);

for (final MyPerson person : factory.create(MyPerson.class, 5)) {
	System.out.println(person);
}

Even more examples are located here. To see all types have a look at the package "types".

Versions

Version Changes
2.0.0 streamlined the API and documentation; moved to Maven Central
1.0.0 internal version with basic API

Features

The following classes and sematic fields are supported.

  • BigDecimal
  • BigInteger
  • Date (and "birthdays", which have another range)
  • Double and double
  • Float and float
  • Integer and int
  • Long and long
  • Short and short
  • some special Strings
    • cities
    • first names
    • last names
    • streets (with house number)

If something is missing, request it via a new issue.

License

This project is licensed under the MIT License - see the MIT license for details.

You can’t perform that action at this time.