You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FormTest.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.vaadin.v7.tests.server.component.form;
  2. import static org.junit.Assert.assertFalse;
  3. import static org.junit.Assert.assertTrue;
  4. import org.junit.Test;
  5. import com.vaadin.v7.ui.Form;
  6. import com.vaadin.v7.ui.TextField;
  7. /**
  8. * Test for {@link Form}.
  9. *
  10. * @author Vaadin Ltd
  11. */
  12. public class FormTest {
  13. @Test
  14. public void testFocus() {
  15. Form form = new Form();
  16. final boolean firstFieldIsFocused[] = new boolean[1];
  17. TextField field1 = new TextField() {
  18. @Override
  19. public boolean isConnectorEnabled() {
  20. return false;
  21. }
  22. @Override
  23. public void focus() {
  24. firstFieldIsFocused[0] = true;
  25. }
  26. };
  27. final boolean secondFieldIsFocused[] = new boolean[1];
  28. TextField field2 = new TextField() {
  29. @Override
  30. public boolean isConnectorEnabled() {
  31. return true;
  32. }
  33. @Override
  34. public void focus() {
  35. secondFieldIsFocused[0] = true;
  36. }
  37. };
  38. form.addField("a", field1);
  39. form.addField("b", field2);
  40. form.focus();
  41. assertTrue("Field with enabled connector is not focused",
  42. secondFieldIsFocused[0]);
  43. assertFalse("Field with disabled connector is focused",
  44. firstFieldIsFocused[0]);
  45. }
  46. }