I wanted to test the IOException
and IllegalArgumentException
thrown by properties.load(in)
method. As per the documentation here OracleDoc it says the load method throws IOException
- if an error occurred when reading from the input stream. IllegalArgumentException
- if the input stream contains a malformed Unicode escape sequence.
Here is my code:
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);
}
Here, a method:
properties.load(in)
throws IOException
and IllegalArgumentException
. I wanted to test this methods in JUnit testing. Is there anyway I can call these methods.