1

I know this question is asked so many times, but I still didn't find any solution,

I have used below solution but it still does not help me

How to mock a final class with mockito

in that suggested that you will use mockito 2+ verison, and I am using latest version but stiill nothing same problem is arising, I am using Java not Kotlin

Code is below

   @Test
    public void isCorrect() {
        LoginActivity summaryActivity = mock(LoginActivity.class);
        Assert.assertEquals(summaryActivity.getPackageName(), "com.revel.application");
    }

I am using Android Studio 3.1.3,
org.mockito:mockito-core:2.9.0,

 compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "${baseApplicationId}"
        minSdkVersion 22
        targetSdkVersion 27

still I am getting an error like

Mockito cannot mock/spy because :
 - final class

    at com.lifescan.reveal.ExampleUnitTest.isCorrect(ExampleUnitTest.java:15)
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150
  • Marking as a dupe; please edit the question to more clearly address what you've tried or why it differs from existing answers. – Jeff Bowman Oct 26 '18 at 17:08
  • Hi @JeffBowman first of all thank you so much for your suggestion but I have already read that question and from that question I have updated mokito library but still i am facing same issue, I am using mokito 2.10.0 latest version – Siddhpura Amit Oct 26 '18 at 17:47
  • I appreciate the clarification; it is helpful to **link in your question** to the resources you tried and why they didn't work. Beyond updating Mockito (which is currently at [v2.23.1](https://github.com/mockito/mockito/releases/tag/v2.23.1)) you need to _add a file to enable the subclassing_, which Mockito can detect at runtime to switch mocking systems. Can you please confirm that you've tried this after [following those steps and creating the `mock-maker-inline` file](https://github.com/mockito/mockito/wiki/What's-new-in-Mockito-2#mock-the-unmockable-opt-in-mocking-of-final-classesmethods)? – Jeff Bowman Oct 26 '18 at 17:54

0 Answers0