You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 31, 2022. It is now read-only.
refactor(Query): Unify Boolean attributes' handling and testing (#552)
## Boolean attributes handling
Although we first thought it would consist in `Move Boolean to boolean in the client`, exploration showed that we need to stick to `Boolean` instead:
- Query's boolean attributes can either be _unset_, _true_ or _false_
- The default for each attribute is _not something we can rely on in the library_ (although sometimes it's mentioned in the docstring)
Consequently, we need our boolean getters to return either of three values: `Boolean.TRUE`, `Boolean.FALSE`, and `null` if unset.
This means **getters should be implemented as `public @nullable Boolean getXXX()`**.
Likewise, the user should be able to unset an attribute's value, putting the `Query` in its default state for that attribute.
This means **setters should be implemented as `public @nonnull Query setXXX(@nullable Boolean xxx);`**.
This is implemented in 530c577, which refactors setters that were not compliant with this reasoning; and 68a955c, which adds appropriate annotations.
## Boolean attributes testing
Testing of our boolean attributes was inconsistent, sometimes testing `TRUE` and `FALSE` cases and sometimes only one of them. Adding a test for the `null` case was an opportunity to refactor those.
I went the following way:
- Extract the Boolean testing logic into [`testBooleanAttribute`](https://github.com/algolia/algoliasearch-client-android/blob/39a4dee0c71eac1db2f8a4a6a53905f1713e9a73/algoliasearch/src/test/java/com/algolia/search/saas/QueryTest.java#L874-L916), a generic method testing all cases of Boolean values for a given attribute
- Refactor Boolean tests to always use `testBooleanAttribute`. This makes the tests much more concise, more consistent, without any significant performance drawback (runnning 5 times `QueryTest` before and after this change results in a mean difference of `0.12`s).
- Reorganize tests into [regions for attribute types](https://github.com/algolia/algoliasearch-client-android/blob/39a4dee0c71eac1db2f8a4a6a53905f1713e9a73/algoliasearch/src/test/java/com/algolia/search/saas/QueryTest.java#L116). If we like the benefits of this new structure, I would apply it to each other attribute type.
- For mixed type attributes that can be Boolean (currently `ignorePlurals`), add assertions for the `null` case and keep it unchanged until further refactoring.
@@ -1476,11 +1483,12 @@ public SortFacetValuesBy getSortFacetValuesBy() {
1476
1483
* @param enabled False means that the total score of a record is the maximum score of an individual filter. Setting it to true changes the total score by adding together the scores of each filter found. Defaults to false.
0 commit comments