-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 test address books via DI #1310
base: main-ose
Are you sure you want to change the base?
Provide test address books via DI #1310
Conversation
61d8ba9
to
2802ec6
Compare
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.
Looks good to me
4a47734
to
89a8f84
Compare
73e258d
to
dc5abdd
Compare
app/src/androidTest/kotlin/at/bitfire/davdroid/resource/LocalTestAddressBookProvider.kt
Outdated
Show resolved
Hide resolved
app/src/androidTest/kotlin/at/bitfire/davdroid/sync/account/AccountsCleanupWorkerTest.kt
Outdated
Show resolved
Hide resolved
But very nice 👍🏻 |
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.
Minor things
account: Account, | ||
provider: ContentProviderClient, | ||
groupMethod: GroupMethod = GroupMethod.GROUP_VCARDS, | ||
provideLocalTestAddressBook: (LocalTestAddressBook) -> Unit |
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.
// remove address book account / address book | ||
assertTrue(accountManager.removeAccountExplicitly( | ||
// recreate account of provided address book, since the account might have been renamed | ||
Account(addressBook.addressBookAccount.name, addressBook.addressBookAccount.type) |
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.
Optional: maybe explicitly define val renamedAccount =
and then delete that one for clarity.
Would reduce complexity of the call, but as you like
Purpose
At the moment test address books are provided via a static companion object method which requires context to be passed in. Passing context to static methods is an antipattern, since the global accessibility of context introduces testing issues and hinders maintainability.
Short description
LocalTestAddressBookProvider
which can be injected in test classes to provideLocalTestAddressBook
sLocalTestAddressBook
toLocalGroupTest
, since that's the only place they are usedreadOnly
flagNote: We should probably not completely remove
LocalTestAddressBook
since it still gives us an easy way to set the group method for tests - which is a valid use case in my eyes. I don't think using aLocalAddressBook
interface or mocking all the group method calls just to get rid ofLocalTestAddressBook
are very beneficial.Checklist