jeudi 19 septembre 2019

Scala mockito test if a method was called without providing parameters

I have the following code:

class MyClass {

  def someMethods(): Unit = {
    val result1 = method1()
    val result2 = method2(result)     
  }
}

No I want to test if method1 and method2 are called, when I run someMethod.

class TestMyClass {

  @Test
  def testSomeMethods(): Unit = {
    val myClass = new MyClass()
    val myClassSpy = Mockito.spy(myClass)
    myClassSpy.someMethods()
    verify(myClassSpy).method1()
  }
}

For method1 this is working, but method2 needs a parameter, that is provided by method1.
Can I not just do something like assertTrue(method2.called)?
Because I do not want to check the result of the methods, I just want to know if they were called.

Aucun commentaire:

Enregistrer un commentaire