Not sure how we simulate the IOException
with the current implementation but if you refactor the code in something like this:
public void loadProperties(String path) throws IOException {
InputStream in = this.getClass().getResourceAsStream(path);
loadProperties(in);
}
public void loadProperties(InputStream in) throws IOException {
Properties properties = new Properties();
properties.load(in);
this.foo = properties.getProperty("foo");
this.foo1 = properties.getProperty("foo1");
}
And create a mocked InputStream, something like this:
package org.uniknow.test;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
public class TestLoadProperties {
@test(expected="IOException.class")
public void testReadProperties() throws IOException {
InputStream in = createMock(InputStream.class);
expect(in.read()).andThrow(IOException.class);
replay(in);
// Instantiate instance in which properties are loaded
x.loadProperties(in);
}
}
WARNING: Created above code on the fly without verifying it by compiling so there might be syntax faults.