I am writing a JUnit test as well using Mockito, and I want to call a method, which in turn calls the second method several times. I don't want this second method ever to be called during my unit test, but I want to know what its arguments would be. My testing code looks something like this:
public class MyClass { public void myMethod() { int a = [do some logic] int b = [do some logic]; doSomething(a, b); a = [do some logic]; b = [do some logic]; doSomething(a, b); } public void doSomething(int a, int b) {
And now unit test:
@Test public void test() { MyClass myClass = new MyClass(); myClass.myMethod(); verify(myClass).doSomething(17, 33); verify(myClass).doSomething(9, 18); }
I'm new to Mockito, and I don't know if it is possible A) to prevent doSomething () and B) from checking the values of a and b. I am ready to accept answers such as "Mokito cannot help you here" or "this is not technically possible." If there is no way to mock it, I can consider reorganizing the blocks [to make some logical ones] into methods that I can test directly, but my code is more complex than this simple example, and I am not allowed to publish the code on the Internet.
source share