Main Content

matlab.mock.actions.DoNothing class

Package: matlab.mock.actions

Take no action

Description

Use the 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 = DoNothing constructs an instance of the DoNothing class and returns the instance in action.

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

Introduced in R2020a