jeudi 16 février 2017

How to mock DynamoDB with Mockito?

I got some code which already makes my DynamoDB instance mocked using PowerMockito like that:

@Mock
private DynamoDB dynamoDB;
 .....
PowerMockito.whenNew(DynamoDB.class).withAnyArguments().thenReturn(dynamoDB);

Our code coverage plugin doesn't like PowerMockito so he doesn't include these tests in the code coverage.

Due to that, now I need to use Mockito instead of PowerMockito.

I tried the following code below to make my DynamoDB mocked, but it failed:

DynamoDB mockedInstance = Mockito.mock(DynamoDB.class);
Mockito.doReturn(mockedInstance).when(carFactorySpy).carFactoryMethod("us-west-2");

Aucun commentaire:

Enregistrer un commentaire