Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to test listener class methods using JUnit?

807603Jan 28 2008 — edited Jan 28 2008
Hello,

I have to test objects returned by a listener class's "xxxchanged" or "xxxperformed" method.

I want to do this by adding the listener to an object and performing the appropriate actions that triggers an event in the listener.

Then AFTER a callback has been received, I want to obtain and run some assertions on the object obtained by the xxxchanged method.

Example: Test ActionListener class

1. Instantiate a JButton
2. Add ActionListener to it
3. Press the button
4. Check that actionPerformed method got called
5. Assert fields of ActionEvent object passed to actionPerformed method

I am not sure how to do this using JUnit.

Please advice.

Thanks,

nitrousfiz
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 25 2008
Added on Jan 28 2008
4 comments
2,680 views