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.beanutils.converters;
18  
19  import java.util.Calendar;
20  import java.util.Date;
21  
22  import junit.framework.TestSuite;
23  
24  /**
25   * Test Case for the DateConverter class.
26   *
27   * @version $Id$
28   */
29  public class DateConverterTestCase extends DateConverterTestBase {
30  
31      /**
32       * Construct a new Date test case.
33       * @param name Test Name
34       */
35      public DateConverterTestCase(final String name) {
36          super(name);
37      }
38  
39      // ------------------------------------------------------------------------
40  
41      /**
42       * Create Test Suite
43       * @return test suite
44       */
45      public static TestSuite suite() {
46          return new TestSuite(DateConverterTestCase.class);
47      }
48  
49      /** Set Up */
50      @Override
51      public void setUp() throws Exception {
52      }
53  
54      /** Tear Down */
55      @Override
56      public void tearDown() throws Exception {
57      }
58  
59      // ------------------------------------------------------------------------
60  
61      /**
62       * Create the Converter with no default value.
63       * @return A new Converter
64       */
65      @Override
66      protected DateTimeConverter makeConverter() {
67          return new DateConverter();
68      }
69  
70      /**
71       * Create the Converter with a default value.
72       * @param defaultValue The default value
73       * @return A new Converter
74       */
75      @Override
76      protected DateTimeConverter makeConverter(final Object defaultValue) {
77          return new DateConverter(defaultValue);
78      }
79  
80      /**
81       * Return the expected type
82       * @return The expected type
83       */
84      @Override
85      protected Class<?> getExpectedType() {
86          return Date.class;
87      }
88  
89      /**
90       * Convert from a Calendar to the appropriate Date type
91       *
92       * @param value The Calendar value to convert
93       * @return The converted value
94       */
95      @Override
96      protected Object toType(final Calendar value) {
97          return value.getTime();
98      }
99  }