Class: matlab.mock.actions.ThrowException
Package: matlab.mock.actions
Repeat throwing exception
repeat(n,action)
If you repeat an action, and do not follow it with
a call to the then
method, the mock continues to
return the repeated value. For example, consider the following mock
of a bank account class.
import matlab.mock.actions.ThrowException testCase = matlab.mock.TestCase.forInteractiveUse; [mock, behavior] = testCase.createMock('AddedProperties',"IsJointAccount");
If you repeat an action to throw an exception twice, the framework continues to throw an exception in the following code, which goes on to get the property value a third time.
when(get(behavior.IsJointAccount),then(repeat(2,ThrowException))); tf = mock.IsJointAccount tf = mock.IsJointAccount tf = mock.IsJointAccount
But the following code throws an exception twice and the returns false
.
import matlab.mock.actions.AssignOutputs when(get(behavior.IsJointAccount),then(repeat(2,ThrowException), ... then(AssignOutputs(false)))); tf = mock.IsJointAccount tf = mock.IsJointAccount tf = mock.IsJointAccount