mardi 27 mars 2018

How to verify a mock interface in a test method using KotlinTest library?

I have an interface that communicates with my presenter who checks whether the fields of a form are valid.

My interface is:

interface MainView {
  fun showMessage(data: LoginEntity)
  fun showEmailError()
  fun showPasswordError()
}

My method in the presenter is like that:

fun sendForm(loginData: LoginDataPresentation, view: MainView) {
   if (isValid()) {
     view.showMessage(mapData(loginData))
   } else if (isValid()) {
     view.showPasswordError()
   } else {
     view.showEmailError()
   }
}

My test class with KotlinTest:

class LoginPresentationKtTest : StringSpec() {

  init {
    "given a bunch of Login Data should be matched successfully" {
       forAll(EmailGenerator(), PasswordGenerator(), { email: String, password: String ->

         val loginData: LoginDataPresentation(email, password)

         val mockMainView = mockMainView()

         sendForm(loginData, mockMainView())

       })
    }
  }

  private fun mockMainView(): MainView {
    //How to mock?????
  }
}

Using the KotlinTest library, is there any way to verify that the call to the showMessage method of the MainView class is done provided that the email and password generated is always correct? Is it possible to use a mock library like mockito?

Aucun commentaire:

Enregistrer un commentaire