Suppose if I want to create an object with fake data for Person
class, manually It'll take too much time, And Person
class internally contains Parties
class.
Is there any simple ways to create Object with fake data.
By using mockito we can create object, but again manually faking data is difficult.
class Person {
int age;
ArrayList<Parties> parties;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public ArrayList<Parties> getParties() {
return parties;
}
public void setParties(ArrayList<Parties> parties) {
this.parties = parties;
}
}
class Parties {
private int date, month, year;
public int getDate() {
return date;
}
public void setDate(int date) {
this.date = date;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
Finally, I found a solution for fake the object data from the class by using PODAM library in Java without the manual interaction.
We can use Podam library to fake data for object.
Dependency
<dependency>
<groupId>uk.co.jemos.podam</groupId>
<artifactId>podam</artifactId>
<version>7.1.0.RELEASE</version>
</dependency>
Code
PodamFactory factory = new PodamFactoryImpl();
Person myPojo = factory.manufacturePojo(Person.class);
Ref: PODAM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With