throw checked Exceptions from mocks with Mockito

后端 未结 5 2038
梦毁少年i
梦毁少年i 2020-11-27 15:17

I\'m trying to have one of my mocked objects throw a checked Exception when a particular method is called. I\'m trying the following.

@Test(expectedException         


        
5条回答
  •  清酒与你
    2020-11-27 15:33

    This works for me in Kotlin:

    when(list.get(0)).thenThrow(new ArrayIndexOutOfBoundsException());
    

    Note : Throw any defined exception other than Exception()

提交回复
热议问题