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.

DateFieldTestCase.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.vaadin.ui;
  2. import static org.hamcrest.CoreMatchers.is;
  3. import static org.hamcrest.MatcherAssert.assertThat;
  4. import static org.hamcrest.core.IsNull.nullValue;
  5. import static org.junit.Assert.assertNotNull;
  6. import static org.junit.Assert.assertNull;
  7. import java.time.LocalDate;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import org.junit.Rule;
  11. import org.junit.rules.ExpectedException;
  12. public class DateFieldTestCase {
  13. private AbstractLocalDateField dateField;
  14. private LocalDate date;
  15. @Rule
  16. public transient ExpectedException exceptionRule = ExpectedException.none();
  17. @Before
  18. public void setup() {
  19. dateField = new AbstractLocalDateField() {
  20. };
  21. date = LocalDate.now();
  22. }
  23. @Test
  24. public void rangeStartIsSetToNull() {
  25. dateField.setRangeStart(null);
  26. assertThat(dateField.getRangeStart(), is(nullValue()));
  27. }
  28. @Test
  29. public void rangeStartIsAcceptedAsValue() {
  30. dateField.setRangeStart(date);
  31. dateField.setValue(date);
  32. assertNull(dateField.getComponentError());
  33. }
  34. @Test
  35. public void belowRangeStartIsNotAcceptedAsValue() {
  36. LocalDate currentDate = dateField.getValue();
  37. dateField.setRangeStart(date);
  38. exceptionRule.expect(IllegalArgumentException.class);
  39. dateField.setValue(date.minusDays(1));
  40. assertThat(dateField.getValue(), is(currentDate));
  41. }
  42. @Test
  43. public void rangeEndIsSetToNull() {
  44. dateField.setRangeEnd(null);
  45. assertThat(dateField.getRangeEnd(), is(nullValue()));
  46. }
  47. @Test
  48. public void rangeEndIsAcceptedAsValue() {
  49. dateField.setRangeEnd(date);
  50. dateField.setValue(date);
  51. assertNull(dateField.getComponentError());
  52. }
  53. @Test
  54. public void aboveRangeEndIsNotAcceptedAsValue() {
  55. LocalDate currentDate = dateField.getValue();
  56. dateField.setRangeEnd(date);
  57. exceptionRule.expect(IllegalArgumentException.class);
  58. dateField.setValue(date.plusDays(1));
  59. assertThat(dateField.getValue(), is(currentDate));
  60. }
  61. }