diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-02-23 08:53:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 08:53:37 -0500 |
commit | 0703cf1f49c7ad8b2bee7a958fa4734376551b62 (patch) | |
tree | ebf3116a329fb705e975d15bdad8f3e28e2c506d | |
parent | a284bdfc1e92ef7e5048fb8d5b1364885bd6ee01 (diff) | |
parent | 77c1a96a29d9322c599572335149e3e11231788e (diff) | |
download | sdl_ios-0703cf1f49c7ad8b2bee7a958fa4734376551b62.tar.gz |
Merge pull request #544 from smartdevicelink/hotfix/issue_543
Improve description of state machine exception throw
-rw-r--r-- | SmartDeviceLink/SDLStateMachine.m | 6 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLStateMachineSpec.m | 9 |
2 files changed, 11 insertions, 4 deletions
diff --git a/SmartDeviceLink/SDLStateMachine.m b/SmartDeviceLink/SDLStateMachine.m index ab5c54689..2d197344d 100644 --- a/SmartDeviceLink/SDLStateMachine.m +++ b/SmartDeviceLink/SDLStateMachine.m @@ -62,9 +62,11 @@ SDLStateMachineTransitionFormat const SDLStateMachineTransitionFormatDidEnter = } if (![self sdl_canState:self.currentState transitionToState:state]) { + NSString *targetClassString = NSStringFromClass([self.target class]); + NSString *reasonMessage = [NSString stringWithFormat:@"Invalid state machine %@ transition of target %@ occurred from %@ to %@", NSStringFromClass(self.class), targetClassString, self.currentState, state]; @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"Invalid state machine transition occurred" - userInfo:@{SDLStateMachineExceptionInfoKeyTargetClass: NSStringFromClass([self.target class]), + reason:reasonMessage + userInfo:@{SDLStateMachineExceptionInfoKeyTargetClass: targetClassString, SDLStateMachineExceptionInfoKeyFromState: self.currentState, SDLStateMachineExceptionInfoKeyToClass: state}]; } diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStateMachineSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStateMachineSpec.m index d657586e5..af851d09b 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStateMachineSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStateMachineSpec.m @@ -121,11 +121,14 @@ describe(@"A state machine", ^{ }); it(@"should throw an exception trying to transition incorrectly and nothing should be called", ^{ + NSString *stateMachineClassString = NSStringFromClass(testStateMachine.class); + NSString *targetClassString = NSStringFromClass(testTarget.class); + // Side effects, but I can't think of any other way around it. expectAction(^{ [testStateMachine transitionToState:thirdState]; - }).to(raiseException().named(NSInternalInconsistencyException)); - + }).to(raiseException().named(NSInternalInconsistencyException).reason([NSString stringWithFormat:@"Invalid state machine %@ transition of target %@ occurred from %@ to %@", stateMachineClassString, targetClassString, initialState, thirdState]).userInfo(@{@"fromState": initialState, @"toState": thirdState, @"targetClass": targetClassString})); + expect(@([testStateMachine isCurrentState:initialState])).to(equal(@YES)); expect(@([testStateMachine isCurrentState:thirdState])).to(equal(@NO)); expect(@(willLeaveNotificationCalled)).to(equal(@NO)); @@ -141,4 +144,6 @@ describe(@"A state machine", ^{ }); }); +// Invalid state machine transition of TestStateMachineTarget occurred from Initial to Third + QuickSpecEnd |