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.

FieldDefaultValuesTest.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.vaadin.v7.tests.server.component.abstractfield;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertTrue;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import org.junit.Test;
  8. import com.vaadin.v7.tests.VaadinClasses;
  9. import com.vaadin.v7.ui.Field;
  10. import com.vaadin.v7.ui.Slider;
  11. public class FieldDefaultValuesTest {
  12. @Test
  13. public void testFieldsHaveDefaultValueAfterClear() throws Exception {
  14. for (Field<?> field : createFields()) {
  15. Object originalValue = field.getValue();
  16. field.clear();
  17. Object clearedValue = field.getValue();
  18. assertEquals(
  19. "Expected to get default value after clearing "
  20. + field.getClass().getName(),
  21. originalValue, clearedValue);
  22. }
  23. }
  24. @Test
  25. public void testFieldsAreEmptyAfterClear() throws Exception {
  26. int count = 0;
  27. for (Field<?> field : createFields()) {
  28. count++;
  29. field.clear();
  30. if (field instanceof Slider) {
  31. assertFalse(
  32. "Slider should not be empty even after being cleared",
  33. field.isEmpty());
  34. } else {
  35. assertTrue(
  36. field.getClass().getName()
  37. + " should be empty after being cleared",
  38. field.isEmpty());
  39. }
  40. }
  41. assertTrue(count > 0);
  42. }
  43. @SuppressWarnings("rawtypes")
  44. private static List<Field<?>> createFields()
  45. throws InstantiationException, IllegalAccessException {
  46. List<Field<?>> fieldInstances = new ArrayList<>();
  47. for (Class<? extends Field> fieldType : VaadinClasses.getFields()) {
  48. fieldInstances.add(fieldType.newInstance());
  49. }
  50. return fieldInstances;
  51. }
  52. }