Main Content

matlab.mock.actions.DoNothing Class

Namespace: matlab.mock.actions

Take no action

Since R2020a

Description

Use the matlab.mock.actions.DoNothing class to specify that the framework takes no action when a mock object method is invoked or when a mock object property is set.

DoNothing cannot be used to set up behavior when accessing a mock object property. To specify that a mock property must not be accessed, use the matlab.mock.actions.ThrowException class.

Creation

action = matlab.mock.actions.DoNothing creates a DoNothing object.

Methods

expand all

Examples

collapse all

Create a mock for a bank account class.

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

Set up behavior. Take no action if the IsOpen property is set to a value that is not of type logical.

import matlab.mock.actions.DoNothing
import matlab.unittest.constraints.IsInstanceOf
when(setToValue(behavior.IsOpen,~IsInstanceOf('logical')),DoNothing)

Use the mock to set IsOpen to a nonlogical value. No action is taken and IsOpen is left unset.

mock.IsOpen = 'Y'
mock = 
  Mock with properties:

    IsOpen: []

Use the mock to set IsOpen to a logical value.

mock.IsOpen = true
mock = 
  Mock with properties:

    IsOpen: 1

Version History

Introduced in R2020a