DataItemTest: Test the date type too, and improve the asserts.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / shared / DataItemTest.java
1 package org.glom.web.shared;
2
3 import static org.junit.Assert.*;
4
5 import java.util.Calendar;
6 import java.util.Date;
7 import java.util.GregorianCalendar;
8
9 import org.junit.Test;
10
11 public class DataItemTest {
12
13         public DataItemTest() {
14         }
15
16         @Test
17         public void testBoolean() {
18                 final DataItem item = new DataItem();
19                 item.setBoolean(true);
20                 assertEquals(true, item.getBoolean());
21         }
22
23         @Test
24         public void testNumber() {
25                 final DataItem item = new DataItem();
26                 final double val = 123.456;
27                 item.setNumber(val);
28                 assertEquals(val, item.getNumber(), 0.000001);
29         }
30
31         @Test
32         public void testText() {
33                 final DataItem item = new DataItem();
34                 final String val = "abc";
35                 item.setText(val);
36                 assertEquals(val, item.getText());
37         }
38         
39         @Test
40         public void testDate() {
41                 final DataItem item = new DataItem();
42                 
43                 //Not that we use a different API to create a Date
44                 //in the client-side test (GwtTestDataItem),
45                 //because this API is not available in GWT client code.
46                 //TODO: Is there no easier (and non-deprecated) way to create
47                 //a Date instance?
48                 Calendar cal = new GregorianCalendar();
49                 cal.setTime(new Date());
50                 cal.set(Calendar.HOUR_OF_DAY, 0);
51                 cal.set(Calendar.MINUTE, 0);
52                 cal.set(Calendar.SECOND, 0);
53                 cal.set(Calendar.MILLISECOND, 0);
54                 cal.set(Calendar.YEAR, 1973);
55                 cal.set(Calendar.MONTH, 4); /* The month is 0 indexed. */
56                 cal.set(Calendar.DAY_OF_MONTH, 11);
57                 final Date val = cal.getTime();
58                                 
59                 item.setDate(val);
60                 assertEquals(val, item.getDate());
61         }
62
63 }