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

Improve event and state assertions #1261

Merged
merged 4 commits into from
Apr 6, 2020
Merged

Conversation

alexander-yevsyukov
Copy link
Contributor

@alexander-yevsyukov alexander-yevsyukov commented Apr 6, 2020

This PR adds assertion methods for events and entity states to BlackBoxContext.

Entity and entity state assertion methods now accept an ID as the first parameter. Methods that used to have the ID as the second parameter were deprecated in favour of ones with the new order.

This order is more natural because we an ID is a "pointer" to an entity. Also, we're going to have more assertion methods that would accept an instance of an entity state. Creation of an entity state (which is a Protobuf message) is a big block of code. It would be more readable if the ID parameter comes before such a block. So, to make the order consistent for all assertion methods, we're making ID coming first for all.
Also:
  * Add nullity checks.
@alexander-yevsyukov alexander-yevsyukov self-assigned this Apr 6, 2020
@alexander-yevsyukov alexander-yevsyukov marked this pull request as ready for review April 6, 2020 15:04
@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #1261 into master will increase coverage by 0.01%.
The diff coverage is 94.44%.

@@             Coverage Diff              @@
##             master    #1261      +/-   ##
============================================
+ Coverage     91.06%   91.08%   +0.01%     
- Complexity     4655     4658       +3     
============================================
  Files           598      598              
  Lines         14734    14767      +33     
  Branches        841      841              
============================================
+ Hits          13417    13450      +33     
  Misses         1057     1057              
  Partials        260      260              

*
* <p>The method compares only fields in the passed state.
*/
public final <I, S extends EntityState> void assertState(I id, S entityState) {
Copy link
Contributor

@dmdashenkov dmdashenkov Apr 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public final <I, S extends EntityState> void assertState(I id, S entityState) {
public final void assertStateEquals(Object id, EntityState entityState) {

* @return assertion that compares only expected fields
*/
public final <I, S extends EntityState> ProtoFluentAssertion
assertState(I id, Class<S> stateClass) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we get rid of unnecessary type parameters. In this case, since neither <I> nor <S> is used in the return type, they both are unnecessary.

Also, there used to be a style check for that. Is it off now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, they are not used. But they are consistent with the rest of assertion methods. Here having <I> as a generic parameter we hint on the fact that an object which can be passed to it can be of one of the identifier types, not any Object.

* Obtains a Subject for an entity of the passed class with the given ID.
*/
public final <I, E extends Entity<I, ? extends EntityState>>
EntitySubject assertEntity(I id, Class<E> entityClass) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we change the order of parameters? One could argue that specifying an entity type first and then its ID is more natural from the user's perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in one of the commit comments. Here's why. 1) When we assert against an entity state, it's a big block of code. Having the ID parameter below this block makes it poorly visible.

  1. A reference to an object usually comes first in a procedure that deals with an object. We use IDs as reference to entities.

@alexander-yevsyukov alexander-yevsyukov merged commit 65f3694 into master Apr 6, 2020
@alexander-yevsyukov alexander-yevsyukov deleted the add-assertions branch April 6, 2020 15:48
@dmitrykuzmin dmitrykuzmin mentioned this pull request Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants