Home > Net >  reason: no instance(s) of type variable(s) T exist so that void conforms to T
reason: no instance(s) of type variable(s) T exist so that void conforms to T

Time:05-25

I want to do nothing when cloudWatchRuleDestroy.destroy(@NonNull String ruleName) function of another class is called.

I have tried Mock and InjectMocks but "cloudWatchRuleDestroyer.destroy(any())" makes the compiler show "reason: no instance(s) of type variable(s) T exist so that void conforms to T"

    public void testHandleRequest() {
        doNothing().when(cloudWatchRuleDestroyer.destroy(any()));
        handler.handleRequest(inputMap);
    }

How to avoid this compiler error? What is the change I need to make?

CodePudding user response:

Syntax of brackets is wrong.

Correct Syntax:

doReturn(someObject)
    .when(someInstance)
    .someMethod();
  • Related