Skip to content
Merged
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
[google_maps_flutter_android] GoogleMapsController tests should mainl…
…y test the right constructor
  • Loading branch information
jokerttu committed Apr 30, 2024
commit 041b9925cb814751544ef55db78b2bb980e348df
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;
import com.google.maps.android.clustering.ClusterManager;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -42,9 +43,9 @@ public class GoogleMapControllerTest {

private Context context;
private ComponentActivity activity;
private GoogleMapController googleMapController;

AutoCloseable mockCloseable;
@Mock BinaryMessenger mockMessenger;
@Mock GoogleMap mockGoogleMap;
@Mock MethodChannel mockMethodChannel;
@Mock ClusterManagersController mockClusterManagersController;
Expand All @@ -59,7 +60,20 @@ public void before() {
mockCloseable = MockitoAnnotations.openMocks(this);
context = ApplicationProvider.getApplicationContext();
setUpActivityLegacy();
googleMapController =
}

// Returns GoogleMapController instance.
// See getGoogleMapControllerWithMockedDependencies for version with dependency injections.
public GoogleMapController getGoogleMapController() {
GoogleMapController googleMapController =
new GoogleMapController(0, context, mockMessenger, activity::getLifecycle, null);
googleMapController.init();
return googleMapController;
}

// Returns GoogleMapController instance with mocked dependency injections.
public GoogleMapController getGoogleMapControllerWithMockedDependencies() {
GoogleMapController googleMapController =
new GoogleMapController(
0,
context,
Expand All @@ -73,6 +87,7 @@ public void before() {
mockCirclesController,
mockTileOverlaysController);
googleMapController.init();
return googleMapController;
}

// TODO(stuartmorgan): Update this to a non-deprecated test API.
Expand All @@ -89,6 +104,7 @@ public void tearDown() throws Exception {

@Test
public void DisposeReleaseTheMap() throws InterruptedException {
GoogleMapController googleMapController = getGoogleMapController();
googleMapController.onMapReady(mockGoogleMap);
assertTrue(googleMapController != null);
googleMapController.dispose();
Expand All @@ -97,6 +113,7 @@ public void DisposeReleaseTheMap() throws InterruptedException {

@Test
public void OnDestroyReleaseTheMap() throws InterruptedException {
GoogleMapController googleMapController = getGoogleMapController();
googleMapController.onMapReady(mockGoogleMap);
assertTrue(googleMapController != null);
googleMapController.onDestroy(activity);
Expand All @@ -105,6 +122,7 @@ public void OnDestroyReleaseTheMap() throws InterruptedException {

@Test
public void OnMapReadySetsPaddingIfInitialPaddingIsThere() {
GoogleMapController googleMapController = getGoogleMapController();
float padding = 10f;
int paddingWithDensity = (int) (padding * googleMapController.density);
googleMapController.setInitialPadding(padding, padding, padding, padding);
Expand All @@ -115,6 +133,7 @@ public void OnMapReadySetsPaddingIfInitialPaddingIsThere() {

@Test
public void SetPaddingStoresThePaddingValuesInInInitialPaddingWhenGoogleMapIsNull() {
GoogleMapController googleMapController = getGoogleMapController();
assertNull(googleMapController.initialPadding);
googleMapController.setPadding(0f, 0f, 0f, 0f);
assertNotNull(googleMapController.initialPadding);
Expand All @@ -123,6 +142,7 @@ public void SetPaddingStoresThePaddingValuesInInInitialPaddingWhenGoogleMapIsNul

@Test
public void OnMapReadySetsMarkerCollectionListener() {
GoogleMapController googleMapController = getGoogleMapController();
GoogleMapController spyGoogleMapController = spy(googleMapController);
// setMarkerCollectionListener method should be called when map is ready
spyGoogleMapController.onMapReady(mockGoogleMap);
Expand All @@ -139,6 +159,7 @@ public void OnMapReadySetsMarkerCollectionListener() {
@Test
@SuppressWarnings("unchecked")
public void OnMapReadySetsClusterItemClickListener() {
GoogleMapController googleMapController = getGoogleMapController();
GoogleMapController spyGoogleMapController = spy(googleMapController);
// setMarkerCollectionListener method should be called when map is ready
spyGoogleMapController.onMapReady(mockGoogleMap);
Expand All @@ -155,6 +176,7 @@ public void OnMapReadySetsClusterItemClickListener() {
@Test
@SuppressWarnings("unchecked")
public void OnMapReadySetsClusterItemRenderedListener() {
GoogleMapController googleMapController = getGoogleMapController();
GoogleMapController spyGoogleMapController = spy(googleMapController);
// setMarkerCollectionListener method should be called when map is ready
spyGoogleMapController.onMapReady(mockGoogleMap);
Expand All @@ -171,6 +193,7 @@ public void OnMapReadySetsClusterItemRenderedListener() {

@Test
public void SetInitialClusterManagers() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
Map<String, Object> initialClusterManager = new HashMap<>();
initialClusterManager.put("clusterManagerId", "cm_1");
List<Object> initialClusterManagers = new ArrayList<>();
Expand All @@ -184,6 +207,7 @@ public void SetInitialClusterManagers() {

@Test
public void OnClusterItemRenderedCallsMarkersController() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
MarkerBuilder markerBuilder = new MarkerBuilder("m_1", "cm_1");
final Marker marker = mock(Marker.class);
googleMapController.onClusterItemRendered(markerBuilder, marker);
Expand All @@ -192,6 +216,7 @@ public void OnClusterItemRenderedCallsMarkersController() {

@Test
public void OnClusterItemClickCallsMarkersController() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
MarkerBuilder markerBuilder = new MarkerBuilder("m_1", "cm_1");

googleMapController.onClusterItemClick(markerBuilder);
Expand Down