All of Mock's fields should be final #201
Labels
P2
A bug or feature request we're likely to work on
S2
type-enhancement
A request for a change that isn't a bug
#200 Really just inspired in me the idea that Mock should only have final fields; i.e. it should be able to satisfy the @immutable contract if needed (it should be immutable-able 😛). And looking at the existing fields, this should be possible:
The top-level
named
API sets two private fields on Mock objects:_givenName
and_givenHashCode
. These two are used to overridetoString()
andhashCode
respectively. However, they are not much used, and they could be declared with standardwhen
stubbing, or could be specified as optional arguments to the Mock constructor.The Mock class allows users to override default stub behavior via the
_defaultResponse
member. This has basically only two uses today:throwOnMissingStub
to override this null-returning behavior with throwing behavior. We have MakethrowOnMissingStub
the default (eventually) #154 open to make this the default behavior.This behavior could 100% be overridden with an optional constructor parameter.
So all three of the non-final fields could be made final without too much ceremony; it would be a breaking change to remove the
named
andthrowOnMissingStub
APIs, but we can introduce the new APIs (constructor parameters) before bumping a major version.The text was updated successfully, but these errors were encountered: