1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils.handlers.properties;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import java.sql.Time;
24 import java.sql.Timestamp;
25 import java.util.Date;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30 public class DatePropertyHandlerTest {
31 private DatePropertyHandler handler;
32 private Date testValue;
33
34 @Before
35 public void setUp() {
36 this.handler = new DatePropertyHandler();
37 this.testValue = new Date();
38 }
39
40 @Test
41 public void testApplyTypeOfDate() throws Exception {
42 assertEquals(java.sql.Date.class, handler.apply(java.sql.Date.class, testValue).getClass());
43 }
44
45 @Test
46 public void testApplyTypeOfTime() throws Exception {
47 assertEquals(Time.class, handler.apply(java.sql.Time.class, testValue).getClass());
48 }
49
50 @Test
51 public void testApplyTypeOfTimestamp() throws Exception {
52 assertEquals(Timestamp.class, handler.apply(java.sql.Timestamp.class, testValue).getClass());
53 }
54
55 @Test
56 public void testMatch() {
57 assertTrue(handler.match(java.sql.Date.class, testValue));
58 assertTrue(handler.match(java.sql.Time.class, testValue));
59 assertTrue(handler.match(java.sql.Timestamp.class, testValue));
60 }
61
62 @Test
63 public void testMatchNegative() {
64 assertFalse(handler.match(Float.class, null));
65 assertFalse(handler.match(Float.class, testValue));
66 }
67
68 @Test
69 public void testNotMatch() {
70 final Timestamp ts = new Timestamp(testValue.getTime());
71 assertFalse(handler.match(java.sql.Timestamp.class, ts));
72 }
73 }