package io.flutter.plugins.googlemaps;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.app.Application;
import android.content.Context;
import androidx.lifecycle.LifecycleOwner;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.gms.maps.GoogleMap;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.view.FlutterMain;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class GoogleMapControllerTest {

  private Context context;
  private Application application;
  private GoogleMapController googleMapController;

  @Mock BinaryMessenger mockMessenger;
  @Mock GoogleMap mockGoogleMap;
  @Mock LifecycleOwner lifecycleOwner;

  @BeforeClass()
  public static void BeforeClass() {
    FlutterMain.setIsRunningInRobolectricTest(true);
  }

  @Before
  public void before() {
    MockitoAnnotations.initMocks(this);
    context = ApplicationProvider.getApplicationContext();
    application = ApplicationProvider.getApplicationContext();
    googleMapController =
        new GoogleMapController(
            0, context, new AtomicInteger(1), mockMessenger, application, null, null, 0, 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(lifecycleOwner);
    assertNull(googleMapController.getView());
  }
}

@@ -376,44 +376,8 @@
 er;%0A
-import io.flutter.view.FlutterMain;%0A
 impo
@@ -451,38 +451,8 @@
 re;%0A
-import org.junit.BeforeClass;%0A
 impo
@@ -922,120 +922,8 @@
 r;%0A%0A
-  @BeforeClass()%0A  public static void BeforeClass() %7B%0A    FlutterMain.setIsRunningInRobolectricTest(true);%0A  %7D%0A%0A
   @B

Fix Android unit test. (#2985)