title: Cannot mock instance of Firebase Analytics for Android
body: <p>I'm trying to mock an instance of Firebase Analytics for Android unit testing, but my Firebase variable remains undefined after I call Firebase's <code>getInstance()</code> method - which should initialize an instance of the FirebaseAnalytics class.</p>
  
  <p>I'm using PowerMock and Android Studio. Here's my Test.java file (no tests yet - just trying to initialize a mock of the class):</p>
  
  <pre><code>@RunWith(RobolectricTestRunner.class)
  @Config(constants = BuildConfig.class, sdk = 18, manifest = 
  Config.NONE)
  @PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
  @PrepareForTest({FirebaseAnalytics.class})
  public class FirebaseTest {
      @Rule public PowerMockRule rule = new PowerMockRule();
      @Mock Application application;
      @Mock Analytics analytics;
      FirebaseAnalytics firebase;
  
      @Before
      public void setUp() {
          initMocks(this);
  
          /* mock context */
          when(analytics.getApplication()).thenReturn(application);
  
          PowerMockito.mockStatic(FirebaseAnalytics.class);
  
  when(FirebaseAnalytics.getInstance(application)).thenReturn(firebase);  /* firebase remains null */
          PowerMockito.mockStatic(FirebaseAnalytics.class);
      }
  </code></pre>
  
  <p>FirebaseAnalytics is a final class, and getInstance() is a static final method. I'm not sure whether these may make mocking difficult. Any ideas are appreciated!</p>