lately I'm coming deeper into unit tests and I kind of stuck.
Example. we have method like this:
boolean isCheckOutChecked(NmCommandBean clientData) {
return "checkOut".equalsIgnoreCase(clientData.getTextParameter("checkOut"));
}
Most of it depends by what clientData
returns. There are two possibilities:
- return null if can not find text parameter
- return string value if did
Well... I have created two tests but wondering if does it have any sense to have tests like this? What will you do in this scenario?
@Test
void shouldReturnTrueWhenCheckoutIsChecked() {
doReturn("checkOut").when(clientData).getTextParameter("checkOut");
boolean checkOutChecked = formProcessor.isCheckOutChecked(clientData);
assertTrue(checkOutChecked);
}
@Test
void shouldReturnFalseWhenCheckoutIsNotChecked() {
doReturn(null).when(clientData).getTextParameter("checkOut");
boolean checkOutChecked = formProcessor.isCheckOutChecked(clientData);
assertFalse(checkOutChecked);
}