How to check setter call in kotlin using mockito?

interface LoginDisplay {
    var username: String
    var password: String
}


class LoginActivityLoginDisplay : LoginDisplay {

    override var username: String
        get() = usernameEditView.text.toString()
        set(value) {
            usernameEditView.setText(value)
        }

    override var password: String
        get() = passwordEditView.text.toString()
        set(value) {
            passwordEditView.setText(value)
        }

}

This is sample code that I would like to test with Mockito as follows:

verify(contract.loginDisplay).username

It is difficult to say that in this call I can only check the user name of the field field, in the meantime I would like to check the call to the installer of this field.

Any help?

+4
source share
1 answer

This is easier than you think :) Call:

verify(contract.loginDisplay).username = ""

will have the desired result. Setter setUsername on the layout of contract.loginDisplay is called.

+15
source

Source: https://habr.com/ru/post/1656315/


All Articles