Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FieldGroupDateTest.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.v7.data.fieldgroup;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertNotNull;
  19. import java.util.Date;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import com.vaadin.v7.data.util.BeanItem;
  23. import com.vaadin.v7.ui.Field;
  24. import com.vaadin.v7.ui.PopupDateField;
  25. public class FieldGroupDateTest {
  26. private FieldGroup fieldGroup;
  27. public class TestBean {
  28. private Date javaDate;
  29. private java.sql.Date sqlDate;
  30. public TestBean(Date javaDate, java.sql.Date sqlDate) {
  31. super();
  32. this.javaDate = javaDate;
  33. this.sqlDate = sqlDate;
  34. }
  35. public java.sql.Date getSqlDate() {
  36. return sqlDate;
  37. }
  38. public void setSqlDate(java.sql.Date sqlDate) {
  39. this.sqlDate = sqlDate;
  40. }
  41. public Date getJavaDate() {
  42. return javaDate;
  43. }
  44. public void setJavaDate(Date date) {
  45. javaDate = date;
  46. }
  47. }
  48. @SuppressWarnings("deprecation")
  49. @Before
  50. public void setup() {
  51. fieldGroup = new FieldGroup();
  52. fieldGroup.setItemDataSource(new BeanItem<TestBean>(new TestBean(
  53. new Date(2010, 5, 7), new java.sql.Date(2011, 6, 8))));
  54. }
  55. @Test
  56. public void testBuildAndBindDate() {
  57. Field f = fieldGroup.buildAndBind("javaDate");
  58. assertNotNull(f);
  59. assertEquals(PopupDateField.class, f.getClass());
  60. }
  61. @Test
  62. public void testBuildAndBindSqlDate() {
  63. Field f = fieldGroup.buildAndBind("sqlDate");
  64. assertNotNull(f);
  65. assertEquals(PopupDateField.class, f.getClass());
  66. }
  67. @Test
  68. public void clearFields() {
  69. PopupDateField sqlDate = new PopupDateField();
  70. PopupDateField javaDate = new PopupDateField();
  71. fieldGroup.bind(sqlDate, "sqlDate");
  72. fieldGroup.bind(javaDate, "javaDate");
  73. assertEquals(new Date(2010, 5, 7), javaDate.getValue());
  74. assertEquals(new Date(2011, 6, 8), sqlDate.getValue());
  75. fieldGroup.clear();
  76. assertEquals(null, javaDate.getValue());
  77. assertEquals(null, sqlDate.getValue());
  78. }
  79. }