A library that makes it easy to create models with test data. JavaFactory is inspired by model-mommy.
With a single line, you can create an object with values (including nested objects, collections and maps).
You can use this lib to generate fake values, seeding a database, factories in tests, etc.
- Java 1.8+
- Maven
- Add the JitPack repository to your build file
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
- Add depedency
<dependency> <groupId>com.github.lramosduarte</groupId> <artifactId>javaFactory</artifactId> <version>{{VERSION|TAG}}</version> </dependency>
- Gradle
- Add the JitPack repository to your build file
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
- Add depedency
dependencies { implementation 'com.github.lramosduarte:javaFactory:{{VERSION|TAG}}' }
The only thing you need is the model's class and one single line:
import static com.github.lramosduarte.fake.FakeDataGenerator.fake;
TempClass object = fake(TempClass.Class);
TANDAM! you have a new instance of the class with those all-important random values!
If you wanna to ignore any attribute of the class on fake generate process, you can call the method makeAndIgnore
.
import static com.github.lramosduarte.fake.FakeDataGenerator;
Set attributesToIgnore = new HashSet<String>() {{ add("atrChar"); }};
TempClass object = FakeDataGenerator.getInstance().makeAndIgnore(TempClass.class, attributesToIgnore);
Until now, we don't have any implementation for shortcut call the method makeAndIgnore
like fake
.
Some types may have the size of the generated value changed with the use of some customizations.
Here is the list of supported customizations(under development):
- @Size(Javax validators)
/*Max parameter will be considerer*/ @Size(max = XXXXX)
You are welcome to raise new issues, just don't be disrespectful.
This is a new project; contributors are welcome.
- Suport to enum Type
- Default values
- Ignore some attributes
- Support java.time objects
- java.time.DayOfWeek;
- java.time.LocalDate;
- java.time.LocalDateTime;
- java.time.LocalTime;
- java.time.Month;
- java.time.ZoneOffset;
- java.time.ZonedDateTime;
- Support nested classes
- [-] Support Javax validators
- DOING Partial support