View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  }