Repository navigation
[mockito] Use an enum value for a sealed return type implemented by an enum - #5276
Open
AbdeldjalilChougui wants to merge 1 commit into
Open
AbdeldjalilChougui wants to merge 1 commit into
AbdeldjalilChougui wants to merge 1 commit into
Conversation
…n enum When a sealed class has no subclass that can be faked, look for an enum that implements it and use its first value as the returnValue passed to noSuchMethod while stubbing. A subclass that can be faked is still preferred. Follow-up to dart-lang#5264, part of dart-lang#4462.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #5264, as suggested in this review comment. Part of #4462.
#5264 fakes a subclass of a sealed class as the stubbing
returnValue, but it only looked at classes. If the only implementation of the sealed class is an enum:the generated mock still fell back to
dummyValue<Status>(), and stubbing threwMissingDummyValueError: StatuswithoutprovideDummy.With this change, when no subclass can be faked, the first value of an enum that implements the sealed class is used, the same way
_dummyValueImplementingalready handles enum return types:Details:
returnValueForMissingStubfor nice mocks is unchanged.Testing:
Future), subclass preferred over an enum, nested sealed class, generic enum skipped, and the nice-mock default. The enum-only, nested and nice-mock tests fail without the change.@GenerateMocks: the mocks compile andwhen(repo.status(1)).thenReturn(Simple.archived)passes, and it fails withMissingDummyValueError: Statuswithout this change.