IllegalStateException when using Mockito with IntelliJ's Java

319
March 06, 2018, at 1:13 PM

The error message I receive:

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker

The code in question:

List<String> mockList = mock(List.class);

The build.gradle dependency:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    def mockito_version = 'latest.release'
    // For local unit tests on your development machine
    testCompile "org.mockito:mockito-core:$mockito_version"
}

I have tried looking at other people with the same issue and I keep getting references to PowerMock. I have no idea what that means, so if this is a duplicate I apologize. It just seems like no other question had a solution that resolved my issue. The library is imported properly, as I do not have any compilation errors. Any help would be greatly appreciated.

Answer 1

i tried to create a new project and test this out. below is how my depdencies in gradle file looks:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile "org.mockito:mockito-core:2.+"
}

below is my test class:

import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestList {
    @Test
    public void Test(){
        List<String> myList = mock(List.class);
        when(myList.get(0)).thenReturn("hello world");
        Assert.assertEquals("hello world",myList.get(0));
    }
}

this works.

Rent Charter Buses Company
READ ALSO
java string split on all non-alphanumeric except apostrophes

java string split on all non-alphanumeric except apostrophes

So I want to split a string in java on any non-alphanumeric characters

268
Java - StringIndexOutOfBoundsException [duplicate]

Java - StringIndexOutOfBoundsException [duplicate]

This question already has an answer here:

237
How to send email of SQLite database using Intent.EXTRA_TEXT?

How to send email of SQLite database using Intent.EXTRA_TEXT?

I am trying to simply send an email with the data from my database as text in the email

163