Added "hasPackage" assertions for Class#2019
Conversation
src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_Package_Test.java
Outdated
Show resolved
Hide resolved
src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_Package_Test.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Stefano Cordio <scordio@users.noreply.github.com> Co-authored-by: Joel Costigliola <joel.costigliola@gmail.com>
Fixed Javadoc Co-authored-by: Stefano Cordio <scordio@users.noreply.github.com>
Co-authored-by: Stefano Cordio <scordio@users.noreply.github.com>
|
Could you review the changes? I think it should be ok now, thanks. |
|
Thank you @polarene and sorry for the slow feedback, I will have a look during this week. |
|
Hi @scordio no problems at all, take your time! Would you mind to tag the PR with |
|
|
|
Thank you very much! |
|
Integrated, thanks @polarene! |
|
Thanks for merging @scordio! Only a small disappointment is that I would have liked to be notified about those last changes in the tests because I had a rationale behind, but it's fine anyway. Thanks for your support, looking forward to contributing again to Assertj! |
|
I noticed that one test was missing and I spotted some changes I'd have done around. As I promised to merge the PR by the end of the week I did them by myself, but nothing is written in stone: what would you do differently? |
|
@polarene we wanted to release 3.18.0 this last week end, even if the PR was merged, we are keen to hear what you have to say. |
|
Hi guys, sorry if my words didn't come out right. I really appreciate your support and hard work, in fact, congratulations on letting this PR in time for 3.18.0, great job! All the latest changes from Stefano are ok indeed, I just wanted to point out that the modifications in the
That's it, thanks for reading so far. |
|
Hi @polarene,
Here I assumed that classes have only one package which is uniquely identified, that's why I generalized it to
Here I didn't want to test how the Package instance retrieval is done (which is JDK business) unless we have a reason for it. To the best of my knowledge, we should expect the same result between Also, I just realized we could even write: @ParameterizedTest
@ValueSource(strings = "java.util")
void should_fail_if_package_does_not_match(Package aPackage) {
...
}and JUnit 5 will resolve it with its implicit argument converter. What do you think? EDIT: I took a look at the JUnit 5 internals,
I preferred to use well-known JDK types to avoid jumping back and forth in the classes and understand where the Jedi class is located. In general, I like the entertaining test style, but I think it's better suited for the javadoc and for
In general, I tend to shorten tests where local variables are single values and can be inline, but I see your point. I'll put them back. |
|
Hi @scordio, thank you very much for answering my points, I see your reasons and generally agree on everything.
Basically you're right, packages are unique for a given class, but what I wanted to show with those tests was to make clear that
Ok maybe I confused test responsibilities, but I really wanted to assert that the instances retrieved in different ways were checked consistently, to cover corner cases, and to be future-proof whenever something changes in the next JDK versions, so those tests could signal it. I wrote it exactly to assert that we expect the same result from the various retrieval methods.
Got it, I understand your reason, thanks for clarifying. Now I know for future PRs: funny stuff only in Javadoc. The thing was, after looking around the code base I found some custom classes uses for tests here and there, so I thought it was a legit use, also I didn't write Jedi, found it in ClassesBaseTest. Thanks for restoring the GIVEN blocks, I appreciate it! |
This PR adds the
hasPackage()assertion for checking if aClassdeclares a given package.For example given:
this assertion succeeds:
There's also an overload with the
java.lang.Packageargument.Check List: