%% Specify Method Call with Specific Number of Outputs
% Create a mock for a triangle class.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mockQuad,behavior] = testCase.createMock('AddedMethods',"sideLengths");

% Set up behavior. If the sideLengths method is called with only the object as input and with one output, then return an array of three values. If it is called with only the object as input and with three outputs, then return the three values. Otherwise, return the default value of an empty array.

import matlab.mock.actions.AssignOutputs
when(withNargout(1,withExactInputs(behavior.sideLengths)), ...
    AssignOutputs([1 2 3]))
when(withNargout(3,withExactInputs(behavior.sideLengths)), ...
    AssignOutputs(1,2,3))

% Call the sideLengths method with only the object as an input and one output.

len = mockQuad.sideLengths

% Verify that the sideLengths method was called at least once with one output argument.

import matlab.mock.constraints.WasCalled
testCase.verifyThat(withNargout(1, ...
    withExactInputs(behavior.sideLengths)),WasCalled)

% Verify that the sideLengths method was not called with three output arguments.

testCase.verifyThat(withNargout(3, ...
    withExactInputs(behavior.sideLengths)),~WasCalled)

% Copyright 2012 The MathWorks, Inc.