|
SimpleExceptionTest
Dealing with Exceptions in jSupervisor.
The source for this discussion is available in SimpleExceptionTest.java This examples shows how jSupervisor deals with exceptions. There are two test methods:
testAuthentication_successful. This test case test is for succssful detection of expected exception. 1. Specifier spec = supervisor.getSpecifier() ;
2. spec.excepts(new ConnectionException("Cannot connect well."));
3. myAuthenticationServer.connect("foo"); The expected excaption is declared in Line 2. It will be thrown by the invocation declared in Line 3. This is a valid sequence and the scenario plays out to completion. testAuthentication_unsuccessful. This test case is for successful detection of incorrect exception. 1. Specifier spec = supervisor.getSpecifier() ;
2. spec.excepts(new Exception("Unexpected Exception."));
3. myAuthenticationServer.connect("foo"); Line 2 here expects an exception of class Exception which will not be the actual exception thrown. This results in an execution failure and the scenario cannot run till completion. |