matlab.mock.constraints.WasAccessed class
Package: matlab.mock.constraints
Constraint determining property get access
Description
The WasAccessed
constraint produces a qualification
failure if an actual value is not a PropertyBehavior
instance,
or if the property that corresponds to the PropertyBehavior
was
not accessed the specified number of times.
The number of times a property is accessed includes the number
of times that MATLAB® implicitly accesses the property. For example,
if you display a mock object, MATLAB accesses the object properties
to display their values.
Construction
constraint = WasAccessed
provides a constraint
that determines the property get access. If a property was accessed
at least once, the constraint is satisfied. To qualify that a property
was not accessed, negate the WasAccessed
constraint
with the tilde (~
) operator.
constraint = WasAccessed('WithCount',n
)
provides
a constraint that is satisfied when a property was accessed exactly n
times.
If you negate WasAccessed
with this syntax, if
the property was not accessed exactly n
times,
the constraint passes. For example, if a property was accessed 4 times, ~WasAccessed('WithCount',3)
passes
and ~WasAccessed('WithCount',4)
fails.
Input Arguments
expand all
n
— Number of times of property get access
integer
Number of times of property get access, specified as an integer.
Properties
expand all
Count
— Property access count
integer
Property access count, returned as an integer. This property
is read-only once the constraint is constructed. You can specify it
during constraint construction.
Copy Semantics
Value. To learn how value classes affect copy
operations, see Copying Objects.
Examples
collapse all
Qualify Mock Property Get Access
Create a mock for a person class.
The person's name is David.
Construct passing cases.
Interactive verification passed.
Interactive verification passed.
Interactive verification passed.
Construct failing cases.
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
Negated WasAccessed failed.
--> Property 'Name' was unexpectedly accessed 1 time(s).
Specified property access:
PropertyGetBehavior
<Mock>.Name
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
WasAccessed failed.
--> Property 'Age' was never accessed.
Specified property access:
PropertyGetBehavior
<Mock>.Age
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
WasAccessed failed.
--> Property 'Name' was not accessed the expected number of times.
Actual property access count:
1
Expected property access count:
5
Specified property access:
PropertyGetBehavior
<Mock>.Name
Introduced in R2017a