나는 인스턴스화되지 않고 정적 메서드로만 구성된 클래스가 있습니다. catch (IOException e) 부분을 제외하고 getProperty()의 모든 부분을 처리했지만 코드에 도달 할 수없는 것 같습니다. 코드의 신뢰할 수없는 부분
public class ResourceUtils
{
private static final String IOEXCEPTION_ERROR_MESSAGE = "ERROR: Problem reading StringBundles.properties";
private static final String PATH_STRING_BUNDLE = "com/qn/config/StringBundles.properties";
public static String getProperty(String key)
{
Properties property = new Properties();
try
{
property.load(ResourceUtils.class.getClassLoader().getResourceAsStream(PATH_STRING_BUNDLE));
}
catch(IOException e)
{
System.err.println(IOEXCEPTION_ERROR_MESSAGE);
e.printStackTrace();
return null;
}
return property.getProperty(key);
}
나는 어디 PATH_STRING_BUNDLE에서 유효 할 것이다 시나리오를 테스트하고 싶었 그것은 캐치 (IOException이 전자)를 통과 벽. 그러나 PATH_STRING_BUNDLE에는 최종 수정자가 있습니다. 이것을 테스트하는 방법을 제안 해 주시겠습니까? 아니면이 부분을 테스트하는 것이 꽤 쓸모 없거나 클래스의 디자인에 문제가있을 수 있습니다.
정말 도달 할 수 없다면,'throw new assertionError (e);'와 같은 것을 넣어서 나중에 도달 할 수있게되면 정말 명백합니다. – immibis