then

Class: matlab.mock.actions.AssignOutputs
Package: matlab.mock.actions

Specify action

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: AssignOutputs(true)

Example: AssignOutputs(7,13,42)

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

Example: AssignOutputs(7,13,42)

Example: 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),then(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 then(action1,then(action2,action3)).

Introduced in R2017a