Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create object with fake data in java?

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;
    }
}
like image 886
BALA Avatar asked Dec 23 '22 07:12

BALA


1 Answers

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

like image 147
BALA Avatar answered Jan 07 '23 21:01

BALA