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

Wrap ably-java in a set of interfaces and add example unit test for DefaultAbly #868

Merged
merged 2 commits into from
Dec 29, 2022

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Dec 28, 2022

This introduces a set of interfaces, AblySDK*, which represent all of the functionality of ably-java used by this SDK.

This allows us to mock out ably-java in unit tests and hence to write unit tests for DefaultAbly, which is currently untested (I've created #869 for writing tests for all the existing behaviour of that class).

I’ve also added one example unit test for DefaultAbly, just to confirm the new interfaces are fit for purpose.

See commit messages for more details.

@github-actions github-actions bot temporarily deployed to staging/pull/868/dokka December 28, 2022 19:40 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/868/dokka December 28, 2022 20:27 Inactive
@lawrence-forooghian lawrence-forooghian changed the title WIP create mocks for Ably Wrap ably-java in a set of interfaces and add example unit test for DefaultAbly Dec 28, 2022
@github-actions github-actions bot temporarily deployed to staging/pull/868/dokka December 28, 2022 23:54 Inactive
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review December 29, 2022 00:52
Copy link
Contributor

@KacperKluka KacperKluka left a comment

Choose a reason for hiding this comment

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

Great job 💪 I've left a few comments and suggestions 😉

Also the test could use some refactoring, however, I know that this is just an example test so wouldn't want to block this PR on the test refactoring 😉

common/src/main/java/com/ably/tracking/common/Ably.kt Outdated Show resolved Hide resolved
common/src/main/java/com/ably/tracking/common/AblySDK.kt Outdated Show resolved Hide resolved
common/src/main/java/com/ably/tracking/common/AblySDK.kt Outdated Show resolved Hide resolved
The DefaultAbly class already has quite a bit of logic (e.g. retries) and I
intend to add further logic to it. It would be good to be able to unit test
this class. It sounds like we haven’t done this so far because we didn’t want
to try and mock the AblyRealtime class. But I think we need to be able to unit
test DefaultAbly (which I’ve created issue #869 for), so I’m putting the
ably-java library behind a set of AblySdk* interfaces. This will allow us to
provide mock implementations of the Ably client library when testing
DefaultAbly.

(I’ve taken this approach from the asset-tracking-swift codebase.)

One thing worth noticing is the new use of the !! operator when extracting the
`reason` from a connection that’s in a failed state. This looks like it’s
introducing a new unsafe behaviour, but it’s actually just making explicit a
previous assumption, namely that when a connection is in a failed state its
`reason` will be non-null. The previous version of the code - in which the
connection’s `reason` was of platform type ErrorInfo! – would equally have
thrown a NullPointerException if this assumption were violated.
This is just to check that the interfaces created in 934ec93 are fit for
purpose.
@lawrence-forooghian
Copy link
Collaborator Author

Also the test could use some refactoring, however, I know that this is just an example test so wouldn't want to block this PR on the test refactoring 😉

Don't worry, you'll have plenty of opportunity to critique my tests when I write some for #862 😁

Copy link
Contributor

@KacperKluka KacperKluka left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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

Successfully merging this pull request may close these issues.

2 participants