Skip to content

do we have an equality check method for random generated beans? #272

Closed

Description

@fyh

hi, today I was writing some unit tests and found random-beans, I think it's cool and make my life so much easier. I can generate random beans for test data-preparation which have a lot of fields.
for example:

    @Autowired
    private PersonDao dao;

    @Test
    public void saveTest() {
        Person person = enhancedRandom.nextObject(Person.class);
        dao.insertSelective(person);
        Person personEntity = dao.selectByPrimaryKey(person.getId());
        // test whether person has the same fields as personEntity
    }

The problem is I don't know how to easily check fileds equality between generated bean and the selected entity bean using DAO.
So, Is there an equality check method for random generated beans?

Thanks!

Activity

  1. fmbenhassine commented on Sep 22, 2017

    @fmbenhassine
    Member

    Hi,

    Thank you, I'm glad you find random beans useful!

    If you are using assertj, you can use the isEqualsToByComparingFields method. For example:

    Assertions.assertThat(person).isEqualsToByComparingFields(personEntity);

    This will compare all fields for you. Does this help?

    Kr
    Mahmoud

  2. fyh commented on Sep 26, 2017

    @fyh
    Author

    Hi,

    Thanks. isEqualsToByComparingFields really does what I want. The cost is to import another library.
    I suppose I shoud reinvent some code for equality check only, maybe an another Utils.java, which can be small and handful.

  3. PascalSchumacher commented on Sep 26, 2017

    @PascalSchumacher
    Collaborator

    AssertJ has really read-able and easy to use DSL (https://joel-costigliola.github.io/assertj/), great support for specific assertions on JDK types (String, Iterable, Streams, etc.) and very helpful error messages.

    It also has not dependencies, so it's only single additional dependency.

    You should give it try. It's the best java assertion library imho.

  4. fmbenhassine commented on Sep 26, 2017

    @fmbenhassine
    Member

    I shoud reinvent some code

    Don't reinvent the wheel 😄 Seriously, use assertj, it's super awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions