close

[Solved] reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito Error Occurs?

Today I am facing the following error reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito in Java.

How To Solve reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito Error ?

  1. How To Solve reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito Error ?

    To Solve reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito Error For void methods, I think you need to use the doThrow syntax.

  2. reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito

    To Solve reason: no instance(s) of type variable(s) T exist so that void conforms to using mockito Error For void methods, I think you need to use the doThrow syntax.

Solution 1

For void methods, I think you need to use the doThrow syntax.

So in your case it would be:

doThrow(BookingException.builder().build())
      .when(booking)
      .validate(any());

I hope this helps.

Solution 2

I Figured out the right syntax.

Service mockedService = new DefaultServie();
doNothing().when(mockedService).sendReportingLogs(null);

Hope this answers the questions

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read