MockSpec<T> constructor

const MockSpec<T>({
  1. Symbol? as,
  2. @Deprecated('Avoid adding concrete implementation to mock classes. ' 'Use a manual implementation of the class without `Mock`') List<Type> mixingIn = const [],
  3. Set<Symbol> unsupportedMembers = const {},
  4. Map<Symbol, Function> fallbackGenerators = const {},
  5. OnMissingStub? onMissingStub,
})

Constructs a custom mock specification.

Specify a custom name with the as parameter.

If onMissingStub is specified as OnMissingStub.returnDefault, a real call to a mock method (or getter) will return a legal value when no stub is found.

If the class-to-mock has a member with a non-nullable unknown return type (such as a type variable, T), then mockito cannot generate a valid override member, unless the member is specified in unsupportedMembers, or a fallback implementation is given in fallbackGenerators.

For each member M in unsupportedMembers, the mock class will have an override that throws, which may be useful if the return type T of M is non-nullable and it's inconvenient to define a fallback generator for M, e.g. if T is an unknown type variable. Such an override cannot be used with the mockito stubbing and verification APIs, but makes the mock class a valid implementation of the class-to-mock.

Each entry in fallbackGenerators specifies a mapping from a method name to a function, with the same signature as the method. This function is used to generate fallback values when a non-null value needs to be returned when stubbing or verifying. A fallback value is not ever exposed in stubbing or verifying; it is an object that mockito's internals can use as a legal return value.

Implementation

const MockSpec({
  Symbol? as,
  @Deprecated('Avoid adding concrete implementation to mock classes. '
      'Use a manual implementation of the class without `Mock`')
  List<Type> mixingIn = const [],
  this.unsupportedMembers = const {},
  this.fallbackGenerators = const {},
  this.onMissingStub,
})  : mockName = as,
      mixins = mixingIn;