无法初始化插件:interface org.mockito.plugins.MockMaker(alternate:null)

时间:2018-04-15 17:51:46

标签: java junit mockito

我见过这个问题的几个变种涉及android,powermock,bytebuddy-downloads-gone-wrong以及其他可能的错误。我不认为我的问题与powermock或android有关,因为我没有使用。下面是测试类,省略了不相关的测试。

import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

/**
 *
 * @author Sedrick
 */
public class JavaFXApplication60 extends Application {   

    @Override
    public void start(Stage primaryStage) {     
        //Start create GUI
        Label lblRequirement11 = new Label("Requirement1");
        Label lblRequirement12 = new Label("Requirement2");
        Label lblRequirement13 = new Label("Requirement3");
        GridPane.setConstraints(lblRequirement11, 1, 0);
        GridPane.setConstraints(lblRequirement12, 2, 0);
        GridPane.setConstraints(lblRequirement13, 3, 0);

        Label lblState1 = new Label("State1");
        ToggleButton toggleButton11 = new ToggleButton();
        toggleButton11.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton12 = new ToggleButton();
        toggleButton12.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton13 = new ToggleButton();
        toggleButton13.setMaxWidth(Double.MAX_VALUE);
        GridPane.setConstraints(lblState1, 0, 1);
        GridPane.setConstraints(toggleButton11, 1, 1);
        GridPane.setConstraints(toggleButton12, 2, 1);
        GridPane.setConstraints(toggleButton13, 3, 1);

        Label lblState2 = new Label("State2");
        ToggleButton toggleButton21 = new ToggleButton();
        toggleButton21.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton22 = new ToggleButton();
        toggleButton22.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton23 = new ToggleButton();
        toggleButton23.setMaxWidth(Double.MAX_VALUE);
        GridPane.setConstraints(lblState2, 0, 2);
        GridPane.setConstraints(toggleButton21, 1, 2);
        GridPane.setConstraints(toggleButton22, 2, 2);
        GridPane.setConstraints(toggleButton23, 3, 2);

        Label lblState3 = new Label("State3");
        ToggleButton toggleButton31 = new ToggleButton();
        toggleButton31.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton32 = new ToggleButton();
        toggleButton32.setMaxWidth(Double.MAX_VALUE);
        ToggleButton toggleButton33 = new ToggleButton();
        toggleButton33.setMaxWidth(Double.MAX_VALUE);
        GridPane.setConstraints(lblState3, 0, 3);
        GridPane.setConstraints(toggleButton31, 1, 3);
        GridPane.setConstraints(toggleButton32, 2, 3);
        GridPane.setConstraints(toggleButton33, 3, 3);

        GridPane root = new GridPane(); 
        root.setVgap(5);
        root.setHgap(5);
        root.getChildren().addAll(lblRequirement11, lblRequirement12, lblRequirement13);
        root.getChildren().addAll(lblState1, toggleButton11, toggleButton12, toggleButton13);
        root.getChildren().addAll(lblState2, toggleButton21, toggleButton22, toggleButton23);
        root.getChildren().addAll(lblState3, toggleButton31, toggleButton32, toggleButton33);
        //End create GUI

        //Start create ToggleButtons' event handlers.
        List<ToggleButton> toggleButtonList = new ArrayList();
        toggleButtonList.add(toggleButton11);
        toggleButtonList.add(toggleButton12);
        toggleButtonList.add(toggleButton13);
        toggleButtonList.add(toggleButton21);
        toggleButtonList.add(toggleButton22);
        toggleButtonList.add(toggleButton23);
        toggleButtonList.add(toggleButton31);
        toggleButtonList.add(toggleButton32);
        toggleButtonList.add(toggleButton33);

        for(ToggleButton tempToggleButton : toggleButtonList)
        {
            tempToggleButton.setOnAction(actionEvent -> {
                if(tempToggleButton.isSelected())
                {
                    tempToggleButton.setText("*");
                }
                else
                {
                    tempToggleButton.setText("");
                }
            });
        }
        ////End create ToggleButtons' event handlers.



        Scene scene = new Scene(root, 400, 300);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

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

    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);


    }

}

我认为这里的任何内容都不合适,并且在我的IDE中检查了下载了像bytebuddy和objenesis这样的依赖项。

我尝试过的一些事情是:

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

0 个答案:

没有答案