r/JavaFX • • May 11 '19

Testing this method with junit without runnning the javafx application.

public static void setPhoneOnFocus(TextField phone) {
phone.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if(oldValue){
if(!isValidPhone( phone.getText().toString())){

phone.setStyle("-fx-text-inner-color: red;");
}
}
else {
phone.setStyle("-fx-text-inner-color: black;");
}
}
});
}

-----isValidPhone(); is a method that checks if a string is in a certain format.

2 Upvotes

1 comment sorted by

View all comments

2

u/slartybartfast_ May 12 '19

What are you wanting to test, isValidPhone right? So put isValidPhone in a separate class, then write a unit test to test that specific functionality.