I’m fairly new to using MongoDB, but I’m finding it quite difficult to find a way to test my Mongo code. Particularly static methods, like Credentials.emailPassword or Realm.init. For example, how would I test the following using JUnit in Kotlin?
override suspend fun login(email:String, password: String) {
val completableDeferred = CompletableDeferred<App.Result<User>>()
val credentials = Credentials.emailPassword(email, password)
app.loginAsync(credentials) {
completableDeferred.complete(it)
}
onResult(completableDeferred, LoginException())
}
private suspend fun onResult(completableDeferred: CompletableDeferred<App.Result<User>>, exception: MyException) {
val result = completableDeferred.await()
if (!result.isSuccess) {
result.error.errorMessage?.let { exception.errorMessage = it }
throw exception
}
}
Thank you for any help.