4 ms·
Right, I mean, if you need to mock it a singleton would be a better choice; that's kind of the point of the pattern. Personally, though, I feel like if you fre
by emodendroket 5y ago
Right, I mean, if you need to mock it a singleton would be a better choice; that's kind of the point of the pattern. Personally, though, I feel like if you frequently find yourself needing to mock these static classes, then they're not really as effective at avoiding statefulness as you claim -- if they're side effect-free, it should be safe to just use the implementation.
- Supermancho 5y agoYou need to mock them because you are asserting that it is the correct thing to use. Verification testing has nothing to do with state, per se. Having a static instance a wrapper just to use another static is java forcing unnecessary state. Forcing a singleton to instance another singleton at runtime is idiotic, which is why spring proponents avoid it and java is still a syntactical dinosaur. When we see proper modules (including static refs), java will be better fir it. PHP is better with how it deals with statics today, which bleeds into other areas like testing.