Question: Need help on a unit testing on handling the empty string, pretty new to java. @Test void should_handle_null_string() { assertNull(ClassName.methodName(null)); } @Test void should_handle_empty_string() {

Need help on a unit testing on handling the empty string, pretty new to java.

@Test void should_handle_null_string() { assertNull(ClassName.methodName(null)); }
@Test void should_handle_empty_string() { assertTrue(ClassName.methodName("").isEmpty()); }

For the first test, I can successfully use "if (input == null) return null;" to pass. However, I encountered the problem on the second one. Since the output of the method is String, so when I tried using the following:

if (input.equals("")) return String.valueOf(true); 

It cannot pass. The error shows that "expected: but was: ". I'm confused about it.

"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!