%% Specify Mock Property Set Behavior
% Create a strict mock for a person class.  The mock has one property, Name.

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

% Set up the behavior.  When the property is set, store the value, and when the property is accessed, return the value.  Without defining this behavior, strict mocks throw an exception when setting or accessing the property.

import matlab.mock.actions.StoreValue
import matlab.mock.actions.ReturnStoredValue
when(set(behavior.Name),StoreValue)
when(get(behavior.Name),ReturnStoredValue)

% Set the property.  The property access is implicit because we are displaying the result.

mock.Name = "David"

% Copyright 2012 The MathWorks, Inc.