repeat

Class: matlab.mock.actions.StoreValue
Package: matlab.mock.actions

Repeat same action multiple times

Syntax

repeat(n,action)

Description

repeat(n,action) repeats the same action multiple times.

Input Arguments

expand all

Number of times to repeat action, specified as an integer.

Example: 5

Defined action, specified as an instance of matlab.mock.actions.StoreValue.

Examples

expand all

Create a mock for a bank account class.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mock,behavior] = testCase.createMock('AddedProperties',"IsOpen");

Specify behavior. Allow the IsOpen property to be set twice, then throw an exception.

import matlab.mock.actions.StoreValue
import matlab.mock.actions.ThrowException
when(set(behavior.IsOpen),then(repeat(2,StoreValue), ...
    then(ThrowException(MException('Account:setValue:tooMany', ...
    'Value set too many times.')))));

Use the mock.

for i = 1:3
    mock.IsOpen = i
end
mock = 

  Mock with properties:

    IsOpen: 1


mock = 

  Mock with properties:

    IsOpen: 2

Error using matlab.mock.internal.MockContext>mockPropertySetCallback (line 706)
Value set too many times.

Error in matlab.mock.internal.MockContext>@(name,obj,value)mockPropertySetCallback(name,obj,value,catalog)
(line 284)
            propertySetCallback = @(name, obj, value)mockPropertySetCallback(name, obj, value, catalog);

Introduced in R2017a