lundi 24 juillet 2017

Junit Testing mock a service and filter results

I want to test the following function (Junit test). I am using Mockito to mock Dynamodao service (It gets items from dynamodb). I am filtering the items based on the owner name.

owner = this.getUser(httpRequest);
List<MapData> result = this.dynamoDao.getAllRecords(TABLE_NAME, Regions.US_WEST_2);
List<MapData> result1 = result.stream().filter(x -> owner.equals(x.getOwner()))
                            .collect(Collectors.toList());

Here MapData is a class which has Owner as a dynamodbattribute. I read about Mockito and realised that I would need it to mock the service.

@Mock
private DynamoDao dynamoDao;

How can I test this simple function? I could really use some help on how to proceed. How can I use "when" here? I tried going through sample codes online but did not understand much.

Aucun commentaire:

Enregistrer un commentaire