无法初始化插件:接口org.mockito.plugins.MockMaker(替代:null)

Bre*_*oke 6 java junit mockito

我已经看到了这个问题的几种变体,涉及到android,powermock,bytebuddy-downloads-gone-wrong和其他可能的问题。我不认为我的问题与powermock或android有关,因为我都不使用。以下是测试类别,省略了不相关的测试。

    public class TournamentsTests {

    private ToornamentClient client;
    private HashMap<String,String> params;
    private HashMap<String,String> headers;

    private TournamentRequest tournamentRequest = new TournamentRequest();
    private TournamentDetails tournamentDetails = new TournamentDetails();
    @Before
    public void Setup() throws IOException {
        client = new ToornamentClient(System.getenv("KEY"),System.getenv("CLIENT"),System.getenv("SECRET"));
        client.authorize();

        headers = new HashMap<>();
        params = new HashMap<>();
        params.put("disciplines","overwatch");

        tournamentDetails.setParticipantType(ParticipantType.TEAM);
        tournamentDetails.setName("OWL Season 1");
        tournamentDetails.setSize(144);
        tournamentDetails.setDiscipline("overwatch");

        tournamentRequest.setDiscipline("overwatch");
        tournamentRequest.setOrganization("Blizzard Entertainment");
        tournamentRequest.setWebsite("http://www.overwatchleague.com");
        tournamentRequest.setMatchFormat(MatchFormat.BO3);
        tournamentRequest.setPrize("$500,000-$1,000,000");
        tournamentRequest.setSize(144);
        tournamentRequest.setName("OWL Season 1");
        tournamentRequest.setParticipantType(ParticipantType.TEAM);

    }
    @AfterEach
    public void CleanUp(){
        headers.clear();
    }

    @Test
    public void createTournamentTest(){
       Mockito.when(client.tournaments().createTournament(tournamentRequest)).thenReturn(tournamentDetails);


    }

}
Run Code Online (Sandbox Code Playgroud)

上面的单个测试是我要模拟的测试,因为它打算通过该库打算使用的api插入。我不确定powermock是否是解决方案的一部分,因为我不清楚它的作用,但是可以随时帮助我解决它。我的build.gradle文件如下所示:

group 'ch.wisv'
version '0.1'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

jar {
    baseName = 'toornament-client'
    version = '0.1'
}

dependencies {
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.7'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.7'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.7'
    compile 'junit:junit:4.12'
    compile 'com.squareup.okhttp3:okhttp:3.6.0'

    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
    testCompile 'org.mockito:mockito-core:2.18.0'
}
Run Code Online (Sandbox Code Playgroud)

我也不认为这里有什么不妥当的地方,并在我的IDE中检查是否下载了诸如bytebuddy和objenesis之类的依赖项。

我尝试过的一些事情是:

  • 变量“ client”上的@Mock注释
  • ToornamentClient客户端= Mockito.mock(ToornamentClient.class)
  • Toornaments调用者= Mockito.mock(client.tournaments()。getClass())