Main Content

then

クラス: matlab.mock.actions.StoreValue
名前空間: matlab.mock.actions

モック オブジェクトの相互作用のアクション、またはプロパティ値の格納の後のアクション

構文

then(action1)
then(action1,action2)

説明

then(action1) は、モック オブジェクトの相互作用のアクションを指定します。

then(action1,action2) は、モック オブジェクトの相互作用のアクションとその次のアクションを指定します。

入力引数

すべて展開する

定義済みのアクション。matlab.mock.actions.StoreValue のインスタンスとして指定します。

2 番目の定義済みのアクション。matlab.mock.actions.DoNothing、または matlab.mock.actions.ThrowException のインスタンスとして指定します。

例: action2 = DoNothing

例: action2 = ThrowException(MException('Account:deposit:Negative','Deposit amount must be positive.'))

すべて展開する

銀行口座クラスのモックを作成します。

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

動作を指定します。IsOpen プロパティを 1 回設定できるようにし、例外をスローします。

import matlab.mock.actions.StoreValue
import matlab.mock.actions.ThrowException
when(set(behavior.IsOpen),StoreValue().then(ThrowException( ...
    MException('Account:setValue:tooMany','Value set too many times.'))))

モックを使用します。

mock.IsOpen = false
mock = 

  Mock with properties:

    IsOpen: 0
mock.IsOpen = true
Error using matlab.mock.internal.MockContext/createMockObject/mockPropertySetCallback (line 429)
Value set too many times.

ヒント

  • then の呼び出しはそれぞれ最大 2 つのアクションを受け入れます。後続のアクションをさらに多く指定するには、then を複数回呼び出します。たとえば、3 つのアクションを指定するには action1.then(action2).then(action3) を使用します。

バージョン履歴

R2017a で導入