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.

TextFieldWithConverterAndValidatorTest.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.vaadin.v7.tests.server.component.textfield;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import com.vaadin.v7.data.util.ObjectProperty;
  5. import com.vaadin.v7.data.validator.RangeValidator;
  6. import com.vaadin.v7.tests.data.converter.ConverterFactoryTest.ConvertTo42;
  7. import com.vaadin.v7.ui.TextField;
  8. public class TextFieldWithConverterAndValidatorTest {
  9. private TextField field;
  10. private ObjectProperty<Integer> property;
  11. @Before
  12. public void setUp() {
  13. field = new TextField();
  14. field.setInvalidAllowed(false);
  15. }
  16. @Test
  17. public void testConvert42AndValidator() {
  18. property = new ObjectProperty<Integer>(123);
  19. field.setConverter(new ConvertTo42());
  20. field.setPropertyDataSource(property);
  21. field.addValidator(new RangeValidator<Integer>("Incorrect value",
  22. Integer.class, 42, 42));
  23. // succeeds
  24. field.setValue("a");
  25. // succeeds
  26. field.setValue("42");
  27. // succeeds - no validation
  28. property.setValue(42);
  29. // nulls
  30. // succeeds - validate() converts field value back to property type
  31. // before validation
  32. property.setValue(null);
  33. field.validate();
  34. // succeeds
  35. field.setValue(null);
  36. }
  37. // TODO test converter changing value to null with validator
  38. }