Oohh. I can't do that!!
The org.mockito.Answers is an enum, I can't extend it.
There is the class org.mockito.stubbing.Answer, which is used inside
Answers enum.
This topic talks about this subject
https://groups.google.com/group/mockito/browse_thread/thread/db86d0b9df1bec87
My problem was solved, I could do this:
when(restTemplate.postForObject("my.url", null,
String.class)).thenThrow(new RuntimeException("Ops. The post had some
problem."));
My initial problem was that I couldn't use Mockito.anyString() method,
so I've used "my.url".
Thank you for your help David.
On 30 maio, 06:25, Wesley Lira <
wesleyl...@gmail.com> wrote:
> It's true David!! I've forgot that!
> I usually create my mocks with some default Answer, but I've not
> thought to create my own answer, thats is perfect to me.
>
> I've asked that because I was mocking a spring's class, RestTemplate,
> and I couldn't stub a single method, so I've thought to doThrow for
> any method. However I did it right now.
> Nevertheless I'll try to create my own answer and post here the
> example.
>
> Thank you David!!
>
> On 26 maio, 18:00, David Wallace <
dmwallace...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Sorry, Wesley, I'm completely wrong; I wasn't thinking. Mockito has the
> > concept of a default answer, that you can set up when you create the mock.
> > All you need to do is write an Answer object that throws an exception, then
> > specify it as the default answer when you make the mock. This technique
> > is mentioned briefly athttp://
docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html...