Skip to content
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

Implement equals for Actions to support better testing #225

Open
zsoltvilagos opened this issue Oct 2, 2020 · 2 comments
Open

Implement equals for Actions to support better testing #225

zsoltvilagos opened this issue Oct 2, 2020 · 2 comments
Labels
Enhancement Indicates a new feature request

Comments

@zsoltvilagos
Copy link

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)
@zsoltvilagos zsoltvilagos added the Enhancement Indicates a new feature request label Oct 2, 2020
@caiofaustino
Copy link
Contributor

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()

@zsoltvilagos
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indicates a new feature request
Projects
None yet
Development

No branches or pull requests

2 participants