【发布时间】:2016-04-28 01:24:19
【问题描述】:
我想测试properties.load(in) 方法抛出的IOException 和IllegalArgumentException。根据 OracleDoc 此处的文档,它说加载方法会抛出 IOException - 如果从输入流读取时发生错误。 IllegalArgumentException - 如果输入流包含格式错误的 Unicode 转义序列。
这是我的代码:
public class PropertiesRetriever {
private String foo;
private String foo1;
private Properties properties;
/**
* Injects the properties file Path in the {GuiceModule}
* Calls {@link PropertiesRetriever#loadPropertiesPath(String) to load the
* properties file.
*/
@Inject
public PropertiesRetriever(@Named("propertiesPath") String propertiesPath, Properties properties)
throws IOException {
this.properties = properties;
loadPropertiesPath(propertiesPath);
}
/**
* Loads the properties file as inputstream.
*
*/
public void loadPropertiesPath(String path) throws IOException {
InputStream in = this.getClass().getResourceAsStream(path);
properties.load(in);
}
这里是一个方法:
properties.load(in)
抛出 IOException 和 IllegalArgumentException。我想在 JUnit 测试中测试这种方法。无论如何我可以调用这些方法。
【问题讨论】:
标签: java android inputstream junit4