Home > Back-end >  Mockito/Mockk verify call paramether
Mockito/Mockk verify call paramether

Time:10-26

I'd like to know if is possible test with mockito/mockk this situation: Im trying to test method "Test.doSomething()" inside this, has a method call to another class like "Test2.doAnotherThing(parameterObject)" . And I'd like to use mockito.verify to test "Test2.doAnotherThing(parameterObject)" but I need verify if parameterObject atributes are correct. This parameterObject is created inside of "Test.doSomething()" soo I'm using "any()" to use 'verify'.

CodePudding user response:

You will need to use an ArgumentCaptor as follows:

ArgumentCaptor<ParameterObjectClass> parameterObjectCaptor = 
      ArgumentCaptor.forClass(ParameterObjectClass.class);
verify(Test2, times(1)).doAnotherThing(parameterObjectCaptor.capture());
assertThat(parameterObjectCaptor.getValue())....
  • Related