adyen-android
adyen-android copied to clipboard
Implement equals for Actions to support better testing
Is your feature request related to a problem? Please describe.
For 3DS integration, our code uses the respective SDK Action class implementations: RedirectAction, Threeds2FingerprintAction, Threeds2ChallengeAction (ofc).
In our tests, using Mockito / Mockito-Kotlin, we usually verify that certain methods are invoked with specific instances of classes to assert behaviour of our components. Such only work if the type of method arguments are implementing equals. Since we're using Kotlin and data classes, that's granted.
But for aforementioned Action implementations, we can't do such verifications since these classes do not implement equals, even though they are pretty much like data classes.
Describe the solution you'd like
Let's implement equals in Action descendants.
Additional context
Some sample (pseudo) code:
We have a ViewModel with a LiveData:
class MyViewModel {
val command = MutableLiveData<Action>()
}
Test code mocks an observer to be used to verify LiveData emissions.
val viewModel = MyViewModel()
val observer: Observer<Action> = mock()
viewModel.command.observeForever(observer)
Then test code calls actions on ViewModel to make it emit expected objects and verify such emissions
// when
viewModel.someAction()
// then
val expectedAction = RedirectAction().apply { ... }
verify(observer).onChanged(expectedAction)
Thx for the suggestion, we will try to work on that for the next releases.
In the meantime, maybe you can use the serialised version of the objects and check equality of the result string?
Like Action.SERIALIZER.serialize(action).toString()
Thanks! Keen to have that release :)
Nope, I can't. These Action objects are a bit further down in a container object in our code.