I tried to make a junit test for my class, I would like to Mock my Cache variable when calling the methot "get". My variable cache is an instance of CacheManger who call my database. But i don't know how to test my method. anyone got an idea ? Thank's for your answer !
private static Cache<String, Integer> cache;
private static final String QUERY = "EXEC myQuery";
public static Integer getLanguageId(String language) {
if (language == null) {
return null;
}
Integer languageId = cache.get(language);
if (languageId == null) {
throw new Exception();
}
return languageId;
}
static void configureCache() {
if (cache == null) {
//CacheManager call database
cache = CacheManager.getInstance()
.createCache(QUERY, new RuleConfigurer.StringAndIntegerRowMapper());
}
}