Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fyh opened this Issue Sep 18, 2017 · 4 comments

Comments

3 participants
@fyh
Copy link

commented Sep 18, 2017

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!

@benas

This comment has been minimized.

Copy link
Collaborator

commented Sep 22, 2017

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

@fyh

This comment has been minimized.

Copy link
Author

commented Sep 26, 2017

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.

@fyh fyh closed this Sep 26, 2017

@PascalSchumacher

This comment has been minimized.

Copy link
Collaborator

commented Sep 26, 2017

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.

@benas

This comment has been minimized.

Copy link
Collaborator

commented Sep 26, 2017

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
You can’t perform that action at this time.