I have a method that contains a try-catch block, and I don't know how to make my test pass ...
Here is my code:
public class ClassToTest {
public void loadFileContent() {
try {
InputStream fileStream = fileLoader.loadFileContent();
fileContentReader = new BufferedReader(new InputStreamReader(fileStream));
} catch(CustomException ce) {
logger.log(Level.SEVERE, "Error message")
}
}
}
public class TestClassToTest {
@Test
(expected = CustomException.class)
public void testCustomException() throws Exception {
loadFileContent();
}
}
The only thing I want to do when an exception is thrown is to register it and it all works fine, how can I create a test that shows that it works?
I tried to capture the console output and
assertTrue(consoleOutput.contains("logMessgae")
and this continued until I ran only this specific test case, but it did not work when I ran it in my test suite.
source
share