Reputation: 1804
@RunWith(MockitoJUnitRunner.class)
public class TestMyStuff{
@Mock
private Worker worker;
@Before
public void setup(){
Mockito.lenient()
.when(worker.doWork("some stuff", "some other stuff", new Date()))
.thenReturn(true);
Mockito.lenient()
.doReturn(true)
.when(worker).doWork("some stuff", "some other stuff", new Date());
}
@Test
public void test(){
//quick test to see if mock works.
final boolean isDone = worker.doWork("zzz", "qwerty);
System.out.println("isDone: " + isDone);//i want isDone to be true
}
}
The Mockito.lenient()
method does not seem to be working because it is not returning true
. How do I make the method Worker.#doWork()
return true
no matter the input?
Upvotes: 0
Views: 2207
Reputation: 843
You may use this:
when(Worker.doWork(anyString(),...).thenReturn(true)
However, I think the code you posted have some problems. "doWork" method seems like taking two String and one Date object. In the test method you should give proper inputs to "doWork" to see results.
Upvotes: 1