leonardoferreiraa / jbacon Goto Github PK
View Code? Open in Web Editor NEWA library for setting up Java objects as test data, inspired in Factory Bot
A library for setting up Java objects as test data, inspired in Factory Bot
¯\_(ツ)_/¯
clientFactory.create(client -> {
client.setName("teste");
client.setEmail("[email protected]");
})
getDefault and persist also
When using example and getDefault
call another factory, can cause duplicated data.
Example:
@Data
public class Phone {
private String number;
private Contact contact;
}
@Data
public class Contact {
private String name;
}
@Component
public class ContactFactory extends JBacon<Contact> {
@Autowired
private ContactRepository contactRepository;
@Override
public Contact getDefault() {
Contact contact = new Contact();
contact.setName("teste");
return contact;
}
@Override
public Contact getEmpty() {
return new Contact();
}
@Override
public void persist(Contact contact) {
contactRepository.save(contact);
}
}
@Component
public class PhoneFactory extends JBacon<Contact> {
@Autowired
private PhoneRepository phoneRepository;
@Autowired
private ContactFactory contactFactory;
@Override
public Phone getDefault() {
Phone phone = new Phone();
phone.setNumber("16 99999-9999");
phone.setContact(contactFactory.create());
return phone;
}
@Override
public Phone getEmpty() {
return new Phone();
}
@Override
public void persist(Phone phone) {
phoneRepository.save(phone);
}
}
In tests:
Contact contact = contactFactory.create(empty -> {
empty.setName("Leonardo");
});
phoneFactory.create(5, empty -> {
empty.setContact(contact);
});
6 Contacts will be persisted in database.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.