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.

FieldGroupDateTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data.fieldgroup;
  17. import java.util.Date;
  18. import org.junit.Assert;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21. import com.vaadin.data.util.BeanItem;
  22. import com.vaadin.v7.ui.LegacyField;
  23. import com.vaadin.v7.ui.LegacyPopupDateField;
  24. public class FieldGroupDateTest {
  25. private FieldGroup fieldGroup;
  26. public class TestBean {
  27. private Date javaDate;
  28. private java.sql.Date sqlDate;
  29. public TestBean(Date javaDate, java.sql.Date sqlDate) {
  30. super();
  31. this.javaDate = javaDate;
  32. this.sqlDate = sqlDate;
  33. }
  34. public java.sql.Date getSqlDate() {
  35. return sqlDate;
  36. }
  37. public void setSqlDate(java.sql.Date sqlDate) {
  38. this.sqlDate = sqlDate;
  39. }
  40. public Date getJavaDate() {
  41. return javaDate;
  42. }
  43. public void setJavaDate(Date date) {
  44. javaDate = date;
  45. }
  46. }
  47. @SuppressWarnings("deprecation")
  48. @Before
  49. public void setup() {
  50. fieldGroup = new FieldGroup();
  51. fieldGroup.setItemDataSource(new BeanItem<TestBean>(new TestBean(
  52. new Date(2010, 5, 7), new java.sql.Date(2011, 6, 8))));
  53. }
  54. @Test
  55. public void testBuildAndBindDate() {
  56. LegacyField f = fieldGroup.buildAndBind("javaDate");
  57. Assert.assertNotNull(f);
  58. Assert.assertEquals(LegacyPopupDateField.class, f.getClass());
  59. }
  60. @Test
  61. public void testBuildAndBindSqlDate() {
  62. LegacyField f = fieldGroup.buildAndBind("sqlDate");
  63. Assert.assertNotNull(f);
  64. Assert.assertEquals(LegacyPopupDateField.class, f.getClass());
  65. }
  66. @Test
  67. public void clearFields() {
  68. LegacyPopupDateField sqlDate = new LegacyPopupDateField();
  69. LegacyPopupDateField javaDate = new LegacyPopupDateField();
  70. fieldGroup.bind(sqlDate, "sqlDate");
  71. fieldGroup.bind(javaDate, "javaDate");
  72. Assert.assertEquals(new Date(2010, 5, 7), javaDate.getValue());
  73. Assert.assertEquals(new Date(2011, 6, 8), sqlDate.getValue());
  74. fieldGroup.clear();
  75. Assert.assertEquals(null, javaDate.getValue());
  76. Assert.assertEquals(null, sqlDate.getValue());
  77. }
  78. }