Patterns or practices for unit testing methods that call a static method

Using dependency injection (either option 2 or 4) is definitely my preferred method of attacking this. Not only does it make testing easier it helps to separate concerns and keep classes from getting bloated. A clarification I need to make though is it is not true that static methods are hard to test. The problem … Read more

How to inherit static methods from base class in JavaScript?

In the classical (OO) inheritance pattern, the static methods do not actually get inherited down. Therefore if you have a static method, why not just call: SuperClass.static_method() whenever you need it, no need for JavaScript to keep extra references or copies of the same method. You can also read this JavaScript Override Patterns to get … Read more

Quick Java question about private static final keywords for fields

I use Checkstyle with Eclipse, which results in a warning if the declaration is in a different order to the one you’ve specified, citing the Java Language Specification (JLS). For example, private final static String filename = “filename.txt”; results in ‘static’ modifier out of order with the JLS suggestions. They have this page which lists … Read more

Creating static Mac OS X C build

It is not supported in Mac OS X’s gcc: http://discussions.apple.com/message.jspa?messageID=11053384 Perhaps that “-static” flag flat out won’t work on MacOS X. Not all features of gcc are implemented on MacOS X. Apple won’t even be using gcc in future versions of the OS. I don’t know how to link using “-static”. I can’t think of … Read more

Use dependency injection in static class

You basically have two options: Change the class from static to an instance class and supply the dependency through Constructor Injection. Supply the dependency to the class’s public method through Method Injection. Here are examples for each option. Option 1. Change the class from static to an instance class Change the class from static to … Read more