Reputation: 129
I need to test if the boolean value returned by the checkIt function when I call Myfunction with 'hello', it should return true.
public class Myclass
{
public void Myfunction(x)
{
if(x!= null)
{
boolean containsHello;
containsHello = checkIt(x)
}
Rest of the statements for Myfunction -------
goes here -------
}
@VisibleForTesting
boolean checkIt(String x)
{
return x.contains('hello');
}
I want to unit test if the checkIt function returns true when I pass 'hello' to Myfunction in Mockito. I tried the below code but it does not seem to work
String loc = Mockito.spy('hello');
Mockito.verify(Myclass).checkIt(x);
Assert.assertEquals(true, checkIt(loc));
Upvotes: 0
Views: 472
Reputation: 38
As cwa mentioned, you don't need to create a spy - just use a string directly. Additionally, in Java you'll need to use double quotes for strings in Java. This will look like:
Assert.assertEquals(true, checkIt("some string"));
Upvotes: 1