Stub a method using when().thenReturn() in JUnit with Mockito
Preconditions (2)
Step 1: Create a mock object of the service class using Mockito.mock()
Step 2: Use Mockito.when() to specify the method call to stub
Step 3: Use thenReturn() to specify the value to return when the method is called
Step 4: Call the stubbed method on the mock object
Step 5: Verify that the returned value matches the stubbed value using an assertion
✅ Expected Result: The stubbed method returns the specified value and the assertion passes