У меня есть следующий класс:
public class FileLoader {
private Map<Brand, String> termsOfUseText = new HashMap<Brand, String>();
public void load() {
for (Brand brand : Brand.values()) {
readAndStoreTermsOfUseForBrand(brand);
}
}
private void readAndStoreTermsOfUseForBrand(Brand brand) {
String resourceName = "termsOfUse/" + brand.name().toLowerCase() + ".txt";
InputStream in = this.getClass().getClassLoader().getResourceAsStream(resourceName);
try {
String content = IOUtils.toString(in);
termsOfUseText.put(brand, content);
} catch (IOException e) {
throw new IllegalStateException(String.format("Failed to find terms of use source file %s", resourceName),e);
}
}
public String getTextForBrand(Brand brand) {
return termsOfUseText.get(brand);
}
}
Бренд - это перечисление, и мне нужно, чтобы все допустимые файлы .txt были в пути к классам. Как заставить IOException возникнуть, учитывая, что перечисление Brand содержит все действительные бренды и, следовательно, все файлы .txt для них существуют?
Предложения по рефакторингу текущего кода приветствуются, если он делает его более тестируемым!