%% Assign Repeating Outputs to Mock
% Create a mock for a class that represents a 12-sided die, including a mocked roll method.

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

% Set up behavior for the roll method to return the value from the randi function twice and then return 0.

import matlab.mock.actions.AssignOutputs
import matlab.mock.actions.Invoke

when(withExactInputs(behavior.roll), ...
    Invoke(@(~)randi(12)).repeat(2).then(AssignOutputs(0)))

% Call the mocked roll method four times.

val = mock.roll
val = mock.roll
val = mock.roll
val = mock.roll

% Copyright 2019 The MathWorks, Inc.