Beware of Incorrect Usage in Accessor Methods
When people have looked at my code, specifically my test code, one of the most common things they ask is why I test my getters and setters. They see this as a weird thing to do, but I tend to be a very paranoid defensive programmer, so I like to ensure that my getters and setters aren’t actually modifying anything. “That is paranoid, Scott” you proclaim, and try to enlighten me on all the code that doesn’t modify accessor methods. But I’ve been burned by this assumption often, and a simple and stupid unit test ensures that the code is adhering to my assumptions. It’s quick and painless. ...