| package io.flutter.plugins.googlemaps; |
| |
| import static org.junit.Assert.assertNull; |
| import static org.junit.Assert.assertTrue; |
| |
| import android.content.Context; |
| import androidx.activity.ComponentActivity; |
| import androidx.test.core.app.ApplicationProvider; |
| import com.google.android.gms.maps.GoogleMap; |
| import io.flutter.plugin.common.BinaryMessenger; |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.mockito.Mock; |
| import org.mockito.MockitoAnnotations; |
| import org.robolectric.Robolectric; |
| import org.robolectric.RobolectricTestRunner; |
| |
| @RunWith(RobolectricTestRunner.class) |
| public class GoogleMapControllerTest { |
| |
| private Context context; |
| private ComponentActivity activity; |
| private GoogleMapController googleMapController; |
| |
| @Mock BinaryMessenger mockMessenger; |
| @Mock GoogleMap mockGoogleMap; |
| |
| @Before |
| public void before() { |
| MockitoAnnotations.initMocks(this); |
| context = ApplicationProvider.getApplicationContext(); |
| activity = Robolectric.setupActivity(ComponentActivity.class); |
| googleMapController = |
| new GoogleMapController(0, context, mockMessenger, activity::getLifecycle, null); |
| googleMapController.init(); |
| } |
| |
| @Test |
| public void DisposeReleaseTheMap() throws InterruptedException { |
| googleMapController.onMapReady(mockGoogleMap); |
| assertTrue(googleMapController != null); |
| googleMapController.dispose(); |
| assertNull(googleMapController.getView()); |
| } |
| |
| @Test |
| public void OnDestroyReleaseTheMap() throws InterruptedException { |
| googleMapController.onMapReady(mockGoogleMap); |
| assertTrue(googleMapController != null); |
| googleMapController.onDestroy(activity); |
| assertNull(googleMapController.getView()); |
| } |
| } |