Main Content

then

Class: matlab.mock.actions.AssignOutputs
Namespace: matlab.mock.actions

Action for mock object interaction or action subsequent to defining return values

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

Example: action1 = AssignOutputs(true)

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

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

Example: action2 = DoNothing

Example: action2 = ThrowException

Examples

expand all

Create a mock for a bank account class.

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

Set up behavior to return true, true, and then false.

import matlab.mock.actions.AssignOutputs;
when(withExactInputs(behavior.isOpen), ...
    AssignOutputs(true).then(AssignOutputs(true)).then(AssignOutputs(false)))

Use the mock.

isAccountOpen = mock.isOpen
isAccountOpen = logical
   1

isAccountOpen = mock.isOpen
isAccountOpen = logical
   1

isAccountOpen = mock.isOpen
isAccountOpen = logical
   0

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