From: SourceForge.net <no...@so...> - 2009-12-01 02:20:30
|
Feature Requests item #1597307, was opened at 2006-11-15 21:51 Message generated for change (Settings changed) made by sf-robot You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=365278&aid=1597307&group_id=15278 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Mark Mosher (mmosher) Assigned to: Nobody/Anonymous (nobody) Summary: WaitingAsserter Initial Comment: A feature for waiting for a condition to become true, that is, not failing if the condition is not immediately true. This is useful in multi-threaded and/or client/server architectures, particularly GUI or event-based applications. Take the case of an application setting a value on a server (or mock server object), where that call returns immediately, and at some point in time the server fires an event on some thread, the client app gets that event and updates a object's state based on that event. We want to verify the round trip, specifically that the object state was updated based on our call to the server, but this won't happen immediately. We should be willing to wait for some period of time for the condition. What I have created is the notion of a waiting asserter, which waits up to 10 seconds (configurable) for an assert condition to become true, e.g. such as assertTrue or assertEquals. This works for me when I do something that eventually fires an event and I want to verify that the right event fired (possibly on a different thread) or the correct callback method eventually was invoked with the correct parameter as a result. And other things like Did a control change state as a result of another control being selected? WaitingAsserter.java is attached. I have a corresponding WaitingAsserterTest, but it appears that I can only attach one file here. Example usage (to assert that clicking on the doClickButton results in setEnabledButton being enabled): final JButton setEnabledButton = new JButton(); setEnabledButton.setEnabled(false); final WaitingAsserter waitingAsserter = new WaitingAsserter(setEnabledButton.isEnabled()); waitingAsserter.assertFalse(); setEnabledButton.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { waitingAsserter.setValue(evt.getNewValue()); } }); final JButton doClickButton = new JButton(); doClickButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent ae) { setEnabledButton.setEnabled(true); } }); new Thread(new Runnable() { public void run() { try {Thread.sleep(500);} catch (InterruptedException ie) {} java.awt.EventQueue.invokeLater(new Runnable() { public void run() { doClickButton.doClick(); } }); } }).start(); waitingAsserter.assertTrue(); Best regards, Mark ----- Mark Mosher Manager, Product Applications EMRT Office: (585) 219-5900 x404 Mobile: (585) 455-0572 mm...@em... www.emrt.com ---------------------------------------------------------------------- >Comment By: SourceForge Robot (sf-robot) Date: 2009-12-01 02:20 Message: This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker). ---------------------------------------------------------------------- Comment By: David Saff (dsaff) Date: 2009-11-16 17:52 Message: This tracker is being shut down. Please move this item to http://github.com/KentBeck/junit/issues ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=365278&aid=1597307&group_id=15278 |