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

forPackage/forClasses full API #697

Closed
xenoterracide opened this issue Sep 12, 2022 · 8 comments
Closed

forPackage/forClasses full API #697

xenoterracide opened this issue Sep 12, 2022 · 8 comments
Labels

Comments

@xenoterracide
Copy link

Is your feature request related to a problem? Please describe.

I dislike writing a customized check for each jpa class

Describe the solution you'd like

EqualsVerifier.forPackage("com.company").withOnlyTheseFields("id").verify()

Describe alternatives you've considered

just doing this for each class, or writing my own scanner, could also do this in a loop

EqualsVerifier.forClass(ExceptionEntity::class.java).withOnlyTheseFields("id").verify()

Additional context

nl.jqno.equalsverifier:equalsverifier:3.10.1
@jqno
Copy link
Owner

jqno commented Sep 13, 2022

That's a good idea!
I don't have a lot of spare time these days so unfortunately I can't promise I'll get to this soon. But I'm open for a PR 😉

@jqno jqno added the accepted label Sep 13, 2022
@xenoterracide
Copy link
Author

If only my company would let me

@jqno
Copy link
Owner

jqno commented Sep 16, 2022

I think I wasn't paying attention when I replied on this thread earlier, because such a feature already (almost) exists. You can do this:

EqualsVerifier.configure()
        .suppress(...)
        .usingGetClass()
        .forPackage(...)
        .verify();

This won't let you specify certain things, including .withOnlyTheseFields() which is of course the one you asked for. The reason I left that out is that I thought it would be confusing to have it, because what if the specified field doesn't exist on some of the classes we're testing? I guess in a JPA context, you can assume id is always there, but that's an exceptional case that already has a workaround that should work in this context -- can you check in your codebase and confirm or deny that?

@xenoterracide
Copy link
Author

hmm... well per other ticket the withOnlyTheseFields doesn't work for me anyways. I also realize that forPackage won't because I do have other types that don't need equality in here. However, forClasses does.

What might be better though that would allow me to use forPackage is if I could do some kind of forPackageWithType("my.package", AbstactClassOrInterface.class) so that I could scan but check only things of that type. Although maybe that should be a different ticket?

@jqno
Copy link
Owner

jqno commented Sep 16, 2022

Glad it worked out! I agree, this feature request should be a new ticket, but I like the idea, so you're free to submit that. The same caveat applies though, I don't have a lot of time so I can't give you any timeframe. But at least you have a workaround now.

@xenoterracide
Copy link
Author

lol, I ended up right back here... since removing @EmbeddedId forClasses won't work since it's missing this api. Any chance we could reopen?

@xenoterracide
Copy link
Author

although this time I'm hitting significant fields. In the mean time I'm going to use parameterized junit

@jqno
Copy link
Owner

jqno commented Oct 3, 2022

I think trying parameterized tests is a good idea, right tool for the job and everything... Please let me know how this works out for you. If it works well, I'll add something to the docs for those who run into similar issues! And if it doesn't work out, we can re-evaluate here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants