Verify method throws exception using when().thenThrow() in JUnit with Mockito
Preconditions (3)
Step 1: Mock the dependency that the service class uses
Step 2: Use when().thenThrow() to simulate an exception when the method is called
Step 3: Call the service method that uses the mocked dependency
Step 4: Catch the exception or use assertion to verify the exception is thrown
✅ Expected Result: The test should pass if the expected exception is thrown when the method is called