If you're testing a method invocation on an instance of type FileClass
, don't mock the instance. Just create an actual instance and call the method.
@Test(expected = ClassNotFoundException.class)
public void testFuncB() throws ClassNotFoundException {
FileClass fc = new FileClass();
fc.funcB();
}
Mocking is meant for things that you know ([would]) work but don't want to setup.
As @dzezzz states in the comments, a ClassNotFoundException
(is that really the exception you want to test?) could be thrown in the FileClass
constructor. If that is not something that should happen and that you want to test, you can set up the following test so that it is only expected from the method invocation
@Rule
public ExpectedException exception = ExpectedException.none();
@Test()
public void testFuncB() throws ClassNotFoundException {
FileClass fc = new FileClass();
exception.expect(ClassNotFoundException.class);
fc.funcB();
}
The test will pass only if a ClassNotFoundException
is thrown after the ExpectedException#expect()
call.