-
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
Mock repositories #73
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think most of those newly created methods should be static. You should not need an instance of |
Also, it is a good idea to mimic the directory structure of the original |
Aderfish
approved these changes
Apr 8, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job, looks good to me
gruvw
approved these changes
Apr 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
This pull request aims to provide the boiler plate code needed to mock the methods of the repositories.
This code is contained in the classes
MockPostRepositoryService
andMockUserRepositoryService
.Here is an example of how such a class can be used in a test to mock a repository method
This PR also provides a class to easily generate mock data for
UserFirestore
which can be useful when testing.This class is
MockUserFirestore
located undertest/models/database/user
.Finally,
MockFirestorePost
has been renamed toMockPostFirestore
as well as being moved totest/models/database/user
for consistency.Important note:
For the mock of the repositories, the way the code is written can misleadingly make believe that a particular value will be returned whithout having to mock it in the tests with
when(...) ...
.This, is not the case, if a method from the mock repository is called without having properly set up the
when(...) ...
before, an exception will be thrown.For example, in the
MockUserRepositoryService
, we have the following override:In our test code we could be tempted to simply call:
userRepository.doesUserExist(...);
expecting it to return it
false
.This wont work and will throw an exception.
The correct way is: