I am using SafetyNet in my application, following this guide: https://developer.android.com/training/safetynet/attestation, and I have code similar to this pattern (which is in provided link):
SafetyNet.getClient(this).attest(nonce, API_KEY)
.addOnSuccessListener(this) {
// ...
}
.addOnFailureListener(this) { e ->
// ...
}
}
Everything is working, I get success or failure when expected.
My question: is there a way I can unit test this code without calling attest()
method on a real SafetyNetClient, but on mock instead? I can mock SafetyNetClient
and SafetyNetApi.AttestationResponse
using Mockito, but I don't know how to simulate success or failure events.