extra readme
This commit is contained in:
parent
c54588b880
commit
dadc6c6610
1 changed files with 31 additions and 1 deletions
30
README.md
30
README.md
|
|
@ -6,3 +6,33 @@ This project was inspired by the FactoryGirl project that was later renamed Fact
|
||||||
* https://en.wikipedia.org/wiki/Edie_Sedgwick
|
* https://en.wikipedia.org/wiki/Edie_Sedgwick
|
||||||
* https://www.imdb.com/title/tt0432402
|
* https://www.imdb.com/title/tt0432402
|
||||||
* https://hn.algolia.com/?q=factorybot
|
* https://hn.algolia.com/?q=factorybot
|
||||||
|
|
||||||
|
*Usage:*
|
||||||
|
for a java bean like:
|
||||||
|
```java
|
||||||
|
class Person{
|
||||||
|
String name;
|
||||||
|
int age;
|
||||||
|
|
||||||
|
//rest omitted for brevity
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* Create a definition (template for creating instances) like so:
|
||||||
|
```
|
||||||
|
Factory.define(Person.class, () -> new Person("John", 48));
|
||||||
|
```
|
||||||
|
* Create instances like so:
|
||||||
|
```
|
||||||
|
Person person = Factory.build(Person.class)
|
||||||
|
```
|
||||||
|
|
||||||
|
* But the real _power_ of this lies in
|
||||||
|
```
|
||||||
|
Person person = Factory.build(Person.class, p -> p.setAge(25));
|
||||||
|
```
|
||||||
|
This will result in an object
|
||||||
|
```json
|
||||||
|
{name: "John", age: 25}
|
||||||
|
```
|
||||||
|
|
||||||
|
Meaning the template can be customized later on
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue