STAssertThrows
throws an exception if the expression does not throw an exception.
The setDelegate method of StackOverflowManager is -
- (void)setDelegate:(id<StackOverflowManagerDelegate>)newDelegate {
if (newDelegate && ![newDelegate conformsToProtocol: @protocol(StackOverflowManagerDelegate)]) {
[[NSException exceptionWithName: NSInvalidArgumentException reason: @"Delegate object does not conform to the delegate protocol" userInfo: nil] raise];
}
delegate = newDelegate;
}
As NSNull does not conform to the StackOverflowManagerDelegate
protocol, the setter will throw an exception. STAssertThrows
will trap that exception and the test passes. If the setter did not throw an exception, then STAssertThrows
will throw an exception and the test will fail