Hi,
When accessing the createAddress I tell the mock to throw a ServletParseException but since the code under test ( see first code snippet below) after catching throw a SipScenarioExcpetion I guess that this is the exception that I shall catch in my test?
Also if I don't add a throws Exception in the test-method declaration the test code will complain that I am not handling the ServletParseException. Is it correct to add a throws Exception to my test-method?
Shall I use context.assertIsSatisfied() or assertNotNull("Exception was thrown"+sse.getReason()) for assert?
br,
//mikael
public void create(){
try {
toAddress = sipFactory.createAddress(address);
} catch (ServletParseException e) {
throw new SipScenarioException(Reason.PARSEERROR);
}
............
}
This is the test using Jmock 2:
@Test
public void testCreateWithParseError() throws Exception {
Home home = new Home();
try{
//Expectations
context.checking(new Expectations() {
{
.....
allowing(mockSipFactory).createAddress(SIP_ADDRESS);
will(throwException(new ServletParseException("Could not parse address!")));
}
});
home.create();
}catch (SipScenarioException sse){
assertNotNull("Exception was thrown"+sse.getReason());
}
}