Wanted but not invoked. Actually, there were zero interactions with this mock. Kinesis.Worker AWS

Viewed 188

I have tried several things to solve this exception. This is an existent test in the application that I had never worked.

 import com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration;
import com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker;

@ExtendWith(MockitoExtension.class)
class TeamEventStreamWorkerTest {
    @Mock
    Worker worker;

    @Mock
    KinesisClientLibConfiguration kinesisClientLibConfiguration;

    @Test
    void onApplicationEvent() throws InterruptedException {
        TeamEventStreamWorker teamEventStreamWorker = new TeamEventStreamWorker(null, null, null, kinesisClientLibConfiguration, null) {
            Worker createDynamoDbStreamsWorker() {
                return worker;
            }
        };

        doNothing().when(worker).run();

        teamEventStreamWorker.onApplicationEvent(null);

        // Wait to make sure worker run is called by the async mechanism
        Thread.sleep(1000);

        verify(worker).run();

    }
}

I know the problem is with worker.run() method. worker and kinesis object are objects for the library of Kinesis from amazon.

Note: The most strange thing is when I test in my local machine(IntelliJ) works perfect, but when I do a push and the Jenkins job starts to try, always returns the same error.

1 Answers

Exception message you've received tells that worker.run() method was never called within your test. You could changes the set-up of increase sleeping time. The test passes as soon as worker.run() is called at least once.

Related