Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit test
  • Loading branch information
Emmanuel Garcia committed May 24, 2022
commit 28ae948e21b8ea00f3c01a8259d4fae0c5c2ecdc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
Expand Down Expand Up @@ -110,6 +111,11 @@ public View getView() {
return mapView;
}

@VisibleForTesting
/*package*/ void setView(MapView view) {
mapView = view;
}

void init() {
lifecycleProvider.getLifecycle().addObserver(this);
mapView.getMapAsync(this);
Expand Down Expand Up @@ -272,19 +278,23 @@ public void onSnapshotReady(Bitmap bitmap) {
// To workaround this limitation, wait two frames.
// This ensures that at least the frame budget (16.66ms at 60hz) have passed since the
// drawing operation was issued.
googleMap.setOnMapLoadedCallback(
new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
postFrameCallback(
() -> {
postFrameCallback(
() -> {
mapView.invalidate();
});
});
}
});
if (googleMap != null) {
googleMap.setOnMapLoadedCallback(
new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
postFrameCallback(
() -> {
postFrameCallback(
() -> {
if (mapView != null) {
mapView.invalidate();
}
});
});
}
});
}

result.success(null);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.plugins.googlemaps;

import static org.mockito.Mockito.verify;
import static org.mockito.ArgumentMatchers.any;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

Expand All @@ -12,15 +14,21 @@
import androidx.activity.ComponentActivity;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import io.flutter.plugin.common.BinaryMessenger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.HashMap;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodCall;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = Build.VERSION_CODES.P)
Expand Down Expand Up @@ -58,4 +66,19 @@ public void OnDestroyReleaseTheMap() throws InterruptedException {
googleMapController.onDestroy(activity);
assertNull(googleMapController.getView());
}

@Test
public void InvalidateMapAfterMarkersUpdate() throws InterruptedException {
googleMapController.onMapReady(mockGoogleMap);
MethodChannel.Result result = mock(MethodChannel.Result.class);
googleMapController.onMethodCall(new MethodCall​("markers#update", new HashMap<String, Object>()), result);

ArgumentCaptor<GoogleMap.OnMapLoadedCallback> argument = ArgumentCaptor.forClass(GoogleMap.OnMapLoadedCallback.class);
verify(mockGoogleMap).setOnMapLoadedCallback(argument.capture());

MapView mapView = mock(MapView.class);
googleMapController.setView(mapView);
argument.getValue().onMapLoaded();
verify(mapView).invalidate();
}
}