[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit Button.java,1.5,1.6 WebForm.java,1.79,1.8
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-03-13 20:16:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv2077/src/com/meterware/httpunit
Modified Files:
Button.java WebForm.java
Log Message:
Added WebForm.getButton method
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Button.java 17 Feb 2003 23:54:40 -0000 1.5
+++ Button.java 13 Mar 2003 20:16:17 -0000 1.6
@@ -33,6 +33,9 @@
**/
public class Button extends FormControl {
+ static final public HTMLElementPredicate HAS_ID;
+ static final public HTMLElementPredicate HAS_LABEL;
+
private String _onClickEvent = "";
@@ -98,5 +101,21 @@
public void click() throws IOException, SAXException {
doButtonAction();
}
+ }
+
+
+ static {
+ HAS_ID = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object button, Object id ) {
+ return ((Button) button).getID().equals( id );
+ };
+ };
+
+ HAS_LABEL = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object button, Object label ) {
+ return ((Button) button).getValue().equals( label );
+ };
+ };
+
}
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- WebForm.java 27 Feb 2003 23:35:59 -0000 1.79
+++ WebForm.java 13 Mar 2003 20:16:17 -0000 1.80
@@ -120,15 +120,20 @@
}
- /**
- * Returns the button with the specified ID
- */
- public Button getButtonWithID( String buttonID ) {
+ public Button getButton( HTMLElementPredicate predicate, Object criteria ) {
Button[] buttons = getButtons();
for (int i = 0; i < buttons.length; i++) {
- if (buttons[i].getID().equals( buttonID )) return buttons[i];
+ if (predicate.matchesCriteria( buttons[i], criteria )) return buttons[i];
}
return null;
+ }
+
+
+ /**
+ * Convenience method which returns the button with the specified ID.
+ */
+ public Button getButtonWithID( String buttonID ) {
+ return getButton( Button.HAS_ID, buttonID );
}
|