views:

91

answers:

1

Hi.

I'm testing a Swing GUI application using the UISpec4J testing framework. I'm testing validation code on a JTextField, but the framework does not support focus-change events, as it runs the application in a headless fashion.

The text field has a DocumentEvent attached to it that activates the validation code. I'm trying to figure out how to dispatch the document event manually to activate the validation code. Trying to dispatch focus or mouse events manually haven't been working for me.

Thanks for any help!

A: 

I'm not sure I understand the problem. Can't you just use

textField.getDocument().insertString(..)

to generate a DocumentEvent?

Also, I would suggest that validation should not be done in the DocumentListener as its too late for this since the Document has already been updated. To validate data as it is typed you should be using a DocumentFilter.

camickr
Tried this, and it doesn't work. The text does get inserted into the text field, but the DocumentEvent does not get dispatched.I think this is a problem of the UISpec4J testing framework, which is why I'm trying to figure out how to manually dispatch the event.Agreed that the DocumentListener isn't the best place for validation, but the code has already been written, and as the tester, I'm dealing with the fallout. :-)
Bassam