2017-12-19 4 views
0

TestFx로 테스트를 변경했지만 문제가 지속됩니다.Testfx에서 java.lang.NoSuchMethodError를 제공합니다.

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ILAreaManagement/ILArea.fxml")); 
     Parent root = fxmlLoader.load(); 

     MaintenanceController maintenanceController = fxmlLoader.getController(); 

     Platform.runLater(() ->{ 
      try { 
       maintenanceController.initialize(maintenanceAreaObjectObservableList); 
      } catch (Exception e) { 

그것이

java.lang.NoSuchMethodError주는 setTitle이라는 방법에 관해서 : gov.tubitak.ys03.sysmaintenance.utilities.BorderedTitledPane.setTitle (Ljava/LANG/문자열) V

((BorderedTitledPane) ILAreaPane) .setTitle ("IL Area"); {반환 제목;}

public class BorderedTitledPane extends StackPane { 

    Label title = new Label(" "); 

    public BorderedTitledPane(Node content) { 
     StackPane contentPane = new StackPane(); 
     content.getStyleClass().add("bordered-titled-content"); 
     contentPane.getChildren().add(content); 

     getStyleClass().add("bordered-titled-border"); 
     getChildren().addAll(title, contentPane); 
    } 

    public void setTitle(String title) { 
     this.title.setText(title); 
     this.title.getStyleClass().add("bordered-titled-title"); 
     StackPane.setAlignment(this.title, Pos.TOP_CENTER); 
    } 

} 

나는 공공 라벨 인 getTitle()에 setTitle이라는 변화하지만 Ljavafx/현장/제어/라벨과 같은 오류가 발생합니다. 나는 예외의 이유를 이해하지 못한다.

답변

0

리팩토링을 수행 할 수없는 경우 Powermock을 사용해야합니다. compatibility table and wiki.

그런 다음 새로운 Label()이 만들어지면 실제로 모의이 사용되도록 테스트를 설정해야합니다.

@PrepareForTest(Label.class) 
@RunWith(PowerMockRunner.class) 
public class MyTest{ 

    @Test 
    public void init() throws Exception { 
     Label labelMock = Mockito.mock(Label.class); 
     PowerMockito.whenNew(Label.class) 
      .withNoArguments().thenReturn(labelMock); 

     // rest of your test 
     .... 
    } 
+0

예.이 솔루션을 사용하면 –

0

예외가 BorderedTitlePane 클래스에 관한 것입니다 : 당신이 쉽게 모방 할 수 있도록 라벨은 최종되지 않습니다. 나는 그것을 바꿨고 나의 시험은 통과되었다. 변경된 BorderedTitlePane 클래스를 공유하고 싶습니다.

@jewelsea가 Writed하는 BorderedTitlePane 클래스입니다. 제목을 변경해야 할 때 제목을 설정하기 위해 그것을 변경했습니다. 하지만 StringProperty 사용해야합니다.

public class BorderedTitledPane extends StackPane { 

    private StringProperty title = new SimpleStringProperty(); 

    public BorderedTitledPane(String titleString, Node content) { 
     final Label titleLabel = new Label(); 
     titleLabel.textProperty().bind(Bindings.concat(title, "")); 
     titleLabel.getStyleClass().add("bordered-titled-title"); 
     title.set(titleString); 
     StackPane.setAlignment(titleLabel, Pos.TOP_CENTER); 

     StackPane contentPane = new StackPane(); 
     content.getStyleClass().add("bordered-titled-content"); 
     contentPane.getChildren().add(content); 

     getStyleClass().add("bordered-titled-border"); 
     getChildren().addAll(titleLabel, contentPane); 
    } 

    public String getTitle(){ 
     return title.get(); 
    } 

    public StringProperty getTitleStringProperty(){ 
     return title; 
    } 

    public void setTitle(String title){ 
     this.title.set(title); 
    } 

} 
관련 문제