Skip to content

[google_maps_flutter] Remove use of OCMock#10863

Merged
auto-submit[bot] merged 12 commits intoflutter:mainfrom
stuartmorgan-g:maps-ocmock-removal
Feb 4, 2026
Merged

[google_maps_flutter] Remove use of OCMock#10863
auto-submit[bot] merged 12 commits intoflutter:mainfrom
stuartmorgan-g:maps-ocmock-removal

Conversation

@stuartmorgan-g
Copy link
Collaborator

Eliminates usage of OCMock in the native iOS unit tests:

  • Creates a protocol for image asset loading that wraps that part of the registrar and the UIImage class method to replace mocking with injecting a protocol implementation.
  • Creates an abstract delegate for event reporting, instead of all of the sub-controllers communicating directly with the FlutterAPI instance.
  • Creates an abstract delegate for tile queries, instead of all of the tile controller communicating directly with the FlutterAPI instance.
  • Replaces mocking of our test subclass of the Google Maps view object with slightly more logic on that existing test subclass.
  • Replaces mocking of our existing protocols with simple manual fakes that lets us test the same assertions.
  • Eliminates static mock testing of GMSCameraUpdate.

Unblocks flutter/flutter#119108

Pre-Review Checklist

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the iOS native unit tests for google_maps_flutter by eliminating the use of OCMock. It introduces new protocols (FGMAssetProvider, FGMMapEventDelegate, FGMTileProviderDelegate) and their concrete implementations to allow for dependency injection, thereby improving testability. The changes include updating controller initializers to use these new delegates/providers and replacing OCMock-based test setups with custom fakes and direct assertions. The CHANGELOG.md and pubspec.yaml have been updated to reflect these changes. The refactoring is comprehensive and aligns well with the stated objective of improving testability.

// GMSCameraUpdate is not inspectable, so this test just ensures that the codepath
// doesn't throw. FGMGetCameraUpdateForPigeonCameraUpdate is simple enough that
// injecting a wrapper would not meaningfully improve test coverage, since the non-test
// implementation would be about as complex as the conversion function itself.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of changes is the only place where this PR actually removes test coverage. The only way to test this without the static class mock (the worst kind of OCMock mocking, so I would want to eliminate this even without OCMock being problematic for Swift migration) would be to make a factory protocol that wraps all of the static factor methods on GMSCameraUpdate.

I did seriously consider that, but the implementation being tested is almost as simple as the wrapper class we would need to write—by intentional design of FGMPlatformCameraUpdate being a direct parallel of GMSCameraUpdate. That wrapper class wouldn't be testable, so it felt like it would be improving test coverage on paper without meaningfully adding any real coverage.

If anyone feels strongly the other way, I can add the wrapper.

@stuartmorgan-g
Copy link
Collaborator Author

(Ideally I would have done this before #10852 rather than after, but I didn't think about that until it was too late. Once #10852 it'll be easy to sync this change across all the copies before landing this.)

zoomLevel:nil]
withMapView:[GoogleMapsGroundOverlayControllerTests mapView]
registrar:nil
assetProvider:[[TestAssetProvider alloc] init]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be a non-nullable parameter (IIRC I fix all the missing NS_ASSUME_NONNULL_BEGIN in test headers in a follow-up PR I have ready; I didn't notice them in this one).

Historically we have a lot of places where we play fast and loose in tests with passing nil in places that are (explicitly declared or just assumed in implementations) non-nullable, which generally works because Obj-C, but it makes Swift migrations more painful. So I tried to provide stubs instead of taking shortcuts.

Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple small comments

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 4, 2026
@auto-submit auto-submit bot merged commit f3ee98a into flutter:main Feb 4, 2026
81 checks passed
@stuartmorgan-g stuartmorgan-g deleted the maps-ocmock-removal branch February 4, 2026 14:56
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2026
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Feb 4, 2026
flutter/packages@5b1bea8...3bddf2c

2026-02-04 ivan-vanyusho@yandex-team.ru [camera_avfoundation] ios saving
path (flutter/packages#10832)
2026-02-04 stuartmorgan@google.com [video_player] Remove OCMock
(flutter/packages#10932)
2026-02-04 stuartmorgan@google.com [google_maps_flutter] Remove use of
OCMock (flutter/packages#10863)
2026-02-04 32538273+ValentinVignal@users.noreply.github.com
[go_router_builder] Add support for `@TypedGoRouteParameter` to
customize parameter names (flutter/packages#10793)
2026-02-03 engine-flutter-autoroll@skia.org Roll Flutter from
c305f1f to bf701fe (9 revisions) (flutter/packages#10957)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: google_maps_flutter platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants