removeListener(ClickEvent.class, listener, BUTTON_CLICK_METHOD);
}
+ /**
+ * Simulates a button click, notifying all server-side listeners.
+ *
+ * No action is taken is the button is disabled.
+ */
+ public void click() {
+ if (isEnabled() && !isReadOnly()) {
+ fireClick();
+ }
+ }
+
/**
* Fires a click event to all listeners without any event details.
*
--- /dev/null
+package com.vaadin.tests.server.component.button;
+
+import static org.junit.Assert.assertEquals;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+import org.junit.Test;
+
+/**
+ * Tests the public click() method.
+ */
+public class ButtonClick {
+ private boolean clicked = false;
+
+ @Test
+ public void testClick() {
+ getButton().click();
+ assertEquals(clicked, true);
+ }
+
+ @Test
+ public void testClickDisabled() {
+ Button b = getButton();
+ b.setEnabled(false);
+ b.click();
+ assertEquals(clicked, false);
+ }
+
+ @Test
+ public void testClickReadOnly() {
+ Button b = getButton();
+ b.setReadOnly(true);
+ b.click();
+ assertEquals(clicked, false);
+ }
+
+ private Button getButton() {
+ Button b = new Button();
+ b.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent ev) {
+ clicked = true;
+ }
+ });
+ return b;
+ }
+}