Skip to content

Instantly share code, notes, and snippets.

@martinsson
Last active January 3, 2019 15:12
Show Gist options
  • Save martinsson/c1371d6f2b872b5aeba71f98f48bfb77 to your computer and use it in GitHub Desktop.
Save martinsson/c1371d6f2b872b5aeba71f98f48bfb77 to your computer and use it in GitHub Desktop.
Full code of an offending class using a database query in it's static initialiser
public class UnTestableDependency {
private static Map<String, Object> translationMap;
static {
translationMap = HibernateUtil.executeQuery("Select ...");
}
// this static method is called by the class you'd like to test
public static String getTranslation(String key, Locale locale) {
Object keys = translationMap.get(locale.toString());
// logic ...
// etc ...
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment