Last active
January 3, 2019 15:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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