I wonder what is the best way to test a method that only checks boolean expressions.
For example, I want to test this method :
boolean canDoSomething( Account account, User user )
{
return ( account.isAck()
&& account.getEmail() != null
&& account.getName().equals( user.getProvider() );
}
Do I have to write a junit method for each boolean combinations ? Like whenNotAckThenDontDoSomething(), whenEmailIsNullThenDontDoSomethind() …
I think it’s a little ugly so I wonder if there a better way to do that.
Fully testing the method means testing each boolean combination within the expression. You may not always need this: test until you are confident that all possible failure options are covered.
You should test at least with each condition being false, while the others true, to verify that the return value is true only if all conditions are fulfilled. I.e.