Code coverage failure inside Flux map method

Viewed 188

Sample code

Flux<Object> result=userMessagesDataStore.getByParamFilter(params)  ;
    result.map(r -> {
        UserMessageV1 v1 = (UserMessageV1) r;
        v1.setClientName("");
        return v1;
    });

For the above code unit test is working fine but when i check in sonar getting code coverage issue(Check the image for reference). Sonar cube analysis

Can anyone help me to resove this issue?

1 Answers

The lambda expression inside is not called. Use its return type and assign it back to the result variable, otherwise the transformed Flux is unused and the original one remains unchanged.

Flux<Object> result = userMessagesDataStore.getByParamFilter(params);
result = result.map(r -> {
    UserMessageV1 v1 = (UserMessageV1) r;
    v1.setClientName("");
    return v1;
});

Notice the Flux#map(Function) JavaDoc, particularly it's return type:

Returns: a transformed Flux

Related