1   /*
2    *  Copyright 2003-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of 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,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.apache.commons.convert1.format;
17  
18  import junit.framework.TestCase;
19  import junit.framework.TestSuite;
20  
21  import java.text.Format;
22  import java.text.SimpleDateFormat;
23  import java.text.DecimalFormat;
24  
25  import java.util.Date;
26  
27  import org.apache.commons.convert1.Converter;
28  
29  
30  /**
31   * Test Case for the FormatConverter class.
32   *
33   * @author Henri Yandell
34   * @version $Id: FormatConverterTestCase.java 155441 2005-02-26 13:19:22Z dirkv $
35   */
36  
37  public class FormatConverterTestCase extends TestCase {
38  
39      // ------------------------------------------------------------------------
40  
41      public FormatConverterTestCase(String name) {
42          super(name);
43      }
44      
45      // ------------------------------------------------------------------------
46  
47      public void setUp() throws Exception {
48      }
49  
50      public static TestSuite suite() {
51          return new TestSuite(FormatConverterTestCase.class);        
52      }
53  
54      public void tearDown() throws Exception {
55      }
56  
57      // ------------------------------------------------------------------------
58  
59      public void testNumberFormat() {
60          Format format = new DecimalFormat("0.0");
61          FormatConverter fc = new FormatConverter(format);
62          assertEquals( "5.4", fc.convert( String.class, new Double(5.43) ) );
63      }
64  
65      public void testDateFormat() {
66          Format format = new SimpleDateFormat("dd MM yyyy");
67          FormatConverter fc = new FormatConverter(format);
68          assertEquals( "31 12 1969", fc.convert( String.class, new Date(0) ) );
69      }
70  }
71