Q:

Unable to test exception with junit

I have a method which 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 the exception is thrown is to log it, and that all works great, however, how can I create a test that shows that it works?
I tried to capture console output and 
assertTrue(consoleOutput.contains("logMessgae") 

and that worked as long as I ran only that specific test case, but it did not work when I ran it in my test suite.

A:

The contract of the method is to catch CustomException and log "Error Message" to an external component : the logger. You should thus create a mock logger, give it to the ClassToTest instance, test the method and verify that the mock logger has been called with the aright arguments. 
I personnally use EasyMock (and its "classextension" extension) to mock concrete classes, but there are other mock frameworks. Read http://easymock.org/EasyMock3_0_Documentation.html for information about EasyMock and mocking in general.

