%% Take No Action When Data Type Is Invalid
% 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'

% Use the mock to set IsOpen to a logical value.

mock.IsOpen = true

% Copyright 2019 The MathWorks, Inc.