Test Overview
This test checks a method that processes strings. It verifies the method handles null and empty string inputs correctly by using @NullSource and @EmptySource annotations in JUnit.
This test checks a method that processes strings. It verifies the method handles null and empty string inputs correctly by using @NullSource and @EmptySource annotations in JUnit.
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.EmptySource; import static org.junit.jupiter.api.Assertions.*; public class StringProcessorTest { @ParameterizedTest @NullSource @EmptySource void testProcessStringHandlesNullAndEmpty(String input) { StringProcessor processor = new StringProcessor(); String result = processor.process(input); assertEquals("default", result); } } class StringProcessor { public String process(String input) { if (input == null || input.isEmpty()) { return "default"; } return input.trim(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts with input = null from @NullSource | Test environment initialized, no UI involved | Check if process(null) returns "default" | PASS |
| 2 | Test runs with input = "" (empty string) from @EmptySource | Test environment ready for next input | Check if process("") returns "default" | PASS |