Main Content

repeat

Class: matlab.mock.actions.ReturnStoredValue
Namespace: matlab.mock.actions

Repeat returning stored property value

Syntax

repeat(action,n)

Description

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.ReturnStoredValue.

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

Example: 5

Examples

expand all

Create a strict mock for a bank account class.

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

Specify behavior. Return the stored property value, which is empty by default, twice and then assign an output of false.

import matlab.mock.actions.ReturnStoredValue
import matlab.mock.actions.AssignOutputs
when(get(behavior.isOpen), ...
    ReturnStoredValue().repeat(2).then(AssignOutputs(false)))

Use the mock.

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

     []


isOpen =

     []
isOpen = logical
   0

Version History

Introduced in R2017a