Main Content

then

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

Action for mock object interaction or action subsequent to returning stored property value

Syntax

then(action1)
then(action1,action2)

Description

then(action1) specifies an action for mock object interactions.

then(action1,action2) specifies an action and a subsequent action for mock object interactions.

Input Arguments

expand all

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

Second defined action, specified as an instance of matlab.mock.actions.AssignOutputs, or matlab.mock.actions.ThrowException.

Example: action2 = ReturnStoredValue

Example: action2 = AssignOutputs(7,13,42)

Example: action2 = ThrowException

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);

Set up behavior to return empty once and then true.

import matlab.mock.actions.ReturnStoredValue
import matlab.mock.actions.AssignOutputs
when(get(behavior.isOpen),ReturnStoredValue().then(AssignOutputs(true)))

Use the mock.

isAccountOpen = mock.isOpen
isAccountOpen =

     []
isAccountOpen = mock.isOpen
isAccountOpen = logical
   1

isAccountOpen = mock.isOpen
isAccountOpen = logical
   1

Tips

  • Each call to then accepts up to two actions. To specify more subsequent actions, use multiple calls to then. For example, to specify three actions, use action1.then(action2).then(action3).

Version History

Introduced in R2017a