-
Notifications
You must be signed in to change notification settings - Fork 1
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
Provide Assertj helpers #11
Conversation
Add ResultAssert
Add ResultAssert comments
Hey, below is my 5 cents. Review
ResultAssertI was also thinking about the assertion and ability to use satisfies method. Then we can define public ObjectAssert<E> isError() {
isNotNull();
if (actual instanceof Result.Error(E error)) {
return Assertions.assertThat(error);
}
throw failure("Expected Result to be Error but was Success");
} and then we can use any assertion method of the error, or if the error is not common type, just use ResultAssert.assertThat(result)
.isError()
.satisfies(error ->
Assertions.assertThat(error)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Name is invalid")
); The same change will be applied to With this approach user will have ability to anything he want, and After that change we can remove With this approach your last example will look like this: assertThat(result)
.isSuccess()
.hasSize(3)
.containsExactlyInAnyOrder("three", "two", "one"); Calling of WDYT? |
I think it should work as intended because the bom is listed in
I do not like to track authorship in the source code. It is usually misleading and outdated (because there are no mechanisms to correctly track it), as you can see my name is absent from any source file. I'm completely not against any kind of badge of honor. I think your contributions are valuable and worth recognition. I just think that the source code is not a place for this. I think I'm going to write release notes for the release and I'll try to list all your contributions there or you can just refer to your commits, which are all preserved, I haven't squashed anything or overwritten any history and I intend to continue this practice.
I think I would leave two copies of tests. The tests in ResultAssert
I do not like it, because with such ResultAssert.assertThat(result).isNotNull().isError(); is not the same as ResultAssert.assertThat(result).isError().isNotNull(); I would like to have a method with some more telling name, probably With
or
and for success:
or differently:
The above looks to me like the best option that ticks all the boxes... |
Hey, I agree with almost everything, but don't agree with that:
Actually this one will be always possible: ResultAssert.assertThat(result).isNotNull().hasErrorThat().isNotNull(); First Of course we can name the method as public ObjectAssert<E> hasErrorThat() {
isNotNull();
if (actual instanceof Result.Error(E error)) {
return Assertions.assertThat(error);
}
throw failure("Expected Result to be Error but was Success");
} or somehow differently? Do you want me to make a pull request with this change? |
Yes, this is mostly about the naming. The following I can understand assertThat(result).isNotNull().hasErrorThat().isNotNull(); , but the same with the assertThat(result).isNotNull().isError().isNotNull();
I think what you've written should work.
I was going to go through the changes and release a new version by the end of the week. The remaining changes that I know of:
You can do any of these to speed things up, but I was also planning to do some of this today and tomorrow. |
[x] change hasErrorThat to be as one that we have discussed [x] remove unnecessary specializations (hasErrorEqualTo, hasSuccessEqualTo) [x] convert all the tests in ResultCollectorsTest.java in result4j-assertj to use ResultAssert or remove those that do not need ResultAssert
I made #12 PR with:
You can cherry pick my commit to this PR. |
…thods without parameters.
Change ResultAssert methods.
I've merged your changes and added some more modifications on top:
Take a look. If there is no strong disagreement, then I'll merge this tomorrow and release version 1.2. |
Few things.
WDYT? |
And one more thing. Why assertion class is in |
I do believe this is wrong. You can import multiple methods with the same name. JLS implicitly allows it, see for instance section 15.12.2.1. There it says
Here it says "examines all member methods that are imported" and in section 7.5.3 there is a restriction on the static imports for the types with the same name, but no restrictions for the multiple static imports of methods with the same name. Moreover, this is not only allowed, it is also the recommended way to use AssertJ. See the Providing an entry point for all custom assertions section in the AssertJ documentation. There is an explicit example that does: import static my.project.MyProjectAssertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat; And this is the recommended way to do it. This is actually a reason, why the Creating your own assertion class section recommends that you create "An entry point to your specific assertion class to use with static import", this is because Java is to select the most specific version of
I like I think I'm mostly ok with choosing
Are you ok with that? |
We need a separate artifact to depend on in tests. The goals for result4j is to
Following these goals we do not want to bundle support of assertj in the same artifact as a main Also
This is more stylistic and only partly technical. When we have multiple packages I prefer organizing them following the layering or dependency-graph. I. e. if I see
Probably it's a good solution, but this will break backwards compatibility, so we have to stay within the Practically I don't think package name is that big of a problem, so I would probably leave package-naming like it is right now. |
|
@marcindabrowski What do you think about renaming |
It is OK to me |
Fixes #7
@marcindabrowski
In #10, you provided an example of the "that"-style method usage.
We assume the following
Result
-value:and the following imports:
I see a several ways assertions can be written:
option
option
option
If we do with static-imports, like
assertj
promoteswe can get 2 or 3 even shorter:
...
option
option
That said, I've found a precedent for such methods in assertj itself and there they use another form, something that can be written as
...
...
...
option
See AbstractObjectAssert::extracting and AbstractOptionalAssert::get.
I think we should go with the 4th option, like the following:
WDYT?