Search code examples
javaunit-testingcompiler-errorsmockitoaws-java-sdk

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


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?


Solution

  • Syntax of brackets is wrong.

    Correct Syntax:

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