repeat
Class: matlab.mock.actions.ThrowException
Namespace: matlab.mock.actions
Repeat throwing exception
Syntax
repeat(action,n)
Description
repeat(
repeats the same action action
,n
)n
times. You can specify the input arguments
in any order. That is, repeat(action,n)
and
repeat(n,action)
both repeat the action n
times.
Input Arguments
Examples
Tips
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),ThrowException().repeat(2)) 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), ... ThrowException().repeat(2).then(AssignOutputs(false))) tf = mock.IsJointAccount tf = mock.IsJointAccount tf = mock.IsJointAccount
Version History
Introduced in R2017a