Main Content


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

Repeat storing property value




repeat(action,n) repeats the same action 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

expand all

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

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

Example: 5


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),StoreValue().repeat(2).then(ThrowException( ...
    MException('Account:setValue:tooMany','Value set too many times.'))))

Use the mock.

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

  Mock with properties:

    IsOpen: 1

mock = 

  Mock with properties:

    IsOpen: 2

Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 429)
Value set too many times.

Version History

Introduced in R2017a