I am trying to improve the test coverage, but I am confused about some lines that are considered as "not covered" or "only partially covered" such as:
400 -> throw BadRequestException(response.code(), response.errorBody()?.string())
and
if (response.code() !in 200..299) {
throwError(response)
}
throwError is a private function. I am testing that, with a response code 204, there is a success event and 400, there is the right error that is thrown. But how to check that throwError is called?
Also, when I check that the error BadRequestException is thrown, why only 1 or 2 conditions are met?
CodePudding user response:
In the first case, the two conditions should be:
response.errorBody()
isnull
response.errorBody()
is notnull
So you need to cover both to have it completely covered.