So I wonder if kosher use a static initializer
The funny thing is that
private static final boolean subscribed = subscribe();
and
private static final boolean subscribed; static { subscribed = subscribe(); }
Get the exact same bytecode compiled. Therefore, the use of an unnecessary static variable is strictly worse.
But until weβre ready to scale to a DI-driven framework,
Open Guice . Do not call it a framework (although it is). It is easy to use and allows you to get rid of static .
Or do it manually. Rewrite your class by dropping all static modifiers and passing them wherever needed. This is pretty verbose, but specifying dependencies explicitly allows you to test classes in isolation.
Be that as it may, you cannot test StratBand without getting into the database, no matter how trivial the test method is. The problem is combining each instance of StratBand with a list of all StratBand s.
In addition, you cannot check the behavior depending on the contents of stratBands , since it is always loaded from the database (of course, you can populate your database accordingly, but this is a big pain).
First, I would create a StratBandManager (or stratBands or any other name) and move all the static functions. To facilitate the transition, I would create a temporary class with static helpers, for example
private static StratBandManager stratBandManager = new StratBandManager(); public static ImmutableList<StratBand> stratBands() { return stratBandManager.stratBands(); }
Then discount it all and replace it with DI (using Guice or do it manually).
I find Guice useful even for small projects. The overhead is tiny, because often there is little or no configuration.