Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.59k stars 593 forks source link

Test improvement: removed Magic Number test smell #364

Closed gvma closed 4 years ago

gvma commented 4 years ago

This is a test refactoring

Problem: The Magic Number Test occurs when assert() statements in a test method contain numeric literals (i.e., magic numbers) as parameters.

Solution: As magic numbers do not indicate the meaning/purpose of the number, they should be replaced with constants or variables, thereby providing a descriptive name for the input.

Before: assertEquals(200, i.getStatus());

After: private final int HTTP_STATUS_OK = 200; assertEquals(HTTP_STATUS_OK, i.getStatus());

gvma commented 4 years ago

Hi @ryber.

Thanks for the reply.

As you recommended, I have implemented a constant class that lists all status code.