I am trying to get one of my mocking objects to throw an exception when calling a particular method. I am trying to do the following.
@Test(expectedExceptions = SomeException.class) public void throwCheckedException() { List<String> list = mock(List.class); when(list.get(0)).thenThrow(new SomeException()); String test = list.get(0); } public class SomeException extends Exception { }
However, this causes the following error.
org.testng.TestException: Expected exception com.testing.MockitoCheckedExceptions$SomeException but got org.mockito.exceptions.base.MockitoException: Checked exception is invalid for this method! Invalid: com.testing.MockitoCheckedExceptions$SomeException
Looking at the Mockito documentation , they only use RuntimeException , is it impossible to throw checked Exceptions from the layout with Mockito?
java mockito mocking
Arthur Maltson Sep 21 '10 at 15:50 2010-09-21 15:50
source share