I have a method that validates whether the correct input is entered into a textfield but I would love to perform some junit test on this how could this be done? Any guidance would be greatly appreciated.
public void number_validator(JTextField txtField) {
textField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char character = e.getKeyChar();
if (!(Character.isDigit(character) || (character == KeyEvent.VK_BACK_SPACE) || (character == KeyEvent.VK_DELETE))) {
e.consume();
JOptionPane.showMessageDialog(null, "Only a number is allowed in this field.\nNo characters!", "WARNING", JOptionPane.WARNING_MESSAGE);
}
}
});
}