Getting EasyMock mock objects to throw Exceptions

后端 未结 2 1511

I\'m in process of using EasyMock to write Unit tests for a number of collaborating classes. One of these classes (lets call it Foo) opens a network connection

2条回答
  •  情书的邮戳
    2020-12-16 12:26

    you can use the method andThrow(Throwable throwable) in easy mock. Check the documentation - heading Working with Exceptions.

    For example

     expect(mock.voteForRemoval("Document"))
        .andThrow(new RuntimeException(), 4);
    

提交回复
热议问题